|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--com.ibm.tspaces.server.handler.TSHandler
|
+--com.ibm.tspaces.examples.handler.StaleTupleSpaceHandler
This class is a handler for a "StaleTupleSpace" this is a space that will clean up tuples that are in there too long. Currenly this only means from creation time, ie reading them or performing some other operation will not update a tuple's timestamp. But of course, the handlers for those commands could be re-implemented here to update the timestamps. The handler only operates on Tuples of type StaleTuple and these tuples must always have a long in the first field that is a timestamp field. The handler will initialize this value on write and return the value to the user if they want to use it for something eg as a unique index ( assuming currentTimeMills returns unique values). Two commands are implemented: TupleSpace.WRITE -- stamps the correct time in the first field before using the basic write command. START -- start the daemon on the server (only call this once). This starts a seperate daemon thread on the server that usually sleeps, but occasionally wakes up to check for stale tuples which it will delete.
TSFactory,
TSFExtendable,
TSHandler| Field Summary | |
static java.lang.String |
START
the command to start this handler up as a daemon on the server that periodically deletes stale tuples |
| Constructor Summary | |
StaleTupleSpaceHandler()
empty constructor called by the factory methods to create the new handler |
|
| Method Summary | |
com.ibm.tspaces.server.handler.AccessAttribute[] |
attributes(java.lang.String cmdString,
SuperTuple argTuple)
What type of access control attributes are required to use the handler? If a zero length array is returned this means no attributes are needed. |
SuperTuple |
command(com.ibm.tspaces.server.TS ts,
java.lang.String cmdString,
SuperTuple argTuple,
java.lang.String clientID_,
TSResponse communicator_,
java.lang.String user_)
Implement one or more "commands" (usually one). |
boolean |
handles(java.lang.String commandString,
SuperTuple argTuple)
Do I handle this command on this argument? For now, always say yes because the factory will only call us on the command strings that we handle and we operate on all types of tuples When each handler only handles one command, can tighten this up. |
static void |
main(java.lang.String[] argv)
This is code to test the handler by simulating what a client application would do to load a special handler and then invode the the new commands.Normally this code would be part of the application that is going to to make use of the handler. |
void |
run()
actually run as a background daemon and do the deletions of stale tuples. |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Field Detail |
public static final java.lang.String START
| Constructor Detail |
public StaleTupleSpaceHandler()
| Method Detail |
public final boolean handles(java.lang.String commandString,
SuperTuple argTuple)
commandString - the commandargTuple - the agument to the command
public com.ibm.tspaces.server.handler.AccessAttribute[] attributes(java.lang.String cmdString,
SuperTuple argTuple)
throws com.ibm.tspaces.server.handler.TSHandlerException
commandStr - the command in questionargTuple - The argument for the command.
public SuperTuple command(com.ibm.tspaces.server.TS ts,
java.lang.String cmdString,
SuperTuple argTuple,
java.lang.String clientID_,
TSResponse communicator_,
java.lang.String user_)
throws com.ibm.tspaces.server.handler.TSHandlerException
ts - The TupleSpace instance on which the command is executed.cmdString - The cmd to be invokedargTuple - The argument for the command.clientID_ - The client Transaction IDcommunicator_ - the io handle back to the clientuser_ - the user issuing the commandpublic void run()
public static void main(java.lang.String[] argv)
The basic steps are:
Create a TupleSpace. Remember that this function must be performed by a user that has "admin" authority for the server
issue an AddFactory specifing a factory that supports downlable handlers. The distributed TSFExtendable can be used for this..
Create the Handler object.
Issue an addHandler command for each of the commands that this handler will support.
The TupleSpace and its new commands are now ready for use so this routine will write a StaleTuple to the Space and then issue the START command which will actually start a thread at the server which will delete tuples when they expire.
This routine then writes some more StaleTuples just to verify that it is really working.
For this relatively simple test, we hardcode all of the values that we need.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||