Class TrolieClientBuilder

java.lang.Object
energy.trolie.client.TrolieClientBuilder

public class TrolieClientBuilder extends Object

Builder class used to construct new instances of the TROLIE client.

When configuring the TROLIE client, users should specifically be aware of two things:

  • The TROLIE client builds on the Apache Commons HTTP Client. While a default may be created for naive users, the client implementation itself is injectable, and users may control most of the advanced options of the HTTP client (proxies etc) as needed for their implementations.
  • Correct implementation of an ETagStore is critical to consuming ratings in a robust way. This marks the current version of data that this application (the TROLIE SDK user) has in its knowledge. The default implementation simply stores in memory. This may be fine for many uses, but applications may want to use their own storage (such as a database) for current data values.
  • Field Details

    • DEFAULT_BUFFER_SIZE

      public static final int DEFAULT_BUFFER_SIZE
      Default buffer size for BufferedInputStreams and BufferedOutputStreams.
      See Also:
  • Constructor Details

    • TrolieClientBuilder

      public TrolieClientBuilder(String baseUrl)
      Initializes a new builder with a preconfigured apache HTTP client
      Parameters:
      baseUrl - URL to the TROLIE service, such as https://trolie.example.com.
    • TrolieClientBuilder

      public TrolieClientBuilder(String baseUrl, org.apache.hc.client5.http.impl.classic.CloseableHttpClient httpClient)
      Initializes a new builder.
      Parameters:
      baseUrl - URL to the TROLIE service, such as https://trolie.example.com.
      httpClient - a pre-configured Apache HTTP client. The TROLIE client is built on top of the Apache HTTP client, and the full suite of configuration options for it are available. See examples for more detail.
  • Method Details

    • requestConfig

      public TrolieClientBuilder requestConfig(org.apache.hc.client5.http.config.RequestConfig config)
      Override the HTTP client request config
      Parameters:
      config - overridden config
      Returns:
      fluent builder
    • bufferSize

      public TrolieClientBuilder bufferSize(int bufferSize)
      Override the buffer size used in Java BufferedInputStreams and BufferedOutputStreams to optimize performance. Defaults to DEFAULT_BUFFER_SIZE.
      Parameters:
      bufferSize - new buffer size
      Returns:
      fluent builder.
    • objectMapper

      public TrolieClientBuilder objectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
      Overrides configuration of the Jackson object mapper using for JSON parsing and serialization
      Parameters:
      objectMapper - new object mapper
      Returns:
      fluent builder
    • etagStore

      public TrolieClientBuilder etagStore(ETagStore eTagStore)
      Overrides the ETag Store used to cache the version of data stored by this system.
      Parameters:
      eTagStore - new store
      Returns:
      fluent builder.
    • httpHeaders

      public TrolieClientBuilder httpHeaders(Map<String,String> httpHeaders)
      Allows for additional headers to be passed with every request.
      Parameters:
      httpHeaders - Key value pairs of additional header set to be passed with every request.
      Returns:
      fluent builder
    • periodLength

      public TrolieClientBuilder periodLength(int periodLengthMinutes)
      Sets the period length assumed for forecast ratings. Defaults to 60 minutes.
      Parameters:
      periodLengthMinutes - new assumed period length.
      Returns:
      fluent builder
    • forecastRatingsPollMs

      public TrolieClientBuilder forecastRatingsPollMs(int forecastRatingsPollMs)
      Sets the period at which TrolieClient.subscribeToInUseLimitForecastUpdates(ForecastSnapshotSubscribedReceiver) and similar methods for forecast ratings poll for new ratings. Defaults to 30 seconds
      Parameters:
      forecastRatingsPollMs - new poll periodicity in milliseconds
      Returns:
      fluent builder
    • realTimeRatingsPollMs

      public TrolieClientBuilder realTimeRatingsPollMs(int realTimeRatingsPollMs)
      Sets the period at which TrolieClient.subscribeToInUseLimits(RealTimeSnapshotSubscribedReceiver) and similar methods poll for new real-time ratings. Defaults to 10 seconds
      Parameters:
      realTimeRatingsPollMs - new poll periodicity in milliseconds
      Returns:
      fluent builder
    • monitoringSetPollMs

      public TrolieClientBuilder monitoringSetPollMs(int monitoringSetPollMs)
      Sets the period at which TrolieClient.subscribeToDefaultMonitoringSetUpdates(MonitoringSetsSubscribedReceiver) and similar methods poll for monitoring sets. Defaults to 60 seconds
      Parameters:
      monitoringSetPollMs - new poll periodicity in milliseconds
      Returns:
      fluent builder
    • build

      public TrolieClient build()
      Construct a new client
      Returns:
      new client