Class 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 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 Detail

      • 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 Detail

      • createActivePublisher

        @Deprecated
        public <T extends SubjectInfoCachedPublisher createActivePublisher​(com.caplin.datasource.namespace.Namespace namespace,
                                                                             CachedDataProvider<T> dataProvider,
                                                                             SubjectParser<T> parser)
        Creates an 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.

        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 SubjectInfoCachedPublisher createActivePublisher​(com.caplin.datasource.namespace.Namespace namespace,
                                                                             CachedDataProvider<T> dataProvider,
                                                                             SubjectParser<T> parser,
                                                                             boolean sendDiscardAfterError)
        Creates an 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

        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 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.
        Returns:
        The CachedPublisher to use for publishing messages.
      • createCachedPublisher

        public <T extends SubjectInfoCachedPublisher createCachedPublisher​(com.caplin.datasource.namespace.Namespace namespace,
                                                                             CachedDataProvider<T> dataProvider,
                                                                             SubjectParser<T> parser)
        Creates an 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.

        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 SubjectInfoCachedPublisher createCachedPublisher​(java.lang.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.

        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 SubjectInfoCachedPublisher 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.

        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 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.
        Returns:
        The CachedPublisher to use for publishing messages.
      • createCachedPublisher

        public <T extends SubjectInfoCachedPublisher createCachedPublisher​(java.lang.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.

        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 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.
        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.