|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.bigdata.service.FederationCallable<T>
com.bigdata.service.DataServiceCallable<U>
com.bigdata.service.jini.master.AbstractClientTask<S,U,V>
S - The generic for the TaskMaster.JobState.U - The generic for the Callable's return type.V - The generic type of the client state (stored in zookeeper).public abstract class AbstractClientTask<S extends TaskMaster.JobState,U,V extends Serializable>
An abstract base class which may be used for client tasks run by the master
on one or more data services. This class contends for a ZLock based
on the assigned clientNum and then invoked #runWithZLock()
if the ZLock if granted. If the lock is lost, it will continue to
contend for the lock and then run until finished.
Note: This implementation presumes that #runWithZLock() has some
means of understanding when it is done and can restart its work from where it
left off. One way to handle that is to write the state of the client into the
client's znode and to update that from time to time as the client makes
progress on its task. You can invoke setupClientState() to do that.
Note: This class DOES NOT have to be submitted to an IDataService for
execution. Most client tasks will in fact run on IClientServices
rather than IDataServices. This class extends
DataServiceCallable for the convienence of subclasses which MAY
introduce a requirement to execute on an IDataService.
| Field Summary | |
|---|---|
protected int |
clientNum
|
protected S |
jobState
|
protected static org.apache.log4j.Logger |
log
|
protected ZLockImpl |
zlock
The zpath for the ZLock node. |
| Constructor Summary | |
|---|---|
protected |
AbstractClientTask(S jobState,
int clientNum)
|
| Method Summary | |
|---|---|
U |
call()
Runs the generator. |
int |
getClientNum()
Return the index assigned to the client. |
JiniFederation |
getFederation()
Return the IBigdataFederation reference. |
S |
getJobState()
Return the jobstate. |
protected abstract V |
newClientState()
Return a new instance of the client's state. |
protected abstract U |
runWithZLock(V clientState)
Do work while holding the ZLock. |
void |
setFederation(IBigdataFederation fed)
Invoked before the task is executed to provide a reference to the IBigdataFederation for the service on which the task is
executing. |
protected V |
setupClientState()
The method invoked newClientState() and attempts to create the
client's znode with the serialized state as its data and that state will
be returned to the caller. |
String |
toString()
|
protected void |
writeClientState(V clientState)
Method updates the client state in zookeeper. |
| Methods inherited from class com.bigdata.service.DataServiceCallable |
|---|
getDataService, isDataService, setDataService |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected static final org.apache.log4j.Logger log
protected final S extends TaskMaster.JobState jobState
protected final int clientNum
protected transient ZLockImpl zlock
ZLock node. Only the instance of this task
holding the ZLock is allowed to run. This makes it safe to
run multiple instances of this task for the same clientNum.
If one instance dies, the instance that gains the ZLock will
read the client's state from zookeeper and continue processing.
This is null until call().
| Constructor Detail |
|---|
protected AbstractClientTask(S jobState,
int clientNum)
| Method Detail |
|---|
public S getJobState()
public int getClientNum()
public void setFederation(IBigdataFederation fed)
IFederationCallableIBigdataFederation for the service on which the task is
executing.
setFederation in interface IFederationCallablesetFederation in class FederationCallable<U>fed - The federation.public JiniFederation getFederation()
IFederationCallableIBigdataFederation reference.
getFederation in interface IFederationCallablegetFederation in class FederationCallable<U>null.public String toString()
toString in class Object
public U call()
throws Exception
call in interface Callable<U>Exception
protected abstract U runWithZLock(V clientState)
throws Exception,
org.apache.zookeeper.KeeperException,
InterruptedException
ZLock. The implementation SHOULD verify
from time to time that it in fact holds the ZLock using
ZLock.isLockHeld().
Exception
org.apache.zookeeper.KeeperException
InterruptedException
protected V setupClientState()
throws InterruptedException,
org.apache.zookeeper.KeeperException
newClientState() and attempts to create the
client's znode with the serialized state as its data and that state will
be returned to the caller. If there is an existing znode for the client,
then the data of the znode is de-serialized and returned by this method.
This method is invoked automatically from within call() before
the client attempts to obtain the ZLock (the zlock is a child of
the client's znode).
You can update the client's state from time to time using
writeClientState(Serializable). If the client looses the
ZLock, it can read the client state from zookeeper using this
method and pick up processing more or less where it left off (depending
on when you last updated the client state in zookeeper).
InterruptedException
org.apache.zookeeper.KeeperExceptionTaskMaster.JobState.getClientZPath(JiniFederation, int)
protected void writeClientState(V clientState)
throws org.apache.zookeeper.KeeperException,
InterruptedException
ZLock (this is verified).
clientState - The state to be written into the znode identified by
clientZPath.
InterruptedException
org.apache.zookeeper.KeeperExceptionprotected abstract V newClientState()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||