Class ConnectStrategy
- java.lang.Object
-
- com.launchdarkly.eventsource.ConnectStrategy
-
- Direct Known Subclasses:
HttpConnectStrategy
public abstract class ConnectStrategy extends java.lang.Object
An abstraction of howEventSource
should obtain an input stream.The default implementation is
HttpConnectStrategy
, which makes HTTP requests. To customize the HTTP behavior, you can use methods ofHttpConnectStrategy
: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 Classes Modifier and Type Class Description static class
ConnectStrategy.Client
An object provided byConnectStrategy
that is retained by a singleEventSource
instance to perform all connection attempts by that instance.
-
Constructor Summary
Constructors Constructor Description ConnectStrategy()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract ConnectStrategy.Client
createClient(LDLogger logger)
Creates a client instance.static HttpConnectStrategy
http(java.net.URI uri)
Returns the default HTTP implementation, specifying a stream URI.static HttpConnectStrategy
http(java.net.URL url)
Returns the default HTTP implementation, specifying a stream URL.static HttpConnectStrategy
http(okhttp3.HttpUrl url)
Returns the default HTTP implementation, specifying a stream URI.
-
-
-
Method Detail
-
createClient
public abstract ConnectStrategy.Client createClient(LDLogger logger)
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.Client
instance
-
http
public static HttpConnectStrategy http(java.net.URI uri)
Returns the default HTTP implementation, specifying a stream URI.To specify custom HTTP behavior, call
HttpConnectStrategy
methods 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:
java.lang.IllegalArgumentException
- if the argument is null, or if the scheme is not HTTP or HTTPS- See Also:
http(HttpUrl)
-
http
public static HttpConnectStrategy http(java.net.URL url)
Returns the default HTTP implementation, specifying a stream URL.This is the same as
http(URI)
, but uses theURL
type.- Parameters:
url
- the stream URL- Returns:
- a configurable
HttpConnectStrategy
- Throws:
java.lang.IllegalArgumentException
- if the argument is null, or if the scheme is not HTTP or HTTPS- See Also:
http(HttpUrl)
-
http
public static HttpConnectStrategy http(okhttp3.HttpUrl url)
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:
java.lang.IllegalArgumentException
- if the argument is null, or if the scheme is not HTTP or HTTPS- See Also:
http(URI)
-
-