public abstract class CommandReceiver extends ErrorServer
CommandReceiver.CommandHandler, takes over the client socket
and is responsible for the entire communication ('protocol'). This
helper thread is an extension to Handler.CommandReceiver.CommandHandler first establishes the streams to the
client (parent class
functionality) and reads in the command sent by the client.getAcknowledgeNumber(stella.CommandEvent) with the
just received command as an argument to get the number of acknowledges
that constitute the whole cycle. The default implementation returns
1 always, concrete subclasses should override this method.getCompletionTime(stella.CommandEvent, int).processCommand(stella.CommandEvent, int) of the main class.processCommand(stella.CommandEvent, int) method returns true to indicate
proper execution of the command (or of the actual subcommand in the case of
macro commands). In this case, the handler thread loops between
decrementing the acknowledge number, calling the getCompletionTime(stella.CommandEvent, int)
and sending back acknowledge events.processCommand(stella.CommandEvent, int), i.e. as the
counter decreases to zero, a successful done event is generated and
sent back.getLastError() method.processCommand(stella.CommandEvent, int) method, because this is the base class's link
to its concrete subclasses. These concrete subclasses in turn can rely on
the receivers sendStatus(stella.ErrorEvent) method to send back a status
message.ErrorReceiver.| Modifier and Type | Class and Description |
|---|---|
protected class |
CommandReceiver.CommandHandler
Handles the command protocol.
|
PropertyResources.Load, PropertyResources.URLResource| Modifier and Type | Field and Description |
|---|---|
private ThreadGroup |
commandgroup
The thread group commands run in.
|
private static long |
DEFAVAILABLE
The default sleep interval between available queries.
|
private static ThreadGroup |
DEFCOMMANDGROUP
The default thread group commands run in.
|
private static long |
DEFTIMEOUT
The default sleep interval between available queries.
|
static String |
KEY_AVAILABLE
The key for sleep intervalls on available queries.
|
static String |
KEY_COMMANDGROUP
The key in the properties for the alarm thread group.
|
static String |
KEY_TIMEOUT
The key for join-time on cancel.
|
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 CommandReceiver.CommandHandler |
receive
The command handler used for sending.
|
KEY_BIND, KEY_BINDNAMEDEFSERVERPORT, handlerGroup, KEY_BUFFERSIZE, KEY_HANDLERPRIORITY, KEY_HOSTADDRESS, KEY_LOGOUT, KEY_RECEIVERNAME, KEY_SERVERPORT, KEY_SERVERPRIORITYALTERNATEHOST, ALTERNATEPORT, 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_MAPSEPARATORKEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOMECONFIG, KEY_CLASS| Modifier | Constructor and Description |
|---|---|
protected |
CommandReceiver(Map qualify)
Constructs a new receiver with the specified properties.
|
| Modifier and Type | Method and Description |
|---|---|
void |
cancel()
Cancels the server.
|
protected int |
getAcknowledgeNumber(CommandEvent cmd)
Returns the type of the first acknowledge event as a function of the
command type.
|
protected abstract long |
getCompletionTime(CommandEvent cmd,
int acktype)
Returns the completion time for the specified command.
|
protected ErrorEvent |
getLastError()
Returns the error event describing the last error that occured.
|
protected abstract boolean |
processCommand(CommandEvent cmd,
int acktype)
Processes the given command.
|
protected void |
protocol(Socket client)
The method to handle the communication from the command-sending client
to this receiver.
|
void |
sendInfo(InfoEvent ie)
Sends an info message to the normal command socket.
|
void |
sendStatus(ErrorEvent ee)
Sends the status event back to registered listeners.
|
exit, init, processErrorgetAsociatedThread, getBufferSize, getHandlerPriority, getReceiverName, getServerPort, getServerPriority, initReceiverServer, maxTimeToCancel, runaddErrorListener, addRmiErrorListener, isValid, notifyErrorListener, removeErrorListener, removeRmiErrorListener, sendError, sendError, sendError, 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, unbindFromRegistrydefaultBoolean, 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_TIMEOUT
public static final String KEY_AVAILABLE
public static final String KEY_COMMANDGROUP
private static final long DEFTIMEOUT
private static final long DEFAVAILABLE
private static final ThreadGroup DEFCOMMANDGROUP
private final Object lockread
private final Object lockwrite
private CommandReceiver.CommandHandler receive
private final ThreadGroup commandgroup
protected CommandReceiver(Map qualify)
protected void protocol(Socket client)
CommandReceiver.CommandHandler thread that implements the
command-receiving protocol. The priority the handler thread should
run at is defined in the base class and is querried with the
ReceiverServer.getHandlerPriority() method.protocol in class ReceiverServerclient - The client socket.CommandReceiver,
ErrorReceiverprotected int getAcknowledgeNumber(CommandEvent cmd)
protected abstract long getCompletionTime(CommandEvent cmd, int acktype)
cmd - The command to process.acktype - The type of the acknowledge that will be sent back.protected abstract boolean processCommand(CommandEvent cmd, int acktype)
The method returns true if the (sub)task was executed without an error.
If it returns false the appropriate error event must be ready for
retrival using the getLastError() method.
protected ErrorEvent getLastError()
public void sendStatus(ErrorEvent ee)
processCommand(stella.CommandEvent, int) method.ErrorServer.processError(stella.ErrorEvent) method.sendStatus in class CastingContainerpublic void sendInfo(InfoEvent ie)
public void cancel()
cancel in interface CancelRunnablecancel in class ReceiverServer