Package energy.trolie.client
Class TrolieClientBuilder
java.lang.Object
energy.trolie.client.TrolieClientBuilder
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Default buffer size for BufferedInputStreams and BufferedOutputStreams. -
Constructor Summary
ConstructorsConstructorDescriptionTrolieClientBuilder
(String baseUrl) Initializes a new builder with a preconfigured apache HTTP clientTrolieClientBuilder
(String baseUrl, org.apache.hc.client5.http.impl.classic.CloseableHttpClient httpClient) Initializes a new builder. -
Method Summary
Modifier and TypeMethodDescriptionbufferSize
(int bufferSize) Override the buffer size used in Java BufferedInputStreams and BufferedOutputStreams to optimize performance.build()
Construct a new clientOverrides the ETag Store used to cache the version of data stored by this system.forecastRatingsPollMs
(int forecastRatingsPollMs) Sets the period at whichTrolieClient.subscribeToInUseLimitForecastUpdates(ForecastSnapshotSubscribedReceiver)
and similar methods for forecast ratings poll for new ratings.httpHeaders
(Map<String, String> httpHeaders) Allows for additional headers to be passed with every request.monitoringSetPollMs
(int monitoringSetPollMs) Sets the period at whichTrolieClient.subscribeToDefaultMonitoringSetUpdates(MonitoringSetsSubscribedReceiver)
and similar methods poll for monitoring sets.objectMapper
(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Overrides configuration of the Jackson object mapper using for JSON parsing and serializationperiodLength
(int periodLengthMinutes) Sets the period length assumed for forecast ratings.realTimeRatingsPollMs
(int realTimeRatingsPollMs) Sets the period at whichTrolieClient.subscribeToInUseLimits(RealTimeSnapshotSubscribedReceiver)
and similar methods poll for new real-time ratings.requestConfig
(org.apache.hc.client5.http.config.RequestConfig config) Override the HTTP client request config
-
Field Details
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZEDefault buffer size for BufferedInputStreams and BufferedOutputStreams.- See Also:
-
-
Constructor Details
-
TrolieClientBuilder
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
Override the HTTP client request config- Parameters:
config
- overridden config- Returns:
- fluent builder
-
bufferSize
Override the buffer size used in Java BufferedInputStreams and BufferedOutputStreams to optimize performance. Defaults toDEFAULT_BUFFER_SIZE
.- Parameters:
bufferSize
- new buffer size- Returns:
- fluent builder.
-
objectMapper
Overrides configuration of the Jackson object mapper using for JSON parsing and serialization- Parameters:
objectMapper
- new object mapper- Returns:
- fluent builder
-
etagStore
Overrides the ETag Store used to cache the version of data stored by this system.- Parameters:
eTagStore
- new store- Returns:
- fluent builder.
-
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
Sets the period length assumed for forecast ratings. Defaults to 60 minutes.- Parameters:
periodLengthMinutes
- new assumed period length.- Returns:
- fluent builder
-
forecastRatingsPollMs
Sets the period at whichTrolieClient.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
Sets the period at whichTrolieClient.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
Sets the period at whichTrolieClient.subscribeToDefaultMonitoringSetUpdates(MonitoringSetsSubscribedReceiver)
and similar methods poll for monitoring sets. Defaults to 60 seconds- Parameters:
monitoringSetPollMs
- new poll periodicity in milliseconds- Returns:
- fluent builder
-
build
Construct a new client- Returns:
- new client
-