org.epics.pvmanager
Class CompositeDataSource

java.lang.Object
  extended by org.epics.pvmanager.DataSource
      extended by org.epics.pvmanager.CompositeDataSource

public class CompositeDataSource
extends DataSource

A data source that can dispatch a request to multiple different data sources.

Author:
carcassi

Constructor Summary
CompositeDataSource()
          Creates a new CompositeDataSource.
 
Method Summary
 void close()
          Closes all DataSources that are registered in the composite.
 void concludeWrite(WriteBuffer writeBuffer, ExceptionHandler exceptionHandler)
          Releases the resources associated with the given write buffer.
 void connect(DataRecipe recipe)
          Connects to a set of channels based on the given recipe.
protected  ChannelHandler createChannel(java.lang.String channelName)
          Creates a channel handler for the given name.
 void disconnect(DataRecipe recipe)
          Disconnects the set of channels given by the recipe.
 java.util.Map<java.lang.String,ChannelHandler> getChannels()
          Returns the channel handlers for this data source.
 java.util.Map<java.lang.String,DataSource> getDataSources()
          Returns the data sources registered to this composite data source.
 java.lang.String getDefaultDataSource()
          Returns which data source is used if no data source is specified in the channel name.
 java.lang.String getDelimiter()
          Returns the delimeter that divides the data source name from the channel name.
 void prepareWrite(WriteBuffer writeBuffer, ExceptionHandler exceptionHandler)
          Prepares the channels defined in the write buffer for writes.
 void putDataSource(java.lang.String name, DataSource dataSource)
          Adds/replaces the data source corresponding to the given name.
 void setDefaultDataSource(java.lang.String defaultDataSource)
          Sets the data source to be used if the channel does not specify one explicitely.
 void setDelimiter(java.lang.String delimiter)
          Changes the data source delimiter.
 
Methods inherited from class org.epics.pvmanager.DataSource
isWriteable, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompositeDataSource

public CompositeDataSource()
Creates a new CompositeDataSource.

Method Detail

getDelimiter

public java.lang.String getDelimiter()
Returns the delimeter that divides the data source name from the channel name. Default is "://" so that "epics://pv1" corresponds to the "pv1" channel from the "epics" datasource.

Returns:
data source delimeter; can't be null

setDelimiter

public void setDelimiter(java.lang.String delimiter)
Changes the data source delimiter.

Parameters:
delimiter - new data source delimiter; can't be null

putDataSource

public void putDataSource(java.lang.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

getDefaultDataSource

public java.lang.String getDefaultDataSource()
Returns which data source is used if no data source is specified in the channel name.

Returns:
the default data source, or null if it was never set

getDataSources

public java.util.Map<java.lang.String,DataSource> getDataSources()
Returns the data sources registered to this composite data source.

Returns:
the registered data sources

setDefaultDataSource

public void setDefaultDataSource(java.lang.String defaultDataSource)
Sets the data source to be used if the channel does not specify one explicitely. The data source must have already been added.

Parameters:
defaultDataSource - the default data source

connect

public void connect(DataRecipe recipe)
Description copied from class: DataSource
Connects to a set of channels based on the given recipe.

The data source must update the value caches relative to each channel. Before updating any cache, it must lock the collector relative to that cache and after any update it must notify the collector.

Overrides:
connect in class DataSource
Parameters:
recipe - the instructions for the data connection

disconnect

public void disconnect(DataRecipe recipe)
Description copied from class: DataSource
Disconnects the set of channels given by the recipe.

The disconnect call is guaranteed to be given the same object, so that the recipe itself can be used as a key in a map to retrieve the list of resources needed to be closed.

Overrides:
disconnect in class DataSource
Parameters:
recipe - the instructions for the data connection

prepareWrite

public void prepareWrite(WriteBuffer writeBuffer,
                         ExceptionHandler exceptionHandler)
Description copied from class: DataSource
Prepares the channels defined in the write buffer for writes.

If these are channels over the network, it will create the network connections with the underlying libraries.

Overrides:
prepareWrite in class DataSource
Parameters:
writeBuffer - the buffer that will contain the write data
exceptionHandler - where to report the exceptions

concludeWrite

public void concludeWrite(WriteBuffer writeBuffer,
                          ExceptionHandler exceptionHandler)
Description copied from class: DataSource
Releases the resources associated with the given write buffer.

Will close network channels and deallocate memory needed.

Overrides:
concludeWrite in class DataSource
Parameters:
writeBuffer - the buffer that will no longer be used
exceptionHandler - where to report the exceptions

createChannel

protected ChannelHandler createChannel(java.lang.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

getChannels

public java.util.Map<java.lang.String,ChannelHandler> getChannels()
Description copied from class: DataSource
Returns the channel handlers for this data source.

Overrides:
getChannels in class DataSource
Returns:
an unmodifiable collection