|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.tuplespace.utils.UnitOfWorkRunner
A class that repeateadly executes a unit of work, always using the same
TupleSpace
.
This class allows subclasses to always be waiting for a
Tuple
., and do not have to concern themselves
with writing the plumbing:
while (true) { Tuple t = tupleSpace.readAndRemove(template); // Work with t }
Instead, subclasses simply have to implement the
execute(net.sf.tuplespace.TupleSpace)
method, and are guaranteed to always be waiting for a tuple.
Constructor Summary | |
UnitOfWorkRunner()
Instantiate a new unit of work, with default values. |
|
UnitOfWorkRunner(UnitOfWork unitOfWork,
TupleSpace tupleSpace)
Instantiate a new unit of work. |
Method Summary | |
void |
execute(TupleSpace tupleSpace)
Delegate to #unitOfWork . |
boolean |
isDone()
Delegate to #unitOfWork . |
void |
run()
Repeatedly call execute() ,
until either an exception is thrown, or isDone() is true .
|
void |
setAbortOnException(boolean abortOnException)
Determine what to do when exceptions occur. |
void |
setTupleSpace(TupleSpace tupleSpace)
Sets the TupleSpace to use.
|
void |
setUnitOfWork(UnitOfWork unitOfWork)
Sets the unit of work to execute. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public UnitOfWorkRunner()
It is imperative that you call setTupleSpace(net.sf.tuplespace.TupleSpace)
otherwise you will get an IllegalArgumentException
when calling
run()
, indicating that you haven't not provided a tuple space.
public UnitOfWorkRunner(UnitOfWork unitOfWork, TupleSpace tupleSpace)
It is illegal to provide a null
TupleSpace
.
unitOfWork
- The UnitOfWork
to run.tupleSpace
- The TupleSpace
to use.Method Detail |
public void setTupleSpace(TupleSpace tupleSpace)
TupleSpace
to use.
It is illegal to provide a null
TupleSpace
.
tupleSpace
- The TupleSpace
to use.public void setUnitOfWork(UnitOfWork unitOfWork)
unitOfWork
- The unit of work to repeateadly call.public void setAbortOnException(boolean abortOnException)
If this is true
, run()
will rethrow the
caught exception as a RuntimeException
. If this is
false
instead (the default), the exception will be logged
and run()
will loop and execute another unit of work.
abortOnException
- true
to make run()
return
when an exception occurs, false
otherwise.public final void run()
execute()
,
until either an exception is thrown, or isDone()
is true
.
Each time through the loop, #tupleSpace
will be asserted to
non-null. If it is, an IllegalArgumentException
will be thrown.
Also, after every call to execute(net.sf.tuplespace.TupleSpace)
,
this method will call isDone()
to determine if it should continue
or not.
run
in interface Runnable
public final void execute(TupleSpace tupleSpace) throws Exception
#unitOfWork
.
execute
in interface UnitOfWork
tupleSpace
- The space to provide to the delegee.
Exception
- Any exception that could be thrown from
UnitOfWork.execute(net.sf.tuplespace.TupleSpace)
.public final boolean isDone()
#unitOfWork
.
isDone
in interface UnitOfWork
true
or false
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |