@InterfaceAudience.Private public class Procedure extends Object implements Callable<Void>, ForeignExceptionListener
All procedures first attempt to reach a barrier point with the sendGlobalBarrierStart()
method. The procedure contacts all members and waits for all subprocedures to execute
Subprocedure.acquireBarrier()
to acquire its local piece of the global barrier and then
send acquisition info back to the coordinator. If all acquisitions at subprocedures succeed,
the coordinator then will call sendGlobalBarrierReached()
. This notifies members to
execute the Subprocedure.insideBarrier()
method. The procedure is blocked until all
Subprocedure.insideBarrier()
executions complete at the members. When
Subprocedure.insideBarrier()
completes at each member, the member sends notification to
the coordinator. Once all members complete, the coordinator calls
sendGlobalBarrierComplete()
.
If errors are encountered remotely, they are forwarded to the coordinator, and
Subprocedure.cleanup(Exception)
is called.
Each Procedure and each Subprocedure enforces a time limit on the execution time. If the time
limit expires before the procedure completes the TimeoutExceptionInjector
will trigger
an ForeignException
to abort the procedure. This is particularly useful for situations
when running a distributed Subprocedure
so participants can avoid blocking for extreme
amounts of time if one of the participants fails or takes a really long time (e.g. GC pause).
Users should generally not directly create or subclass instances of this. They are created
for them implicitly via ProcedureCoordinator.startProcedure(ForeignExceptionDispatcher,
String, byte[], List)
}
Modifier and Type | Field and Description |
---|---|
protected TimeoutExceptionInjector |
timeoutInjector |
protected long |
wakeFrequency
frequency to check for errors (ms)
|
Constructor and Description |
---|
Procedure(ProcedureCoordinator coord,
ForeignExceptionDispatcher monitor,
long wakeFreq,
long timeout,
String procName,
byte[] args,
List<String> expectedMembers)
Creates a procedure.
|
Procedure(ProcedureCoordinator coord,
long wakeFreq,
long timeout,
String procName,
byte[] args,
List<String> expectedMembers)
Create a procedure.
|
Modifier and Type | Method and Description |
---|---|
void |
barrierAcquiredByMember(String member)
Call back triggered by an individual member upon successful local barrier acquisition
|
void |
barrierReleasedByMember(String member,
byte[] dataFromMember)
Call back triggered by a individual member upon successful local in-barrier execution and
release
|
Void |
call()
This call is the main execution thread of the barriered procedure.
|
ForeignExceptionDispatcher |
getErrorMonitor()
Get the ForeignExceptionDispatcher
|
String |
getName() |
String |
getStatus() |
boolean |
isCompleted()
Check if the entire procedure has globally completed, or has been aborted.
|
void |
receive(ForeignException e)
A callback that handles incoming ForeignExceptions.
|
void |
sendGlobalBarrierComplete()
Sends a message to members that all
Subprocedure.insideBarrier() calls have completed. |
void |
sendGlobalBarrierReached()
Sends a message to all members that the global barrier condition has been satisfied.
|
void |
sendGlobalBarrierStart()
Sends a message to Members to create a new
Subprocedure for this Procedure and execute
the Subprocedure.acquireBarrier() step. |
void |
waitForCompleted()
Waits until the entire procedure has globally completed, or has been aborted.
|
HashMap<String,byte[]> |
waitForCompletedWithRet()
Waits until the entire procedure has globally completed, or has been aborted.
|
static void |
waitForLatch(CountDownLatch latch,
ForeignExceptionSnare monitor,
long wakeFrequency,
String latchDescription)
Wait for latch to count to zero, ignoring any spurious wake-ups, but waking periodically to
check for errors
|
protected final long wakeFrequency
protected final TimeoutExceptionInjector timeoutInjector
public Procedure(ProcedureCoordinator coord, ForeignExceptionDispatcher monitor, long wakeFreq, long timeout, String procName, byte[] args, List<String> expectedMembers)
Procedure
state to be run by a ProcedureCoordinator
.coord
- coordinator to call back to for general errors (e.g.
ProcedureCoordinator.rpcConnectionFailure(String, IOException)
).monitor
- error monitor to check for external errorswakeFreq
- frequency to check for errors while waitingtimeout
- amount of time to allow the procedure to run before cancellingprocName
- name of the procedure instanceargs
- argument data associated with the procedure instanceexpectedMembers
- names of the expected memberspublic Procedure(ProcedureCoordinator coord, long wakeFreq, long timeout, String procName, byte[] args, List<String> expectedMembers)
ProcedureCoordinator.createProcedure(ForeignExceptionDispatcher,
String, byte[], List)
}coord
- coordinator to call back to for general errors (e.g.
ProcedureCoordinator.rpcConnectionFailure(String, IOException)
).wakeFreq
- frequency to check for errors while waitingtimeout
- amount of time to allow the procedure to run before cancellingprocName
- name of the procedure instanceargs
- argument data associated with the procedure instanceexpectedMembers
- names of the expected memberspublic String getName()
public String getStatus()
public ForeignExceptionDispatcher getErrorMonitor()
public final Void call()
public void sendGlobalBarrierStart() throws ForeignException
Subprocedure
for this Procedure and execute
the Subprocedure.acquireBarrier()
step.ForeignException
public void sendGlobalBarrierReached() throws ForeignException
Subprocedure.acquireBarrier()
call successfully. This triggers the member
Subprocedure.insideBarrier()
method.ForeignException
public void sendGlobalBarrierComplete()
Subprocedure.insideBarrier()
calls have completed.
After this executes, the coordinator can assume that any state resources about this barrier
procedure state has been released.public void barrierAcquiredByMember(String member)
member
- public void barrierReleasedByMember(String member, byte[] dataFromMember)
member
- dataFromMember
- public void waitForCompleted() throws ForeignException, InterruptedException
ForeignException
InterruptedException
public HashMap<String,byte[]> waitForCompletedWithRet() throws ForeignException, InterruptedException
ForeignException
InterruptedException
public boolean isCompleted() throws ForeignException
ForeignException
public void receive(ForeignException e)
receive
in interface ForeignExceptionListener
e
- exception causing the error. Implementations must accept and handle null here.public static void waitForLatch(CountDownLatch latch, ForeignExceptionSnare monitor, long wakeFrequency, String latchDescription) throws ForeignException, InterruptedException
latch
- latch to wait onmonitor
- monitor to check for errors while waitingwakeFrequency
- frequency to wake up and check for errors (in
TimeUnit.MILLISECONDS
)latchDescription
- description of the latch, for loggingForeignException
- type of error the monitor can throw, if the task failsInterruptedException
- if we are interrupted while waiting on latchCopyright © 2007-2016 The Apache Software Foundation. All Rights Reserved.