stella.net
Class CasterClient.CommandSender

java.lang.Object
  extended by java.lang.Thread
      extended by stella.net.CasterClient.CommandSender
All Implemented Interfaces:
Runnable, AlarmHandler
Enclosing class:
CasterClient

protected class CasterClient.CommandSender
extends Thread
implements AlarmHandler

The helper thread for this ascii caster to handle a command/acknowledge/done sequence. This thread is started after the connection to the command receiver (server) has been established. To allow the main thread to return-fast from its CasterClient.castCommand(stella.CommandEvent) method this helper thread does the whole handling of writing the command to the socket as an ASCII-String, waiting for the acknowledge and done replies and call time-out handlers if necessary.

Please not that any command sent to the server must be terminated with a final done regardless of errors occuring or further commands sent during the processing of the actual command!

To avoid time-consuming construction of lookup-tables for each command sent this class uses static lookup-tables that are constructed only once.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
private  boolean cancel
          Gets true if this thread should terminate unexpectedly.
private  CommandEvent command
          The command to send to the server.
private static String COMPLETE
          The name for alarms waiting for done or additional acknowledges.
private static String FIRSTACKNOWLEDGE
          The name for alarms waiting for the first acknowledge.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
protected CasterClient.CommandSender(ThreadGroup group, CommandEvent cmd)
          Constructs a new command sender.
 
Method Summary
 void cancel()
          Cancels the current cycle.
 void run()
          The main method of the command sender.
 void setOff(String alarm)
          The method called by the internal alarms of this caster if a problem with in-time replies occured.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, 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
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

command

private CommandEvent command
The command to send to the server.


cancel

private boolean cancel
Gets true if this thread should terminate unexpectedly.


FIRSTACKNOWLEDGE

private static final String FIRSTACKNOWLEDGE
The name for alarms waiting for the first acknowledge.

See Also:
Constant Field Values

COMPLETE

private static final String COMPLETE
The name for alarms waiting for done or additional acknowledges.

See Also:
Constant Field Values
Constructor Detail

CasterClient.CommandSender

protected CasterClient.CommandSender(ThreadGroup group,
                                     CommandEvent cmd)
Constructs a new command sender. The command and the thread group the sender should run in are given as arguments. The socket connection handed over is already opened by the calling class, but is automatically closed after the command-specific done has been received.

This thread is not started automatically.
Note that construction may be blocked if the server is not accepting connetions, see CasterClient.KEY_RETRYCOUNT and CasterClient.KEY_RETRYSLEEP.

Method Detail

cancel

public void cancel()
Cancels the current cycle. Note that all alarms are left unhandled.


run

public void run()
The main method of the command sender. If no error occurs this method does the following: Note that from the chain of command it is never possible that there is already an alarm mapped to the command's key. If this situation occurs nevertheless this is a software bug and is reported by casting a software error.

Specified by:
run in interface Runnable
Overrides:
run in class Thread

setOff

public void setOff(String alarm)
The method called by the internal alarms of this caster if a problem with in-time replies occured. The name of the alarm is used to either generate a acknowledge time-out error or a completion time-out error. An acknowledge time-out means that the listener did not sent back the acknowledge following the command. This error probably suggests some connection problem since no other action than simply replying to the command is involved. Completion time-outs may indicate that there is a problem with the hardware involved in completing the required task.
Note that acknowledge events sent after the verry first produce completion time-outs rather than acknowledge time-outs.

Specified by:
setOff in interface AlarmHandler