com.ibm.tspaces
Class CallbackThread

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--com.ibm.tspaces.CallbackThread

public class CallbackThread
extends java.lang.Thread

The callback thread handles all communication that is sent from the server to the client, that is all responses from a server.

TupleSpace.talkToAServer method, which handles all requests, will register a response handler with the callback thread for the server it is talking to for each and every request it sends. The callback thread just hands the responses over to these response handler (callback) guys. The class CallbackThread is always run on the client side and handles the case where the server needs to "callback" the client. This is whenever a tuple space operation would block. So, the idea is that this thread just sits around waiting for the server to send tuples back for old requests. A unique sequence # is sent with each and every request and thus, this class can figure out which request goes where. The TSCmdSocketImpl class has more complete documentation on the process.

Author:
Pete Wyckoff
See Also:
Callback, TSCmd, TSCmdSocketImpl, TSCmdLocalImpl, TSDispatch, TSIOHandler, TupleSpace

Field Summary
 java.lang.Integer _SYSTEM_CALLBACK_NUMBER
          the system itself registers a callback so that the server can tell it stuff.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
CallbackThread(java.net.Socket s_, java.lang.String hostAndPort_)
          constructor for callback thread creates its server socket to activate itself.
CallbackThread(TSCmdLocalImpl tscmd_)
          constructor for callback thread when it gets the Reply Tuple from a queue instead of from a socket.
 
Method Summary
 void addWaiter(java.lang.Integer seqNum_, Callback cb_, java.lang.String cmdString_, SuperTuple argTuple_, java.lang.String tsName_, boolean newThread_, java.lang.String clientID_)
          Add another callback object and its sequence # to our pending table
 void removeWaiter(java.lang.Integer seqNum_)
          Remove a waiter from my pending table.
 void run()
          This is the main code for the callback listener thread.
 void shutdown(java.lang.Exception ioe_)
          shutdown this listener due to an IO exception, called by TupleSpace.killConnection.
 void stopCallback()
          This method allows the TupleSpace instance to issue a stop to this thread.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, 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

_SYSTEM_CALLBACK_NUMBER

public java.lang.Integer _SYSTEM_CALLBACK_NUMBER
the system itself registers a callback so that the server can tell it stuff.
Constructor Detail

CallbackThread

public CallbackThread(java.net.Socket s_,
                      java.lang.String hostAndPort_)
constructor for callback thread creates its server socket to activate itself. It opens it on any free port. It will setup the SYSTEM callback Object and add it to the tables
See Also:
TupleSpace, CallbackThread, TSDispatch

CallbackThread

public CallbackThread(TSCmdLocalImpl tscmd_)
constructor for callback thread when it gets the Reply Tuple from a queue instead of from a socket. It will setup the SYSTEM callback Object and add it to the tables
Throws:
java.io.IOException - if there is a problem creating the server socket
See Also:
TupleSpace, CallbackThread, TSDispatch
Method Detail

addWaiter

public void addWaiter(java.lang.Integer seqNum_,
                      Callback cb_,
                      java.lang.String cmdString_,
                      SuperTuple argTuple_,
                      java.lang.String tsName_,
                      boolean newThread_,
                      java.lang.String clientID_)
Add another callback object and its sequence # to our pending table
Parameters:
seqNum_ - the sequence number of this waiting request
cb_ - the callback object to call when this request arrives
cmdString_ - the command that this waiter is waiting on --- normally it is the command that is being executed but for event registration, it is the command that we are registering an event on.
tsName_ - the tuple space that the command is operating on
newThread_ - If true, a new thread will be started for the callback
See Also:
TupleSpace, Callback, TSDispatch

removeWaiter

public void removeWaiter(java.lang.Integer seqNum_)
Remove a waiter from my pending table. May be called from TSCmdSocketImp.talkToAServer if the command is serviced by the server without blocking or by this.run when the command is serviced by blocking.
Parameters:
seqNum_ - the sequence # of the waiter to be removed If zero, then remove all waiters.
See Also:
TupleSpace, Callback, TSDispatch

stopCallback

public void stopCallback()
This method allows the TupleSpace instance to issue a stop to this thread.
See Also:
TupleSpace

run

public void run()
This is the main code for the callback listener thread. It will run Forever (although this class is run as a daemon and therefore will terminate when all non-daemon threads do) If running for a socket connection to a server then:
- Read a response Tuple from the socket (handle any socket error conditions) - Call doTheCallback The value specified for TupleSpace.setCommandWaitTime(long) is used to specify a socket timeout value for causing an InterruptedIOException to be thrown for network stalls If running for a Local connection to the server, then:
- get next response from TSCmdLocalImpl queue - Call doTheCallback
Overrides:
run in class java.lang.Thread
See Also:
TupleSpace, Callback, TSDispatch

shutdown

public void shutdown(java.lang.Exception ioe_)
shutdown this listener due to an IO exception, called by TupleSpace.killConnection. Each pending callback is called back with the IOexception. If the listener itself discovers the io exception, it calls TupleSpace.killConnection from its run method, then this shutdown method is called from there. It can also be called from cleanup() with a TupleSpaceException.
Parameters:
ioe_, - the io exception that is causing the shutdown.
See Also:
TupleSpace, Callback, TSDispatch, because these two are synched so that they will avoid collisions in talking to client callbacks