Class BackgroundEventSource.Builder

java.lang.Object
com.launchdarkly.eventsource.background.BackgroundEventSource.Builder
Enclosing class:
BackgroundEventSource

public static class BackgroundEventSource.Builder extends Object
Builder for configuring BackgroundEventSource.
  • Constructor Details

    • Builder

      public Builder(BackgroundEventHandler handler, EventSource.Builder eventSourceBuilder)
      Creates a builder.
      Parameters:
      handler - the event handler
      eventSourceBuilder - builder for the underlying EventSource
  • Method Details

    • build

      public BackgroundEventSource build()
      Creates a BackgroundEventSource 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 the ConnectionErrorHandler that should process connection errors.
      Parameters:
      handler - the error handler
      Returns:
      the builder
    • eventsExecutor

      public BackgroundEventSource.Builder eventsExecutor(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 on threadBaseName(String) and threadPriority(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 executing BackgroundEventHandler. 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 the BackgorundEventHandler
      Returns:
      the builder
    • streamExecutor

      public BackgroundEventSource.Builder streamExecutor(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 on threadBaseName(String) and threadPriority(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(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) or streamExecutor(Executor).

      Parameters:
      threadBaseName - a string to be used in worker thread names (must not contain spaces)
      Returns:
      the builder
    • threadPriority

      public BackgroundEventSource.Builder threadPriority(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 by Executors.defaultThreadFactory().

      This setting is ignored if you have specified a custom executor with eventsExecutor(Executor) or streamExecutor(Executor).

      Parameters:
      threadPriority - the thread priority, or null to use the default
      Returns:
      the builder