Class ConnectStrategy
- Direct Known Subclasses:
HttpConnectStrategy
EventSource should obtain an input stream.
The default implementation is HttpConnectStrategy, which makes HTTP
requests. To customize the HTTP behavior, you can use methods of
HttpConnectStrategy:
EventSource.Builder builder = new EventSource.Builder(
ConnectStrategy.http(myStreamUri)
.headers(myCustomHeaders)
.connectTimeout(10, TimeUnit.SECONDS)
);
Or, if you want to consume an input stream from some other source, you can
create your own subclass of ConnectStrategy.
Instances of this class should be immutable and not contain any state that
is specific to one active stream. The ConnectStrategy.Client that
they produce is stateful and belongs to a single EventSource.
- Since:
- 4.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAn object provided byConnectStrategythat is retained by a singleEventSourceinstance to perform all connection attempts by that instance. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract ConnectStrategy.ClientcreateClient(LDLogger logger) Creates a client instance.static HttpConnectStrategyReturns the default HTTP implementation, specifying a stream URI.static HttpConnectStrategyReturns the default HTTP implementation, specifying a stream URL.static HttpConnectStrategyhttp(okhttp3.HttpUrl url) Returns the default HTTP implementation, specifying a stream URI.
-
Constructor Details
-
ConnectStrategy
public ConnectStrategy()
-
-
Method Details
-
createClient
Creates a client instance.This is called once when an EventSource is created. The EventSource retains the returned Client and uses it to perform all subsequent connection attempts.
- Parameters:
logger- the logger belonging to EventSource- Returns:
- a
ConnectStrategy.Clientinstance
-
http
Returns the default HTTP implementation, specifying a stream URI.To specify custom HTTP behavior, call
HttpConnectStrategymethods on the returned object to obtain a modified instance:EventSource.Builder builder = new EventSource.Builder( ConnectStrategy.http(myStreamUri) .headers(myCustomHeaders) .connectTimeout(10, TimeUnit.SECONDS) );- Parameters:
uri- the stream URI- Returns:
- a configurable
HttpConnectStrategy - Throws:
IllegalArgumentException- if the argument is null, or if the scheme is not HTTP or HTTPS- See Also:
-
http
Returns the default HTTP implementation, specifying a stream URL.- Parameters:
url- the stream URL- Returns:
- a configurable
HttpConnectStrategy - Throws:
IllegalArgumentException- if the argument is null, or if the scheme is not HTTP or HTTPS- See Also:
-
http
Returns the default HTTP implementation, specifying a stream URI.This is the same as
http(URI), but uses the okhttp typeHttpUrl.- Parameters:
url- the stream URL- Returns:
- a configurable
HttpConnectStrategy - Throws:
IllegalArgumentException- if the argument is null, or if the scheme is not HTTP or HTTPS- See Also:
-