client
Class Client.CascadeInputOutputHandler

java.lang.Object
  extended by java.lang.Thread
      extended by client.Client.CascadeInputOutputHandler
All Implemented Interfaces:
java.lang.Runnable
Enclosing class:
Client

private final class Client.CascadeInputOutputHandler
extends java.lang.Thread

Internal class used to communicate with the mix cascade. Makes sure messages are sent synchronously (request and reply alternately). Otherwise the cascade would drop this client. Synchronized with Client via sendBuffer and receiveBuffer .

Author:
Karl-Peter Fuchs

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
private  boolean lastMessageWasDummy
          Indicates if the last message, that was received from the cascade, was a dummy.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
private Client.CascadeInputOutputHandler()
          Constructs a new CascadeInputOutputHandler and calls start().
 
Method Summary
private  void closeConnection()
          Releases connection to mix cascade.
private  void receiveReply()
          Receives a message (Reply) from the mix cascade and saves its payload in the receiveBuffer, from where it's available for the user's InputStream.
 void run()
          Communicates with the mix cascade.
private  void sendMixMessage()
          Sends a message to the mix cascade.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

lastMessageWasDummy

private boolean lastMessageWasDummy
Indicates if the last message, that was received from the cascade, was a dummy. Used as indicator when "no further data can be expected from the corresponding communication partner".

See Also:
receiveReply()
Constructor Detail

Client.CascadeInputOutputHandler

private Client.CascadeInputOutputHandler()
Constructs a new CascadeInputOutputHandler and calls start().

Method Detail

run

public void run()
Communicates with the mix cascade. Makes sure messages are sent synchronously (request and reply alternately). Otherwise the cascade would drop this client. Synchronized with Client via sendBuffer and receiveBuffer.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

sendMixMessage

private void sendMixMessage()
Sends a message to the mix cascade. The message can be of one of the following types (depending on connection status (disconnected or connected) and the amount of data available in sendBuffer ): ChannelEstablishMessage, ChannelMessage , ChannelReleaseMessage or DummyMessage (= ChannelMessage without payload (=only padding)). Blocks until message is sent.


receiveReply

private void receiveReply()
Receives a message (Reply) from the mix cascade and saves its payload in the receiveBuffer, from where it's available for the user's InputStream. Blocks until message is received and written to buffer.


closeConnection

private void closeConnection()
Releases connection to mix cascade.