com.ibm.tspaces
Class Waiter

java.lang.Object
  |
  +--com.ibm.tspaces.Waiter

public class Waiter
extends java.lang.Object
implements Callback

The Waiter class is used as the simplest type of callback method for making the basic synchronous tuple space operations actually synchronous in the case where the server is going to do a call back. Actually, it is even used when there is no callback just to make things uniform. From someone talking to the server through the tuple space interface, there should be no way to tell if a callback was issued or the command immediately returned --- at least from a programming perspective there is no reason to have different control flow paths. It implements the callback interface by implementing call(tuple, boolean). Its call just saves the tuple and makes it available to others through a public member that returns the tuple.

Author:
Pete Wyckoff
See Also:
CallbackThread, (especially the command method), Semaphore, TSDispatch

Constructor Summary
Waiter()
           
 
Method Summary
 boolean call(java.lang.String eventName_, java.lang.String tsName_, int sequenceNumber_, SuperTuple tuple_, boolean isException_)
          Call an application back with a tuple it requested.
 boolean isException()
          Was there an exception for this callback?
 boolean isTimeOut()
          Was the wait interrupted or timed out?
 SuperTuple tuple()
          Return the queued up tuple
 void waitFor(long timeout_)
          Wait for the call method to be called This method calls the semaphore's decrement method to block until the tuple arrives.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Waiter

public Waiter()
Method Detail

call

public boolean call(java.lang.String eventName_,
                    java.lang.String tsName_,
                    int sequenceNumber_,
                    SuperTuple tuple_,
                    boolean isException_)
Call an application back with a tuple it requested. In the case of an exceptional condition occurring on the server, isException will be true and the exception will be inside the tuple_, i.e., the tuple will contain one field that is a TupleSpaceServerException. This method is called by the callback thread and thus should do something really quick and return, that is it should not take up lots of time. Typically, it might just queue up the tuple and isException and wake up some other thread that will do the real processing, at least that is the intention. This design may need to be changed in which case one alternative is for this guy to be a thread which gets fired up by the callback thread. I am not sure as to whether JavaSpaces makes this into a new thread or not even after looking at the section on it, but I will come back to this. PW Also, true is returned if this is the last call this callback class is expecting. For a one time read or in etc this is the case, but for EventHandlers, this is not the case, they will keep on servicing more and more events. The problem here may be that I am using one interface for two somewhat different things, although they are only really different in their longevity. Let's keep it this way until we see how the API should evolve. PW
Specified by:
call in interface Callback
Parameters:
eventName_ - the name of the event command that caused this call, that is the name of the client side command of the thread that registered this call, e.g., in the case of a read, this would be TupleSpace.READ, **not** TupleSpace.WRITE which is the corresponding command that caused the actaul event.
tsName_ - the name of the tuple space this command was executed on.
sequenceNumber_ - the sequenceNumber for this event/command
tuple_ - the returned tuple or a Tuple with an exception inside
isException_ - was the command processed normaly or was there an exception
Returns:
true if this is the last call this sequence # should be getting otherwise false
See Also:
TupleSpace, CallbackThread, TSDispatch

waitFor

public void waitFor(long timeout_)
Wait for the call method to be called This method calls the semaphore's decrement method to block until the tuple arrives.
Parameters:
timeout_ - The time it should wait before indicating there is a timeout

tuple

public SuperTuple tuple()
Return the queued up tuple
Returns:
the tuple that was given to the call method

isException

public boolean isException()
Was there an exception for this callback?
Returns:
whether there was an exception

isTimeOut

public boolean isTimeOut()
Was the wait interrupted or timed out?
Returns:
whether there was aa timeout