public abstract class ReceiverServer extends CastingContainer implements CancelRunnable, ErrorProcessing, Initializable, ExitCleaning
protocol(java.net.Socket) is called with the client socket as an
argument which is an abstract method in the base implementation.
Concrete subclasses should
provide their implementations of the protocol, like CommandReceiver
or ErrorReceiver. The details of this class's functionality can be described as follows.
Handler, takes over the
client socket
and is responsible for the entire communication ('protocol').Handler first establishes the streams to the
client and reads in the command sent by the client.Handler.close() method that closes the streams
and the socket. init() method),
a Thread is initialized with is directly linked with this receiver server.
It can be querried with getAsociatedThread(). If full
thread behaviour is intended, some parts of the codes have to be updated.
The run method loops forever unless cancel is called.PropertyResources.Load, PropertyResources.URLResource| Modifier and Type | Field and Description |
|---|---|
private boolean |
cancel
Gets true if this thread should exit.
|
private static int |
COUNT
An internal counter for automatic naming.
|
private static int |
DEFBUFFERSIZE
The default buffer size of the I/O streams (2048).
|
private static int |
DEFHANDLERPRIORITY
The default handler thread priority (Thread.NORM_PRIORITY).
|
private static long |
DEFLOGOUT
The default log-out time granted to clients.
|
private static String |
DEFRECEIVERNAME
The default receiver (Receiver-).
|
static int |
DEFSERVERPORT
The default port number (1026).
|
private static int |
DEFSERVERPRIORITY
The default server thread priority (1).
|
protected ThreadGroup |
handlerGroup
The thread group handlers run in.
|
static String |
KEY_BUFFERSIZE
The key in the properties for the stream buffer size.
|
static String |
KEY_HANDLERPRIORITY
The key in the properties defining the priority of the server.
|
static String |
KEY_HOSTADDRESS
The key to the host running the server.
|
static String |
KEY_LOGOUT
The key for the log-out time granted to the clients.
|
static String |
KEY_RECEIVERNAME
The key in the properties defining the name of this receiver.
|
static String |
KEY_SERVERPORT
The key for the socket port to listen to.
|
static String |
KEY_SERVERPRIORITY
The key in the properties defining the priority of the server.
|
private ServerSocket |
listen
The server socket the server listens to.
|
private Thread |
thisThread
A reference to the thread constructed from this Runnable.
|
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_MAPSEPARATORKEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOMECONFIG, KEY_CLASS| Modifier | Constructor and Description |
|---|---|
protected |
ReceiverServer(Map qualify)
Constructs a new receiver with the specified properties.
|
| Modifier and Type | Method and Description |
|---|---|
void |
cancel()
Cancels the server thread.
|
void |
exit()
Closes the receiver socket.
|
Thread |
getAsociatedThread()
Returns the thread asociated with this server.
|
int |
getBufferSize()
Returns the buffer size used for buffering the socket streams.
|
int |
getHandlerPriority()
Returns the priority at which the connection handler thread should run.
|
String |
getReceiverName()
Returns the name used for binding this receiver.
|
int |
getServerPort()
Returns the port number the clients should connect to on this receiver.
|
int |
getServerPriority()
Returns the priority at which this thread (the server) should run.
|
void |
init()
Initializes the receiver server.
|
protected void |
initReceiverServer()
An escape pod for subclasses.
|
long |
maxTimeToCancel()
Returns the maximum time-out for this thread.
|
private static int |
nextCount()
Gets the next available number at automatic naming.
|
void |
processError(ErrorEvent ee)
An escape pod for subclasses that want to do anything special with
errors or exceptions thrown during the lifecycle of this thread.
|
protected abstract void |
protocol(Socket client)
The method called as soon as a connection is established.
|
void |
run()
The run method of the receiver server.
|
addErrorListener, 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, waitdefaultBoolean, 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_RECEIVERNAME
public static final String KEY_HOSTADDRESS
public static final String KEY_SERVERPORT
public static final String KEY_BUFFERSIZE
public static final String KEY_SERVERPRIORITY
public static final String KEY_HANDLERPRIORITY
public static final String KEY_LOGOUT
private static final String DEFRECEIVERNAME
public static final int DEFSERVERPORT
private static final int DEFBUFFERSIZE
private static final int DEFSERVERPRIORITY
private static final int DEFHANDLERPRIORITY
private static final long DEFLOGOUT
private Thread thisThread
private ServerSocket listen
private boolean cancel
protected final ThreadGroup handlerGroup
private static int COUNT
protected ReceiverServer(Map qualify)
private static int nextCount()
public void init()
initReceiverServer().init in interface Initializableinit in class CastingContainerprotected void initReceiverServer()
public String getReceiverName()
public int getServerPort()
public int getBufferSize()
public int getServerPriority()
public int getHandlerPriority()
public void processError(ErrorEvent ee)
The default implementation is empty.
processError in interface ErrorProcessingthrown - The exception/error to be reported.public void run()
cancel is called,
it loops forever accepting
connections. If a client connects to the listening port the server
calls the abstract method protocol(java.net.Socket) that should in turn
launch a dedicated helper thread and should return immediately.public void exit()
exit in interface ExitCleaningexit in class CastingContainerprotected abstract void protocol(Socket client)
client - The client socket.CommandReceiver,
ErrorReceiverpublic void cancel()
run() loop. This I/O Exception is catched and the
cancel flag is querried within the catch. If it is
true this thread exits gracefully.cancel in interface CancelRunnablepublic Thread getAsociatedThread()
getAsociatedThread in interface CancelRunnablepublic long maxTimeToCancel()
maxTimeToCancel in interface CancelRunnable