ConnectionPayload
- type of the payload for the connectionMessagePayload
- type of the payload for each messagepublic abstract class MultiplexedChannelHandler<ConnectionPayload,MessagePayload> extends ChannelHandler
ChannelHandler
on top of a single subscription and
multiplexes all reads on top of it.Constructor and Description |
---|
MultiplexedChannelHandler(String channelName)
Creates a new channel handler.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addMonitor(ChannelHandlerReadSubscription subscription)
Used by the data source to add a read request on the channel managed
by this handler.
|
protected void |
addWriter(WriteCache<?> cache,
ExceptionHandler handler)
Used by the data source to prepare the channel managed by this handler
for write.
|
protected abstract void |
connect()
Used by the handler to open the connection.
|
protected abstract void |
disconnect()
Used by the handler to close the connection.
|
protected DataSourceTypeAdapter<ConnectionPayload,MessagePayload> |
findTypeAdapter(ValueCache<?> cache,
ConnectionPayload connection)
Finds the right adapter to use for the particular cache given the information
of the channels in the connection payload.
|
protected ConnectionPayload |
getConnectionPayload()
The last processes connection payload.
|
protected MessagePayload |
getLastMessagePayload()
The last processed message payload.
|
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.
|
boolean |
isConnected()
Returns true if it is connected.
|
protected boolean |
isConnected(ConnectionPayload payload)
Determines from the payload whether the channel is connected or not.
|
protected void |
processConnection(ConnectionPayload connectionPayload)
Process the next connection payload.
|
protected void |
processMessage(MessagePayload 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(WriteCache<?> cache,
ExceptionHandler exceptionHandler)
Used by the data source to conclude writes to the channel managed by this handler.
|
protected void |
reportExceptionToAllReadersAndWriters(Exception ex)
Notifies all readers and writers of an error condition.
|
protected abstract void |
write(Object newValue,
ChannelWriteCallback callback)
Implements a write operation.
|
getChannelName, getProperties
public MultiplexedChannelHandler(String channelName)
channelName
- the name of the channel this handler will be responsible ofprotected final void reportExceptionToAllReadersAndWriters(Exception ex)
ex
- the exception to notifyprotected final ConnectionPayload getConnectionPayload()
protected final MessagePayload getLastMessagePayload()
protected final void processConnection(ConnectionPayload connectionPayload)
connectionPayload
- protected DataSourceTypeAdapter<ConnectionPayload,MessagePayload> findTypeAdapter(ValueCache<?> cache, ConnectionPayload connection)
DataSourceTypeSupport
as
a good first implementation.cache
- the cache that will store the dataconnection
- the connection payloadpublic int getUsageCounter()
getUsageCounter
in class ChannelHandler
public int getReadUsageCounter()
getReadUsageCounter
in class ChannelHandler
public int getWriteUsageCounter()
getWriteUsageCounter
in class ChannelHandler
protected void addMonitor(ChannelHandlerReadSubscription subscription)
addMonitor
in class ChannelHandler
subscription
- the data required for a subscriptionprotected void removeMonitor(Collector<?> collector)
removeMonitor
in class ChannelHandler
collector
- the collector that does not need to be notified anymoreprotected void addWriter(WriteCache<?> cache, ExceptionHandler handler)
addWriter
in class ChannelHandler
handler
- to be notified in case of errorsprotected void removeWrite(WriteCache<?> cache, ExceptionHandler exceptionHandler)
removeWrite
in class ChannelHandler
exceptionHandler
- to be notified in case of errorsprotected final void processMessage(MessagePayload payload)
DataSourceTypeAdapter
for each read monitor that was setup.payload
- the payload of for this type of channelprotected abstract void connect()
protected abstract void disconnect()
protected abstract void write(Object newValue, ChannelWriteCallback callback)
write
in class ChannelHandler
newValue
- new value to be writtencallback
- called when done or on errorprotected boolean isConnected(ConnectionPayload payload)
By default, this uses the usage counter to determine whether it's connected or not. One should override this to use the actual connection payload to check whether the actual protocol connection has been established.
payload
- the connection payloadpublic final boolean isConnected()
isConnected
in class ChannelHandler
Copyright © 2012. All Rights Reserved.