Skip to content

Commit

Permalink
Issue #5018 - add request timeout onto ClientUpgradeRequest
Browse files Browse the repository at this point in the history
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
  • Loading branch information
lachlan-roberts committed Jul 4, 2020
1 parent ae43b70 commit 6a8a6ef
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;

import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.http.HttpField;
Expand Down Expand Up @@ -68,6 +69,7 @@ public class ClientUpgradeRequest extends UpgradeRequestAdapter

private final String key;
private Object localEndpoint;
private long timeout;

public ClientUpgradeRequest()
{
Expand Down Expand Up @@ -179,6 +181,27 @@ public void setRequestURI(URI uri)
}
}

/**
* @param timeout the total timeout for the request/response conversation of the WebSocket handshake;
* use zero or a negative value to disable the timeout
* @param unit the timeout unit
* @return this request object
*/
public ClientUpgradeRequest timeout(long timeout, TimeUnit unit)
{
this.timeout = unit.toMillis(timeout);
return this;
}

/**
* @return the total timeout for this request, in milliseconds;
* zero or negative if the timeout is disabled
*/
public long getTimeout()
{
return timeout;
}

public void setLocalEndpoint(Object websocket)
{
this.localEndpoint = websocket;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;

import org.eclipse.jetty.client.HttpClient;
Expand Down Expand Up @@ -374,7 +375,7 @@ public Future<Session> connect(Object websocket, URI toUri, ClientUpgradeRequest
init();

WebSocketUpgradeRequest wsReq = new WebSocketUpgradeRequest(this, httpClient, request);

wsReq.timeout(request.getTimeout() , TimeUnit.MILLISECONDS);
wsReq.setUpgradeListener(upgradeListener);
return wsReq.sendAsync();
}
Expand Down

0 comments on commit 6a8a6ef

Please sign in to comment.