org.epics.pvmanager
Class DataSource

java.lang.Object
  extended by org.epics.pvmanager.DataSource
Direct Known Subclasses:
CompositeDataSource, JCADataSource, LocalDataSource, SimulationDataSource

public abstract class DataSource
extends java.lang.Object

A source for data that is going to be processed by the PVManager. PVManager can work with more than one source at a time. Support for each different source can be added by external libraries.

Author:
carcassi

Constructor Summary
DataSource(boolean writeable)
          Creates a new data source.
 
Method Summary
 void close()
          Closes the DataSource and the resources associated with it.
 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 abstract  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.
 boolean isWriteable()
          Returns true whether the channels of this data source can be written to.
 void prepareWrite(WriteBuffer writeBuffer, ExceptionHandler exceptionHandler)
          Prepares the channels defined in the write buffer for writes.
 void write(WriteBuffer writeBuffer, java.lang.Runnable callback, ExceptionHandler exceptionHandler)
          Writes the contents in the given write buffers to the channels of this data sources.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataSource

public DataSource(boolean writeable)
Creates a new data source.

Parameters:
writeable - whether the data source implements write operations
Method Detail

isWriteable

public boolean isWriteable()
Returns true whether the channels of this data source can be written to.

Returns:
true if data source accept write operations

createChannel

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

connect

public void connect(DataRecipe recipe)
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.

Parameters:
recipe - the instructions for the data connection

disconnect

public void disconnect(DataRecipe recipe)
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.

Parameters:
recipe - the instructions for the data connection

prepareWrite

public void prepareWrite(WriteBuffer writeBuffer,
                         ExceptionHandler exceptionHandler)
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.

Parameters:
writeBuffer - the buffer that will contain the write data
exceptionHandler - where to report the exceptions

concludeWrite

public void concludeWrite(WriteBuffer writeBuffer,
                          ExceptionHandler exceptionHandler)
Releases the resources associated with the given write buffer.

Will close network channels and deallocate memory needed.

Parameters:
writeBuffer - the buffer that will no longer be used
exceptionHandler - where to report the exceptions

write

public void write(WriteBuffer writeBuffer,
                  java.lang.Runnable callback,
                  ExceptionHandler exceptionHandler)
Writes the contents in the given write buffers to the channels of this data sources.

The write buffer need to be first prepared with prepareWrite(org.epics.pvmanager.WriteBuffer, org.epics.pvmanager.ExceptionHandler) and then cleaned up with concludeWrite(org.epics.pvmanager.WriteBuffer, org.epics.pvmanager.ExceptionHandler).

Parameters:
writeBuffer - the buffer containing the data to write
callback - function to call when the write is concluded
exceptionHandler - where to report the exceptions

getChannels

public java.util.Map<java.lang.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.