Class CachedAdapter
- Direct Known Subclasses:
CommoditiesTradeAdapter
,FXOrderAdapter
,FXPrecisionAdapter
,FXRatesAdapter
,FXTradeAdapter
,MMCalendarAdapter
,MMRatesAdapter
,UserDetailsAdapter
Provides a Single-Request, Single-Discard DataSource API for a DataProvider
and simplifies the Publisher
API. This class also handles multiple
peer requests for the same subscription by maintaining a cache, which is useful
for fail-over and redundancy scenarios.
CachedAdapter adapter = new CachedAdapter(dataSource); CachedPublisher publisher = adapter.createActivePublisher(new NamespacePrefix("/FX"), this, new FXSubjectParser());
-
Field Summary
-
Constructor Summary
ConstructorDescriptionCachedAdapter
(com.caplin.datasource.DataSource dataSource) Constructs a CachedAdapter to wrap requests made to the specified dataSource. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Clears the cache of subscriptions and cached records.<T extends SubjectInfo>
CachedPublishercreateActivePublisher
(com.caplin.datasource.namespace.Namespace namespace, CachedDataProvider<T> dataProvider, SubjectParser<T> parser) Deprecated.<T extends SubjectInfo>
CachedPublishercreateActivePublisher
(com.caplin.datasource.namespace.Namespace namespace, CachedDataProvider<T> dataProvider, SubjectParser<T> parser, boolean sendDiscardAfterError) <T extends SubjectInfo>
CachedPublishercreateCachedPublisher
(com.caplin.datasource.namespace.Namespace namespace, CachedDataProvider<T> dataProvider, SubjectParser<T> parser) Creates anCachedPublisher
that will publish messages on the specified Namespace.<T extends SubjectInfo>
CachedPublishercreateCachedPublisher
(com.caplin.datasource.namespace.Namespace namespace, CachedDataProvider<T> dataProvider, SubjectParser<T> parser, boolean sendDiscardAfterError) Creates anActivePublisher
that will publish messages on the specified Namespace.<T extends SubjectInfo>
CachedPublishercreateCachedPublisher
(String metricNamePrefix, com.caplin.datasource.namespace.Namespace namespace, CachedDataProvider<T> dataProvider, SubjectParser<T> parser) Creates anCachedPublisher
that will publish messages on the specified Namespace.<T extends SubjectInfo>
CachedPublishercreateCachedPublisher
(String name, com.caplin.datasource.namespace.Namespace namespace, CachedDataProvider<T> dataProvider, SubjectParser<T> parser, boolean sendDiscardAfterError) Creates anActivePublisher
that will publish messages on the specified Namespace.
-
Field Details
-
dataSource
protected final com.caplin.datasource.DataSource dataSource
-
-
Constructor Details
-
CachedAdapter
public CachedAdapter(com.caplin.datasource.DataSource dataSource) Constructs a CachedAdapter to wrap requests made to the specified dataSource.- Parameters:
dataSource
- The dataSource to wrap.
-
-
Method Details
-
createActivePublisher
@Deprecated public <T extends SubjectInfo> CachedPublisher createActivePublisher(com.caplin.datasource.namespace.Namespace namespace, CachedDataProvider<T> dataProvider, SubjectParser<T> parser) Creates anCachedPublisher
that will publish messages on the specified Namespace.This method uses a subject parser which allows subjects to be parsed into meaningful request objects.
- Type Parameters:
T
- The generic type erasure to provide compile time type-safety- Parameters:
namespace
- The namespace that the publisher will publish on.dataProvider
- The provider that will accept requests and discards.parser
- The parser that will parse subject requests into a object representation of the request.- Returns:
- The CachedPublisher to use for publishing messages.
-
createActivePublisher
@Deprecated public <T extends SubjectInfo> CachedPublisher createActivePublisher(com.caplin.datasource.namespace.Namespace namespace, CachedDataProvider<T> dataProvider, SubjectParser<T> parser, boolean sendDiscardAfterError) Creates anCachedPublisher
that will publish messages on the specified Namespace.This method uses a subject parser which allows subjects to be parsed into meaningful request objects
- Type Parameters:
T
- The generic type erasure to provide compile time type-safety- Parameters:
namespace
- The namespace that the publisher will publish on.dataProvider
- The provider that will accept requests and discards.parser
- The parser that will parse subject requests into a object representation of the request.sendDiscardAfterError
- If set to TRUE, your DataProvider will receive an immediate callback on theCachedDataProvider.onDiscard(SubjectInfo)
method after you publish a failure message by callingCachedPublisher.sendNotFound(String)
orCachedPublisher.sendUnavailable(String)
. This can be useful if you want to use the same code path to clear a cache (for example) whether a subscription is ended by the client discarding it or the back end you are integrating with no longer providing the data.- Returns:
- The CachedPublisher to use for publishing messages.
-
createCachedPublisher
public <T extends SubjectInfo> CachedPublisher createCachedPublisher(com.caplin.datasource.namespace.Namespace namespace, CachedDataProvider<T> dataProvider, SubjectParser<T> parser) Creates anCachedPublisher
that will publish messages on the specified Namespace.This method uses a subject parser which allows subjects to be parsed into meaningful request objects.
- Type Parameters:
T
- The generic type erasure to provide compile time type-safety- Parameters:
namespace
- The namespace that the publisher will publish on.dataProvider
- The provider that will accept requests and discards.parser
- The parser that will parse subject requests into a object representation of the request.- Returns:
- The CachedPublisher to use for publishing messages.
-
createCachedPublisher
public <T extends SubjectInfo> CachedPublisher createCachedPublisher(String metricNamePrefix, com.caplin.datasource.namespace.Namespace namespace, CachedDataProvider<T> dataProvider, SubjectParser<T> parser) Creates anCachedPublisher
that will publish messages on the specified Namespace.This method uses a subject parser which allows subjects to be parsed into meaningful request objects.
- Type Parameters:
T
- The generic type erasure to provide compile time type-safety- Parameters:
namespace
- The namespace that the publisher will publish on.dataProvider
- The provider that will accept requests and discards.parser
- The parser that will parse subject requests into a object representation of the request.metricNamePrefix
- The prefix of the metric name- Returns:
- The CachedPublisher to use for publishing messages.
-
createCachedPublisher
public <T extends SubjectInfo> CachedPublisher createCachedPublisher(com.caplin.datasource.namespace.Namespace namespace, CachedDataProvider<T> dataProvider, SubjectParser<T> parser, boolean sendDiscardAfterError) Creates anActivePublisher
that will publish messages on the specified Namespace.This method uses a subject parser which allows subjects to be parsed into meaningful request objects
- Type Parameters:
T
- The generic type erasure to provide compile time type-safety- Parameters:
namespace
- The namespace that the publisher will publish on.dataProvider
- The provider that will accept requests and discards.parser
- The parser that will parse subject requests into a object representation of the request.sendDiscardAfterError
- If set to TRUE, your DataProvider will receive an immediate callback on theCachedDataProvider.onDiscard(SubjectInfo)
method after you publish a failure message by callingCachedPublisher.sendNotFound(String)
orCachedPublisher.sendUnavailable(String)
. This can be useful if you want to use the same code path to clear a cache (for example) whether a subscription is ended by the client discarding it or the back end you are integrating with no longer providing the data.- Returns:
- The CachedPublisher to use for publishing messages.
-
createCachedPublisher
public <T extends SubjectInfo> CachedPublisher createCachedPublisher(String name, com.caplin.datasource.namespace.Namespace namespace, CachedDataProvider<T> dataProvider, SubjectParser<T> parser, boolean sendDiscardAfterError) Creates anActivePublisher
that will publish messages on the specified Namespace.This method uses a subject parser which allows subjects to be parsed into meaningful request objects
- Type Parameters:
T
- The generic type erasure to provide compile time type-safety- Parameters:
name
- The prefix that will be used on publisher metrics.namespace
- The namespace that the publisher will publish on.dataProvider
- The provider that will accept requests and discards.parser
- The parser that will parse subject requests into a object representation of the request.sendDiscardAfterError
- If set to TRUE, your DataProvider will receive an immediate callback on theCachedDataProvider.onDiscard(SubjectInfo)
method after you publish a failure message by callingCachedPublisher.sendNotFound(String)
orCachedPublisher.sendUnavailable(String)
. This can be useful if you want to use the same code path to clear a cache (for example) whether a subscription is ended by the client discarding it or the back end you are integrating with no longer providing the data.- Returns:
- The CachedPublisher to use for publishing messages.
-
clearCache
public void clearCache()Clears the cache of subscriptions and cached records. Only invoke this method when a peer down message has been received.
-
createCachedPublisher(Namespace, CachedDataProvider, SubjectParser)