public abstract class CasterClient extends AbstractCommandLauncher implements ReplyDeliverer, RmiCommandCaster, RmiAcknowledgeCaster, RmiDoneCaster, RmiErrorCaster, ErrorCaster, Initializable, ExitCleaning
This caster sends the specified command and receives the incoming
acknowledge and done replies in a seperated thread. On sending a command a
socket to the server is opened in the main thread, handed over to a handler
sub-thread which is responsible for closing the socket after the final
done event was received. Sending a command to
the castCommand(stella.CommandEvent) immediately-returning method spawns this handler
thread with the following capabilities:
Alarm is started to eventually
time-out the acknowledge receiving.AcknowledgeEvent is received in time another alarm is
started, its time-out depending on the completion time handed over with
the acknowledge event.ReplySubscriber relies on in talking to his client.
A ReplySubscriber can be associated with this caster
instance. All incoming replies (i.e. acknowledge and done
events are checked whether they should be forwarded to the reply subscriber.
The intended use for this is that some sort of a command sequencer is not
necessaryly interested in all acknowledge and done
events sent back to the caster, but only in some that allow the sequencer
optimal timing.
ReplySubscriber| Modifier and Type | Class and Description |
|---|---|
protected class |
CasterClient.CommandSender
The helper thread for this ascii caster to handle a
command/acknowledge/done
sequence.
|
PropertyResources.Load, PropertyResources.URLResource| Modifier and Type | Field and Description |
|---|---|
private List |
acknowledgeList
The registered acknowledge listeners.
|
private List |
activecommand
A list of active command send threads.
|
private ThreadGroup |
alarmGroup
The ThreadGroup the alarms should run in.
|
private int |
alarmNumber
The numbering for the alarms.
|
private Hashtable |
alarmTable
The table mapping commands to alarms.
|
private static long |
ATISENLARGE
Fuckin ATIS multiplier on time-outs.
|
private static int |
CAST
An internal counter for automatic naming of the main command caster.
|
private static ThreadGroup |
commandGroup
The thread group command senders run in.
|
private List |
commandList
The registered command listeners.
|
private Socket |
connect
The socket for this client.
|
private static long |
DEFACKNOWLEDGETIMEOUT
The default acknowledge time-out value, in ms (10000).
|
private static ThreadGroup |
DEFALARMGROUP
The default thread group the alarms run in.
|
private static boolean |
DEFBIND
The default binding of the done caster (false).
|
private static int |
DEFBUFFERSIZE
The default buffer size of the I/O streams (2048).
|
private static String |
DEFCASTERNAME
The default name (Caster).
|
private static long |
DEFMAXWAITONCLOSE
The default sleep intervall between server-up retries.
|
private static int |
DEFPORT
The default port number (1026).
|
private static int |
DEFRETRYCOUNT
The default number of retries if server is not ready.
|
private static long |
DEFRETRYSLEEP
The default sleep intervall between server-up retries.
|
private List |
doneList
The registered done listeners.
|
private ReplySubscriber |
forward
The registered reply subscriber.
|
private static long |
ID
A session ID.
|
private BufferedReader |
in
The input stream connected with the socket.
|
private boolean |
isBound
True if this caster is already bound.
|
private boolean |
isclosing
A boolean stating that the client is closing its connection.
|
static String |
KEY_ACKNOWLEDGETIMEOUT
The key in the properties for the acknowledge time out.
|
static String |
KEY_ALARMGROUP
The key in the properties for the alarm thread group.
|
static String |
KEY_BIND
The key in the properties for binding the command caster.
|
static String |
KEY_BUFFERSIZE
The key in the properties for the stream buffer size.
|
static String |
KEY_CASTERNAME
The key in the properties defining the unique name of this caster.
|
static String |
KEY_MAXWAITONCLOSE
The maximum wait on close operation.
|
static String |
KEY_PORT
The key for the socket port.
|
static String |
KEY_RECEIVER
The key in the properties for the command server.
|
static String |
KEY_RETRYCOUNT
The key for the maximum retry number if server is down.
|
static String |
KEY_RETRYSLEEP
The key for the maximum retry number if server is down.
|
private CommandEvent |
lastCommand
The last command sent.
|
private Object |
lockread
A locking object to prevent simultaneous read access to socket.
|
private Object |
lockwrite
A locking object to prevent simultaneous write access to socket.
|
private BufferedWriter |
out
The output stream connected with the socket.
|
private List |
pattern
The replies the reply subscriber is interested in.
|
private Hashtable |
setOffAlarms
The table mapping alarms that have been set off to commands.
|
ALTERNATEHOST, ALTERNATEPORT, KEY_BINDNAME, KEY_EXPORTPORT, KEY_REGISTRYHOST, KEY_REGISTRYPORTKEY_NOINITONCREATE, POSTFIX_ALPHABET, POSTFIX_BYTES, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_MODTIME, POSTFIX_URLKEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATORNAMING_EXTENSIONNAMING_EXTENSIONNAMING_EXTENSIONCONFIG, KEY_CLASSKEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME| Modifier | Constructor and Description |
|---|---|
protected |
CasterClient(Map qualify)
Constructs a new caster with the specified properties.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addRmiAcknowledgeListener(RmiAcknowledgeListener ear)
Registers an acknowledge event listener to this caster.
|
void |
addRmiCommandListener(RmiCommandListener ear)
Registers a command event listener to this caster.
|
void |
addRmiDoneListener(RmiDoneListener ear)
Registers a done event listener to this caster.
|
void |
announceInterest(ReplyEvent re)
Adds a new reply event pattern to the pattern list.
|
void |
castCommand(CommandEvent ce)
The public method called to cast a command to the specified receiver.
|
protected void |
checkForward(ReplyEvent re)
Checks if the received reply message should be forwarded to the
registered reply subscriber.
|
protected void |
close()
Closes the socket and the associated streams.
|
void |
exit()
Performs an orderly exit for a threatening shutdown.
|
long |
getAcknowledgeTimeOut()
Returns the acknowledge time out, in ms.
|
ThreadGroup |
getAlarmGroup()
Returns the thread group the done and acknowledge time-out alarms should
run in.
|
int |
getBufferSize()
Returns the buffer size used for buffering the socket streams.
|
String |
getClientName()
Returns the name used for this caster.
|
CommandEvent |
getExitCommand()
Default implementation of exit command is null.
|
int |
getPort()
Returns the port number the caster should connect to on the receiver.
|
String |
getReceiver()
Returns the name of the receiver of commands from this caster.
|
boolean |
handles(CommandEvent ce)
A caster client can only handle
CloseSocket commands, as this
command should be understood by any caster client dealing with
sockets. |
void |
init()
Initializes this caster's acknowledge and done casting binidings.
|
boolean |
isReady()
Should always return true if socket connection is open.
|
private int |
nextAlarmNumber()
Returns the next available number for the alarm numbering.
|
private static int |
nextCast()
Gets the next available number at automatic naming of the caster.
|
private static long |
nextID()
Returns the next session ID.
|
protected void |
notifyAcknowledgeListener(AcknowledgeEvent ae)
Notifies all registered
RmiAcknowledgeListeners. |
protected void |
notifyCommandListener(CommandEvent ce)
Notifies all registered
RmiCommandListeners. |
protected void |
notifyDoneListener(DoneEvent de)
Notifies all registered
RmiDoneListeners. |
private void |
openSocket()
Actually opens the socket and the associated streams.
|
void |
recastCommand()
Recasts the last command.
|
void |
registerReplySubscriber(ReplySubscriber fwd)
Registers the reply subscriber.
|
void |
removeRmiAcknowledgeListener(RmiAcknowledgeListener ear)
Deregisters an acknowledge event listener from this caster.
|
void |
removeRmiCommandListener(RmiCommandListener ear)
Deregisters a command event listener from this caster.
|
void |
removeRmiDoneListener(RmiDoneListener ear)
Deregisters a done event listener to this caster.
|
createCommandLauncheraddErrorListener, addRmiErrorListener, isValid, notifyErrorListener, removeErrorListener, removeRmiErrorListener, sendError, sendError, sendError, sendStatus, sendStatus, sendStatusbindToRegistry, bindToRegistry, bindToRegistry, bindToRegistry, bindToRegistry, bindToRegistry, casterExit, casterExit, getBindName, getBindName, unbindFromRegistry, unbindFromRegistrycontainsRemoteProperty, getRemoteProperties, getRemoteProperty, setRemotePropertyclone, createFrom, createFrom, createFrom, createInstance, getApplet, getAsResources, getLocate, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, hasLocalURLs, initProperties, keyCreate, keyCreate, reload, setAppletaugment, augment, augment, augment, augment, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, isNew, parseObject, parseObject, reload, removeProperty, requires, rescanned, setObject, setProperties, setProperty, stringProperties, toStringequals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitaddRmiErrorListener, removeRmiErrorListenerbindToRegistry, isValid, unbindFromRegistryaddErrorListener, removeErrorListenergetShutdownCommanddefaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, parseObject, removeProperty, setObject, setProperty, stringPropertiespublic static final String KEY_CASTERNAME
public static final String KEY_RECEIVER
public static final String KEY_PORT
public static final String KEY_BIND
public static final String KEY_ACKNOWLEDGETIMEOUT
public static final String KEY_RETRYCOUNT
public static final String KEY_RETRYSLEEP
public static final String KEY_BUFFERSIZE
public static final String KEY_ALARMGROUP
public static final String KEY_MAXWAITONCLOSE
private static final String DEFCASTERNAME
private static final int DEFPORT
private static final boolean DEFBIND
private static final long DEFACKNOWLEDGETIMEOUT
private static final int DEFBUFFERSIZE
private static final int DEFRETRYCOUNT
private static final long DEFRETRYSLEEP
private static final long DEFMAXWAITONCLOSE
private static final ThreadGroup DEFALARMGROUP
private static final long ATISENLARGE
private boolean isBound
private List commandList
private List acknowledgeList
private List doneList
private ReplySubscriber forward
private List pattern
private Socket connect
private BufferedWriter out
private BufferedReader in
private Object lockread
private Object lockwrite
private CommandEvent lastCommand
private List activecommand
private ThreadGroup alarmGroup
private Hashtable alarmTable
private Hashtable setOffAlarms
private int alarmNumber
private boolean isclosing
private static int CAST
private static long ID
private static final ThreadGroup commandGroup
protected CasterClient(Map qualify)
KEY_CASTERNAME, the connection socket port KEY_PORT,
the bind properties as an rmi caster
KEY_BIND, the acknowledge
time-out (see
KEY_ACKNOWLEDGETIMEOUT), the thread group the alarms should
run in KEY_ALARMGROUP and the stream buffer size
KEY_BUFFERSIZE is always set. Additionally the receiver is set
to none if not present in the properties. Note that the
default receiver does not map to an allowed receiver!qualify - The properties of this casterprivate static int nextCast()
private static long nextID()
private int nextAlarmNumber()
public void init()
AbstractRmiCaster.bindToRegistry()
method regardless of the value of
the binding key KEY_BIND.init in interface Initializableinit in class CastingContainerKEY_RETRYCOUNT,
KEY_RETRYSLEEPpublic CommandEvent getExitCommand()
getExitCommand in interface CommandLaunchingprivate void openSocket()
KEY_RETRYCOUNT,
KEY_RETRYSLEEPpublic String getClientName()
getClientName in interface CommandLaunchingpublic String getReceiver()
public int getPort()
public long getAcknowledgeTimeOut()
public int getBufferSize()
public ThreadGroup getAlarmGroup()
public void registerReplySubscriber(ReplySubscriber fwd)
registerReplySubscriber in interface ReplyDelivererforward - The reply subscriber interested in received replies.public boolean isReady()
isReady in interface CommandLaunchingprotected void checkForward(ReplyEvent re)
ReplyEvent.matches(stella.ReplyEvent) all stored reply patterns are used as
arguments to the reply event under question.If the argument is matched to one of the patterns the argument is immediately passed to the registered reply subscriber and the pattern is removed from the list.
Note that this method synchronizes on the pattern vector.
public void announceInterest(ReplyEvent re)
castCommand(stella.CommandEvent)). Otherwise timing fluctuation may cause
problems.announceInterest in interface ReplyDelivererpublic void addRmiCommandListener(RmiCommandListener ear) throws RemoteException
addRmiCommandListener in interface RmiCommandCasterear - The command listener to register.RemoteExceptionpublic void removeRmiCommandListener(RmiCommandListener ear) throws RemoteException
removeRmiCommandListener in interface RmiCommandCasterear - The command listener to deregister.RemoteExceptionprotected void notifyCommandListener(CommandEvent ce)
RmiCommandListeners. This method parses
through the Vector of CommandListeners and passes the argument to
their RmiCommandListener.rmiCommand(stella.CommandEvent) method. Registered
listeners are RMI based.ce - The CommandEvent to pass to the listeners.public void addRmiAcknowledgeListener(RmiAcknowledgeListener ear) throws RemoteException
addRmiAcknowledgeListener in interface RmiAcknowledgeCasterear - The acknowledge listener to register.RemoteExceptionpublic void removeRmiAcknowledgeListener(RmiAcknowledgeListener ear) throws RemoteException
removeRmiAcknowledgeListener in interface RmiAcknowledgeCasterear - The acknowledge listener to deregister.RemoteExceptionprotected void notifyAcknowledgeListener(AcknowledgeEvent ae)
RmiAcknowledgeListeners. This method
parses
through the Vector of AcknowledgeListeners and passes the argument to
their RmiAcknowledgeListener.rmiGotAcknowledge(stella.AcknowledgeEvent) method.
Registered
listeners are RMI based.ae - The AcknowledgeEvent to pass to the Listeners.public void addRmiDoneListener(RmiDoneListener ear) throws RemoteException
addRmiDoneListener in interface RmiDoneCasterear - The done listener to register.RemoteExceptionpublic void removeRmiDoneListener(RmiDoneListener ear) throws RemoteException
removeRmiDoneListener in interface RmiDoneCasterear - The done listener to deregister.RemoteExceptionprotected void notifyDoneListener(DoneEvent de)
RmiDoneListeners. This method parses
through the Vector of DoneListeners and passes the argument to
their RmiDoneListener.rmiGotDone(stella.DoneEvent) method. Registered
listeners are RMI based.de - The DoneEvent to pass to the listeners.public boolean handles(CommandEvent ce)
CloseSocket commands, as this
command should be understood by any caster client dealing with
sockets. Note that subclasses should override this method.handles in interface CommandLaunchingpublic void castCommand(CommandEvent ce)
CasterClient.CommandSender.
If this method is called while an other command handler is still running the new command is simply cast to the listener. Please note that the command server must be capable of handling multiple connections simultaniously. Additionally, any command cast to the server must be terminated with a done sent back to this caster (i.e. the helper thread) otherwise lockup will occur!
castCommand in interface CommandLaunchingpublic void recastCommand()
Because recasting of a command is only useful if the command has not been completely received at the receiver, only a first acknowledge may be in the waiting queue.
recastCommand in interface CommandLaunchingpublic void exit()
ExitCleaning recommondation.exit in interface ExitCleaningexit in class CastingContainerprotected void close()