Class DataSource

  • Direct Known Subclasses:
    CompositeDataSource

    public abstract class DataSource
    extends Object
    A source for data that is going to be processed by the general purpose client. The GP client can work with more than one source at a time. Support for each different source can be added by external libraries.

    To implement a datasource, one has to implement the createChannel(java.lang.String) method, and requests will be forwarded to the channel accordingly. The channels are automatically cached and reused. The name under which the channels are looked up in the cache or registered in the cache is configurable.

    Channel handlers can be implemented from scratch, or one can use the MultiplexedChannelHandler for handlers that want to open a single connection which is going to be shared by all readers and writers.

    Author:
    carcassi
    • Constructor Detail

      • DataSource

        public DataSource()
    • Method Detail

      • channelHandlerLookupName

        protected String channelHandlerLookupName​(String channelName)
        Returns the lookup name to use to find the channel handler in the cache. By default, it returns the channel name itself. If a datasource needs multiple different channel names to be the same channel handler (e.g. parts of the channel name are initialization parameters) then it can override this method to change the lookup.
        Parameters:
        channelName - the channel name
        Returns:
        the channel handler to look up in the cache
      • channelHandlerRegisterName

        protected String channelHandlerRegisterName​(String channelName,
                                                    ChannelHandler handler)
        Returns the name the given handler should be registered as. By default, it returns the lookup name, so that lookup and registration in the cache are consistent. If a datasource needs multiple different channel names to be the same channel handler (e.g. parts of the channel name are read/write parameters) then it can override this method to change the registration.
        Parameters:
        channelName - the name under which the ChannelHandler was created
        handler - the handler to register
        Returns:
        the name under which to register in the cache
      • createChannel

        protected abstract ChannelHandler createChannel​(String channelName)
        Creates a channel handler for the given name. In the simplest case, this is the only method a data source needs to implement.
        Parameters:
        channelName - the name for a new channel
        Returns:
        a new handler
      • startRead

        public void startRead​(ReadSubscription readSubscription)
        Starts the given read subscription.
        Parameters:
        readSubscription - the subscription information
      • stopRead

        public void stopRead​(ReadSubscription readSubscription)
        Stops the given read subscription.
        Parameters:
        readSubscription - the subscription information
      • startWrite

        public void startWrite​(WriteSubscription writeSubscription)
        Starts the given write subscription.
        Parameters:
        writeSubscription - the subscription information
      • stopWrite

        public void stopWrite​(WriteSubscription writeRecipe)
        Stops the given write subscription.
        Parameters:
        writeRecipe - the subscription information
      • getChannels

        public Map<String,​ChannelHandler> getChannels()
        Returns the channel handlers for this data source.
        Returns:
        an unmodifiable collection
      • close

        public void close()
        Closes the DataSource and the resources associated with it.