public abstract class DataSource extends Object
To implement a datasource, one has to implement the createChannel(java.lang.String)
method, and the requested 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.
Constructor and Description |
---|
DataSource(boolean writeable)
Creates a new data source.
|
Modifier and Type | Method and Description |
---|---|
protected String |
channelHandlerLookupName(String channelName)
Returns the lookup name to use to find the channel handler in
the cache.
|
protected String |
channelHandlerRegisterName(String channelName,
ChannelHandler handler)
Returns the name the given handler should be registered as.
|
void |
close()
Closes the DataSource and the resources associated with it.
|
void |
connectRead(ReadRecipe readRecipe)
Connects to a set of channels based on the given recipe.
|
void |
connectWrite(WriteRecipe writeRecipe)
Prepares the channels defined in the write recipe for writes.
|
protected abstract ChannelHandler |
createChannel(String channelName)
Creates a channel handler for the given name.
|
void |
disconnectRead(ReadRecipe readRecipe)
Disconnects the set of channels given by the recipe.
|
void |
disconnectWrite(WriteRecipe writeRecipe)
Releases the resources associated with the given write recipe.
|
Map<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 |
write(WriteRecipe writeRecipe,
Runnable callback,
ExceptionHandler exceptionHandler)
Writes the contents in the given write recipe to the channels
of this data sources.
|
public DataSource(boolean writeable)
writeable
- whether the data source implements write operationspublic boolean isWriteable()
protected String channelHandlerLookupName(String channelName)
channelName
- the channel nameprotected String channelHandlerRegisterName(String channelName, ChannelHandler handler)
channelName
- the name under which the ChannelHandler was createdhandler
- the handler to registerprotected abstract ChannelHandler createChannel(String channelName)
channelName
- the name for a new channelpublic void connectRead(ReadRecipe readRecipe)
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.
readRecipe
- the instructions for the data connectionpublic void disconnectRead(ReadRecipe readRecipe)
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.
readRecipe
- the instructions for the data connectionpublic void connectWrite(WriteRecipe writeRecipe)
If these are channels over the network, it will create the network connections with the underlying libraries.
writeRecipe
- the recipe that will contain the write datapublic void disconnectWrite(WriteRecipe writeRecipe)
Will close network channels and deallocate memory needed.
writeRecipe
- the recipe that will no longer be usedpublic void write(WriteRecipe writeRecipe, Runnable callback, ExceptionHandler exceptionHandler)
The write recipe needs to be first prepared with connectWrite(org.epics.pvmanager.WriteRecipe)
and then cleaned up with disconnectWrite(org.epics.pvmanager.WriteRecipe)
.
writeRecipe
- the recipe containing the data to writecallback
- function to call when the write is concludedexceptionHandler
- where to report the exceptionspublic Map<String,ChannelHandler> getChannels()
public void close()
Copyright © 2010–2015. All rights reserved.