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.
Usage:
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.
|
CachedPublisher |
createActivePublisher(com.caplin.datasource.namespace.Namespace namespace,
CachedDataProvider<?> dataProvider,
SubjectParser<?> parser)
Creates an
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, for example the FXSubjectInfo . |
CachedPublisher |
createActivePublisher(com.caplin.datasource.namespace.Namespace namespace,
CachedDataProvider<?> dataProvider,
SubjectParser<?> parser,
boolean sendDiscardAfterError)
Creates an
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, for example the FXSubjectInfo |
CachedPublisher |
createActivePublisher(com.caplin.datasource.namespace.Namespace namespace,
com.caplin.datasource.publisher.DataProvider dataProvider)
Creates an
ActivePublisher that will
publish messages on the specified Namespace.. |
CachedPublisher |
createActivePublisher(com.caplin.datasource.namespace.Namespace namespace,
com.caplin.datasource.publisher.DataProvider dataProvider,
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.public CachedPublisher createActivePublisher(com.caplin.datasource.namespace.Namespace namespace, com.caplin.datasource.publisher.DataProvider dataProvider)
ActivePublisher
that will
publish messages on the specified Namespace..
Only use this method if you need to use a DataProvider instance,
otherwise use
createActivePublisher(com.caplin.datasource.namespace.Namespace, CachedDataProvider, SubjectParser)
Also note that the Peer returned by RequestEvent.getPeer()
and DiscardEvent.getPeer() will always be the first peer that made
the request.namespace
- The namespace that the publisher will publish on.dataProvider
- The provider that will accept requests and discards.public CachedPublisher createActivePublisher(com.caplin.datasource.namespace.Namespace namespace, com.caplin.datasource.publisher.DataProvider dataProvider, boolean sendDiscardAfterError)
ActivePublisher
that will
publish messages on the specified Namespace..
Only use this method if you need to use a DataProvider instance,
otherwise use
createActivePublisher(com.caplin.datasource.namespace.Namespace, CachedDataProvider, SubjectParser)
Also note that the Peer return by RequestEvent.getPeer()
and DiscardEvent.getPeer() will always be the first peer that made
the request.namespace
- The namespace that the publisher will publish on.dataProvider
- The provider that will accept requests and discards.sendDiscardAfterError
- If set to TRUE, your DataProvider will receive an
immediate callback on the DataProvider.onDiscard(com.caplin.datasource.publisher.DiscardEvent)
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 CachedPublisher createActivePublisher(com.caplin.datasource.namespace.Namespace namespace, CachedDataProvider<?> dataProvider, SubjectParser<?> parser)
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, for example the FXSubjectInfo
.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.public CachedPublisher createActivePublisher(com.caplin.datasource.namespace.Namespace namespace, CachedDataProvider<?> dataProvider, SubjectParser<?> 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, for example the FXSubjectInfo
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 © 2015 Caplin Systems.