Class 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
ETagStoreis 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 intDefault 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 TypeMethodDescriptionAdds a request header provider that can generate additional headers for each request execution.bufferSize(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 configrequestHeaderProviders(List<RequestHeaderProvider> providers) Replaces the current set of request header providers with the given list.seasonalRatingsPollMs(int seasonalRatingsPollMs) Sets the period at whichTrolieClient.subscribeToInUseSeasonalSnapshotUpdates(SeasonalSnapshotSubscribedReceiver)and similar methods for forecast ratings poll for new ratings.withSppAuthentication(String screenName, String apiKey) Configures this client to authenticate with an SPP system using the SPP Two-Factor Authentication (TFA) protocol.
-
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
-
addRequestHeaderProvider
Adds a request header provider that can generate additional headers for each request execution. Providers are invoked during the initial request construction.Note: If the underlying
HttpClientis configured with automatic retries, the same request object (and its headers) may be sent multiple times. To ensure security-sensitive headers like nonces are regenerated, users should ensure that automatic retries are disabled or that the client is configured to rebuild requests on retry.- Parameters:
provider- provider used to generate request-specific headers- Returns:
- fluent builder
-
requestHeaderProviders
Replaces the current set of request header providers with the given list. Providers are invoked during the initial request construction.Note: If the underlying
HttpClientis configured with automatic retries, the request (including these headers) may be reused across multiple attempts. To guarantee fresh header values (e.g., new nonces) on retry, implementers must ensure that automatic transport-level retries are disabled or that the client is configured to rebuild requests on retry.- Parameters:
providers- list of providers used to generate request-specific headers- 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
-
seasonalRatingsPollMs
Sets the period at whichTrolieClient.subscribeToInUseSeasonalSnapshotUpdates(SeasonalSnapshotSubscribedReceiver)and similar methods for forecast ratings poll for new ratings. Defaults to 30 seconds- Parameters:
seasonalRatingsPollMs- new poll periodicity in milliseconds- Returns:
- fluent builder
-
withSppAuthentication
Configures this client to authenticate with an SPP system using the SPP Two-Factor Authentication (TFA) protocol.- Parameters:
screenName- the SPP-assigned screen nameapiKey- the Base64-encoded API key assigned by SPP- Returns:
- this builder
- See Also:
-
build
Construct a new client- Returns:
- new client
-