Class BackgroundEventSource.Builder
- Enclosing class:
- BackgroundEventSource
BackgroundEventSource.-
Constructor Summary
ConstructorsConstructorDescriptionBuilder(BackgroundEventHandler handler, EventSource.Builder eventSourceBuilder) Creates a builder. -
Method Summary
Modifier and TypeMethodDescriptionbuild()Creates aBackgroundEventSourcewith this configuration.Sets theConnectionErrorHandlerthat should process connection errors.eventsExecutor(Executor eventsExecutor) Specifies a custom executor to use for dispatching events.maxEventTasksInFlight(int maxEventTasksInFlight) Specifies the maximum number of tasks that can be "in-flight" for the thread executingBackgroundEventHandler.streamExecutor(Executor streamExecutor) Specifies a custom executor to use for running the stream-reading task.threadBaseName(String threadBaseName) Set the name for this BackgroundEventSource to be used when naming thread pools, when BackgroundEventSource is using its default executors.threadPriority(Integer threadPriority) Specifies the priority for threads created by BackgroundEventSource using its default executors.
-
Constructor Details
-
Builder
Creates a builder.- Parameters:
handler- the event handlereventSourceBuilder- builder for the underlying EventSource
-
-
Method Details
-
build
Creates aBackgroundEventSourcewith this configuration.The stream is not started until you call
BackgroundEventSource.start().- Returns:
- the configured
BackgroundEventSource
-
connectionErrorHandler
Sets theConnectionErrorHandlerthat should process connection errors.- Parameters:
handler- the error handler- Returns:
- the builder
-
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
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
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
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
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
-