class Protocol
extends java.lang.Object
Protocol
is responsible for
notifying queue about I/O errors.
The reading and writing loops implement the proper callbacks for the
StateSynchronizer
implementation of bidirectional state
synchronization. This processing can be activated using the
registerSynchronizer
method.
WARNING: the core loops of the reader and writer threads are controlled by a variable which they read outside of a synchronized block. This means that it is possible (depending on the JVM implementation) to get inconsistent or corrupt results because it may be read in the middle of being changed. At this time, we are not introducing a lock object since this would cause potential contention to occur between the reader and writer threads. This is something that needs to be tested to ensure its impact is understood but it DOES need to be fixed.
Modifier and Type | Class and Description |
---|---|
private class |
Protocol.Reader
This helper class implements functionality of Reader thread.
|
private class |
Protocol.Writer
This helper class implements functionality of Writer thread.
|
Modifier and Type | Field and Description |
---|---|
private static java.util.logging.Logger |
LOG
Logger.
|
private static java.lang.ThreadGroup |
protoThreads
Thread group for the protocol threads.
|
private Queue |
queue
The queue representing the session with which protocol is working.
|
private java.lang.Thread |
readerThread
Reader thread.
|
private boolean |
running
Flag indicating status for Reader/Writer threads.
|
private java.lang.Object |
slock
Synchronizes access to the state synchronizer.
|
private StateSynchronizer |
ssync
The object used to implement state synchronization if enabled.
|
private java.lang.Object |
tlock
Synchronizes termination processing.
|
private java.lang.Thread |
writerThread
Writer thread.
|
Constructor and Description |
---|
Protocol(Queue queue)
Constructs an instance using the provided queue.
|
Modifier and Type | Method and Description |
---|---|
(package private) Message |
applyChanges(Message inbound)
If there is a registered state synchronizer and if there are any
attached state updates sent from the other side of the connection,
these updates are passed to the state synchronizer to be applied to
this node's state.
|
(package private) Message |
attachChanges(Message outbound)
Checks if there is a registered state synchronizer and if so, it is
queried to obtain the latest changes in state that must be sent to the
other side of the connection.
|
boolean |
isRunning()
Returns the operational state of this protocol driver.
|
(package private) void |
registerSynchronizer(StateSynchronizer ssync)
Sets the instance of the state synchronizer the reader and writer
threads should use, if and only if there is no other state synchronizer
already in use.
|
(package private) void |
setNames()
Force the reader and writer threads to have more descriptive names
to aid debugging.
|
(package private) void |
start()
Starts Reader and Writer threads as daemon threads.
|
(package private) void |
stop()
Stops Reader and Writer threads.
|
private void |
stopQueue(java.lang.Exception result)
Stop the queue with SilentUnwindException checking.
|
private static final java.util.logging.Logger LOG
private static java.lang.ThreadGroup protoThreads
private volatile boolean running
private Queue queue
private java.lang.Thread readerThread
private java.lang.Thread writerThread
private java.lang.Object slock
private StateSynchronizer ssync
private java.lang.Object tlock
Protocol(Queue queue)
queue
- Instance of the Queue
to/from which messages
are written/read.void start()
void stop()
void setNames()
public boolean isRunning()
true
if the protocol is running (operational)
and false
if the session is closed.void registerSynchronizer(StateSynchronizer ssync)
ssync
- The synchronizer to register or null
if the
currently registered synchronizer should be deregistered.Message attachChanges(Message outbound)
outbound
- The message that was dequeued for transmission.Message applyChanges(Message inbound)
inbound
- The message that is about to be enqueued for processing.private void stopQueue(java.lang.Exception result)
result
- The managed exception.