org.epics.pvmanager
Class ChannelHandler<EType>

java.lang.Object
  extended by org.epics.pvmanager.ChannelHandler<EType>
Type Parameters:
EType - type of the connection payload
Direct Known Subclasses:
JCAChannelHandler

public abstract class ChannelHandler<EType>
extends Object

Manages the connection for each channel of a data source.

Author:
carcassi

Constructor Summary
ChannelHandler(String channelName)
          Creates a new channel handler.
 
Method Summary
protected  void addMonitor(Collector<?> collector, ValueCache<?> cache, ExceptionHandler handler)
          Used by the data source to add a read request on the channel managed by this handler.
protected  void addWriter(ExceptionHandler handler)
          Used by the data source to prepare the channel managed by this handler for write.
protected abstract  void connect(ExceptionHandler handler)
          Used by the handler to open the connection.
protected abstract  void disconnect(ExceptionHandler handler)
          Used by the handler to close the connection.
 String getChannelName()
          Returns the name of the channel.
 int getReadUsageCounter()
          Returns how many read PVs are open on this channel.
 int getUsageCounter()
          Returns how many read or write PVs are open on this channel.
 int getWriteUsageCounter()
          Returns how many write PVs are open on this channel.
abstract  boolean isConnected()
          Returns true if it is connected.
protected  void processValue(EType payload)
          Process the payload for this channel.
protected  void removeMonitor(Collector<?> collector)
          Used by the data source to remove a read request.
protected  void removeWrite(ExceptionHandler exceptionHandler)
          Used by the data source to conclude writes to the channel managed by this handler.
protected abstract  boolean updateCache(EType event, ValueCache<?> cache)
          Used by the handler to forward values.
protected abstract  void write(Object newValue, ChannelWriteCallback callback)
          Implements a write operation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChannelHandler

public ChannelHandler(String channelName)
Creates a new channel handler.

Parameters:
channelName - the name of the channel this handler will be responsible of
Method Detail

getChannelName

public String getChannelName()
Returns the name of the channel.

Returns:
the channel name; can't be null

getUsageCounter

public int getUsageCounter()
Returns how many read or write PVs are open on this channel.

Returns:
the number of open read/writes

getReadUsageCounter

public int getReadUsageCounter()
Returns how many read PVs are open on this channel.

Returns:
the number of open reads

getWriteUsageCounter

public int getWriteUsageCounter()
Returns how many write PVs are open on this channel.

Returns:
the number of open writes

addMonitor

protected void addMonitor(Collector<?> collector,
                          ValueCache<?> cache,
                          ExceptionHandler handler)
Used by the data source to add a read request on the channel managed by this handler.

Parameters:
collector - collector to be notified at each update
cache - cache to contain the new value
handler - to be notified in case of errors

removeMonitor

protected void removeMonitor(Collector<?> collector)
Used by the data source to remove a read request.

Parameters:
collector - the collector that does not need to be notified anymore

addWriter

protected void addWriter(ExceptionHandler handler)
Used by the data source to prepare the channel managed by this handler for write.

Parameters:
handler - to be notified in case of errors

removeWrite

protected void removeWrite(ExceptionHandler exceptionHandler)
Used by the data source to conclude writes to the channel managed by this handler.

Parameters:
exceptionHandler - to be notified in case of errors

processValue

protected final void processValue(EType payload)
Process the payload for this channel. This should be called whenever a new value needs to be processed. The handler will take care of calling updateCache(java.lang.Object, org.epics.pvmanager.ValueCache) for each read monitor that was setup.

Parameters:
payload - the payload of for this type of channel

connect

protected abstract void connect(ExceptionHandler handler)
Used by the handler to open the connection. This is called whenever the first read or write request is made.

Parameters:
handler - to be notified in case of errors

disconnect

protected abstract void disconnect(ExceptionHandler handler)
Used by the handler to close the connection. This is called whenever the last reader or writer is de-registered.

Parameters:
handler - to be notified in case of errors

write

protected abstract void write(Object newValue,
                              ChannelWriteCallback callback)
Implements a write operation. Write the newValues to the channel and call the callback when done.

Parameters:
newValue - new value to be written
callback - called when done or on error

updateCache

protected abstract boolean updateCache(EType event,
                                       ValueCache<?> cache)
Used by the handler to forward values. Extracts the value form the payload and stores it in the cache.

Parameters:
event - the payload
cache - the cache where to store the new value
Returns:
true if a new value was stored

isConnected

public abstract boolean isConnected()
Returns true if it is connected.

Returns:
true if underlying channel is connected


Copyright © 2011. All Rights Reserved.