public class CachedAdapter extends Object
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());
Constructor and Description |
---|
CachedAdapter(com.caplin.datasource.DataSource dataSource)
Constructs a CachedAdapter to wrap requests made to the specified
dataSource.
|
Modifier and Type | Method and Description |
---|---|
void |
clearCache()
Clears the cache of subscriptions and cached records.
|
<T extends SubjectInfo> |
createActivePublisher(com.caplin.datasource.namespace.Namespace namespace,
CachedDataProvider<T> dataProvider,
SubjectParser<T> parser)
|
<T extends SubjectInfo> |
createActivePublisher(com.caplin.datasource.namespace.Namespace namespace,
CachedDataProvider<T> dataProvider,
SubjectParser<T> parser,
boolean sendDiscardAfterError)
|
<T extends SubjectInfo> |
createCachedPublisher(com.caplin.datasource.namespace.Namespace namespace,
CachedDataProvider<T> dataProvider,
SubjectParser<T> parser)
Creates an
CachedPublisher that will
publish messages on the specified Namespace. |
<T extends SubjectInfo> |
createCachedPublisher(com.caplin.datasource.namespace.Namespace namespace,
CachedDataProvider<T> dataProvider,
SubjectParser<T> parser,
boolean sendDiscardAfterError)
Creates an
ActivePublisher that will
publish messages on the specified Namespace. |
<T extends SubjectInfo> |
createCachedPublisher(String metricNamePrefix,
com.caplin.datasource.namespace.Namespace namespace,
CachedDataProvider<T> dataProvider,
SubjectParser<T> parser)
Creates an
CachedPublisher that will
publish messages on the specified Namespace. |
<T extends SubjectInfo> |
createCachedPublisher(String name,
com.caplin.datasource.namespace.Namespace namespace,
CachedDataProvider<T> dataProvider,
SubjectParser<T> parser,
boolean sendDiscardAfterError)
Creates an
ActivePublisher that will
publish messages on the specified Namespace. |
public CachedAdapter(com.caplin.datasource.DataSource dataSource)
dataSource
- The dataSource to wrap.@Deprecated public <T extends SubjectInfo> CachedPublisher createActivePublisher(com.caplin.datasource.namespace.Namespace namespace, CachedDataProvider<T> dataProvider, SubjectParser<T> parser)
CachedPublisher
that will
publish messages on the specified Namespace.
This method uses a subject parser which allows subjects to be parsed into meaningful request objects.
T
- The generic type erasure to provide compile time type-safetynamespace
- 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.@Deprecated public <T extends SubjectInfo> CachedPublisher createActivePublisher(com.caplin.datasource.namespace.Namespace namespace, CachedDataProvider<T> dataProvider, SubjectParser<T> parser, boolean sendDiscardAfterError)
CachedPublisher
that will
publish messages on the specified Namespace.
This method uses a subject parser which allows subjects to be parsed into meaningful request objects
T
- The generic type erasure to provide compile time type-safetynamespace
- 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 the CachedDataProvider.onDiscard(SubjectInfo)
method
after you publish a failure message by calling CachedPublisher.sendNotFound(String)
or
CachedPublisher.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.public <T extends SubjectInfo> CachedPublisher createCachedPublisher(com.caplin.datasource.namespace.Namespace namespace, CachedDataProvider<T> dataProvider, SubjectParser<T> parser)
CachedPublisher
that will
publish messages on the specified Namespace.
This method uses a subject parser which allows subjects to be parsed into meaningful request objects.
T
- The generic type erasure to provide compile time type-safetynamespace
- 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.public <T extends SubjectInfo> CachedPublisher createCachedPublisher(String metricNamePrefix, com.caplin.datasource.namespace.Namespace namespace, CachedDataProvider<T> dataProvider, SubjectParser<T> parser)
CachedPublisher
that will
publish messages on the specified Namespace.
This method uses a subject parser which allows subjects to be parsed into meaningful request objects.
T
- The generic type erasure to provide compile time type-safetynamespace
- 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 namepublic <T extends SubjectInfo> CachedPublisher createCachedPublisher(com.caplin.datasource.namespace.Namespace namespace, CachedDataProvider<T> dataProvider, SubjectParser<T> parser, boolean sendDiscardAfterError)
ActivePublisher
that will
publish messages on the specified Namespace.
This method uses a subject parser which allows subjects to be parsed into meaningful request objects
T
- The generic type erasure to provide compile time type-safetynamespace
- 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 the CachedDataProvider.onDiscard(SubjectInfo)
method
after you publish a failure message by calling CachedPublisher.sendNotFound(String)
or
CachedPublisher.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.public <T extends SubjectInfo> CachedPublisher createCachedPublisher(String name, com.caplin.datasource.namespace.Namespace namespace, CachedDataProvider<T> dataProvider, SubjectParser<T> parser, boolean sendDiscardAfterError)
ActivePublisher
that will
publish messages on the specified Namespace.
This method uses a subject parser which allows subjects to be parsed into meaningful request objects
T
- The generic type erasure to provide compile time type-safetyname
- 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 the CachedDataProvider.onDiscard(SubjectInfo)
method
after you publish a failure message by calling CachedPublisher.sendNotFound(String)
or
CachedPublisher.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.public void clearCache()
Copyright © 2020 Caplin Systems.