Class BackgroundEventSource.Builder
- java.lang.Object
-
- com.launchdarkly.eventsource.background.BackgroundEventSource.Builder
-
- Enclosing class:
- BackgroundEventSource
public static class BackgroundEventSource.Builder extends java.lang.Object
Builder for configuringBackgroundEventSource
.
-
-
Constructor Summary
Constructors Constructor Description Builder(BackgroundEventHandler handler, EventSource.Builder eventSourceBuilder)
Creates a builder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BackgroundEventSource
build()
Creates aBackgroundEventSource
with this configuration.BackgroundEventSource.Builder
connectionErrorHandler(ConnectionErrorHandler handler)
Sets theConnectionErrorHandler
that should process connection errors.BackgroundEventSource.Builder
eventsExecutor(java.util.concurrent.Executor eventsExecutor)
Specifies a custom executor to use for dispatching events.BackgroundEventSource.Builder
maxEventTasksInFlight(int maxEventTasksInFlight)
Specifies the maximum number of tasks that can be "in-flight" for the thread executingBackgroundEventHandler
.BackgroundEventSource.Builder
streamExecutor(java.util.concurrent.Executor streamExecutor)
Specifies a custom executor to use for running the stream-reading task.BackgroundEventSource.Builder
threadBaseName(java.lang.String threadBaseName)
Set the name for this BackgroundEventSource to be used when naming thread pools, when BackgroundEventSource is using its default executors.BackgroundEventSource.Builder
threadPriority(java.lang.Integer threadPriority)
Specifies the priority for threads created by BackgroundEventSource using its default executors.
-
-
-
Constructor Detail
-
Builder
public Builder(BackgroundEventHandler handler, EventSource.Builder eventSourceBuilder)
Creates a builder.- Parameters:
handler
- the event handlereventSourceBuilder
- builder for the underlying EventSource
-
-
Method Detail
-
build
public BackgroundEventSource build()
Creates aBackgroundEventSource
with this configuration.The stream is not started until you call
BackgroundEventSource.start()
.- Returns:
- the configured
BackgroundEventSource
-
connectionErrorHandler
public BackgroundEventSource.Builder connectionErrorHandler(ConnectionErrorHandler handler)
Sets theConnectionErrorHandler
that should process connection errors.- Parameters:
handler
- the error handler- Returns:
- the builder
-
eventsExecutor
public BackgroundEventSource.Builder eventsExecutor(java.util.concurrent.Executor eventsExecutor)
Specifies a custom executor to use for dispatching events.If you do not specify a custom executor, the default is to call
Executors.newSingleThreadExecutor(java.util.concurrent.ThreadFactory)
, using a simple thread factory that creates daemon threads whose properties are based onthreadBaseName(String)
andthreadPriority(Integer)
. This executor will be shut down when you close the BackgroundEventSource.If you do specify a custom executor, it will not be shut down when you close the BackgroundEventSource; you are responsible for its lifecycle.
- Parameters:
eventsExecutor
- an executor, or null to use the default behavior- Returns:
- the builder
-
maxEventTasksInFlight
public BackgroundEventSource.Builder maxEventTasksInFlight(int maxEventTasksInFlight)
Specifies the maximum number of tasks that can be "in-flight" for the thread executingBackgroundEventHandler
. A semaphore will be used to artificially constrain the number of tasks sitting in the queue fronting the event handler thread. When this limit is reached the stream thread will block until the backpressure passes.The default is no maximum.
- Parameters:
maxEventTasksInFlight
- the maximum number of tasks/messages that can be in-flight for theBackgorundEventHandler
- Returns:
- the builder
-
streamExecutor
public BackgroundEventSource.Builder streamExecutor(java.util.concurrent.Executor streamExecutor)
Specifies a custom executor to use for running the stream-reading task.If you do not specify a custom executor, the default is to call
Executors.newSingleThreadExecutor(java.util.concurrent.ThreadFactory)
, using a simple thread factory that creates daemon threads whose properties are based onthreadBaseName(String)
andthreadPriority(Integer)
. This executor will be shut down when you close the BackgroundEventSource.If you do specify a custom executor, it will not be shut down when you close the BackgroundEventSource; you are responsible for its lifecycle.
- Parameters:
streamExecutor
- an executor, or null to use the default behavior- Returns:
- the builder
-
threadBaseName
public BackgroundEventSource.Builder threadBaseName(java.lang.String threadBaseName)
Set the name for this BackgroundEventSource to be used when naming thread pools, when BackgroundEventSource is using its default executors.This is mainly useful when multiple BackgroundEventSource instances exist within the same process.
This setting is ignored if you have specified a custom executor with
eventsExecutor(Executor)
orstreamExecutor(Executor)
.- Parameters:
threadBaseName
- a string to be used in worker thread names (must not contain spaces)- Returns:
- the builder
-
threadPriority
public BackgroundEventSource.Builder threadPriority(java.lang.Integer threadPriority)
Specifies the priority for threads created by BackgroundEventSource using its default executors.If this is left unset, or set to
null
, threads will inherit the default priority provided byExecutors.defaultThreadFactory()
.This setting is ignored if you have specified a custom executor with
eventsExecutor(Executor)
orstreamExecutor(Executor)
.- Parameters:
threadPriority
- the thread priority, or null to use the default- Returns:
- the builder
-
-