Class CompositeDataSource


  • public class CompositeDataSource
    extends DataSource
    A data source that can dispatch a request to multiple different data sources.

    This supports lazy initialization of DataSources: DataSourceProviders are initialized only if the a channel of the corresponding DataSource is opened. There is not penalty, then, if no channel is every opened.

    Author:
    carcassi
    • Constructor Detail

      • CompositeDataSource

        public CompositeDataSource()
        Creates a new CompositeDataSource.
      • CompositeDataSource

        public CompositeDataSource​(CompositeDataSourceConfiguration conf)
        Creates a new CompositeDataSource with the given configuration.
        Parameters:
        conf - the configuration for the new CompositeDataSource
    • Method Detail

      • getConfiguration

        public CompositeDataSourceConfiguration getConfiguration()
        The configuration used for the composite data source.
        Returns:
        the configuration; can't be null
      • putDataSource

        public void putDataSource​(String name,
                                  DataSource dataSource)
        Adds/replaces the data source corresponding to the given name.
        Parameters:
        name - the name of the data source
        dataSource - the data source to add/replace
      • putDataSource

        public void putDataSource​(DataSourceProvider dataSourceProvider)
        Adds/replaces the data source corresponding to the given name.
        Parameters:
        dataSourceProvider - the data source to add/replace
      • getDataSources

        public Map<String,​DataSource> getDataSources()
        Returns the data sources used by this composite data source.

        Returns only the data sources that have been created.

        Returns:
        the registered data sources
      • getDataSourceProviders

        public Map<String,​DataSourceProvider> getDataSourceProviders()
        Returns the data source providers registered to this composite data source.

        Returns all registered data sources.

        Returns:
        the registered data source providers
      • startRead

        public void startRead​(ReadSubscription readRecipe)
        Description copied from class: DataSource
        Starts the given read subscription.
        Overrides:
        startRead in class DataSource
        Parameters:
        readRecipe - the subscription information
      • stopRead

        public void stopRead​(ReadSubscription readRecipe)
        Description copied from class: DataSource
        Stops the given read subscription.
        Overrides:
        stopRead in class DataSource
        Parameters:
        readRecipe - the subscription information
      • startWrite

        public void startWrite​(WriteSubscription writeRecipe)
        Description copied from class: DataSource
        Starts the given write subscription.
        Overrides:
        startWrite in class DataSource
        Parameters:
        writeRecipe - the subscription information
      • stopWrite

        public void stopWrite​(WriteSubscription writeRecipe)
        Description copied from class: DataSource
        Stops the given write subscription.
        Overrides:
        stopWrite in class DataSource
        Parameters:
        writeRecipe - the subscription information
      • createChannel

        protected ChannelHandler createChannel​(String channelName)
        Description copied from class: DataSource
        Creates a channel handler for the given name. In the simplest case, this is the only method a data source needs to implement.
        Specified by:
        createChannel in class DataSource
        Parameters:
        channelName - the name for a new channel
        Returns:
        a new handler
      • close

        public void close()
        Closes all DataSources that are registered in the composite.
        Overrides:
        close in class DataSource