Class CachedAdapter
- java.lang.Object
-
- com.caplin.motif.datasource.CachedAdapter
-
- Direct Known Subclasses:
FXConfigAdapter
,FXOrderAdapter
,FXPrecisionAdapter
,FXRatesAdapter
,FXTradeAdapter
,MMCalendarAdapter
,MMRatesAdapter
,UserDetailsAdapter
public class CachedAdapter extends java.lang.Object
Provides a Single-Request, Single-Discard DataSource API for a
Usage:DataProvider
and simplifies thePublisher
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 Summary
Constructors Constructor Description CachedAdapter(com.caplin.datasource.DataSource dataSource)
Constructs a CachedAdapter to wrap requests made to the specified dataSource.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
clearCache()
Clears the cache of subscriptions and cached records.<T extends SubjectInfo>
CachedPublishercreateActivePublisher(com.caplin.datasource.namespace.Namespace namespace, CachedDataProvider<T> dataProvider, SubjectParser<T> parser)
<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(java.lang.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(java.lang.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.
-
-
-
Method Detail
-
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(java.lang.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(java.lang.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.
-
-