A bundle can use the Coordinator service to create {@link Coordination}objects. Once a Coordination object is created, it can be {@link Coordination#push() pushed} on the thread local Coordination stack tobe an implicit parameter as the current Coordination for calls to other parties, or it can be passed directly to other parties as an argument. The current Coordination, which is on the top of the current thread's thread local Coordination stack, can be obtained with {@link #peek()}.
Any active Coordinations created by a bundle must be terminated when the bundle releases the Coordinator service. The Coordinator service must {@link Coordination#fail(Throwable) fail} these Coordinations with the{@link Coordination#RELEASED RELEASED} exception.
A {@link Participant} can {@link Coordination#addParticipant(Participant) register} to participate in a Coordination and receive notification of thetermination of the Coordination.
The following example code shows a example usage of the Coordinator service.
void foo() { Coordination c = coordinator.begin("work", 0); try { doWork(); } catch (Exception e) { c.fail(e); } finally { c.end(); } }In the {@code doWork} method, code can be called that requires notificationof the termination of the Coordination. The {@code doWork} method can thenregister a Participant with the Coordination.
void doWork() { if (coordinator.addParticipant(this)) { beginWork(); } else { beginWork(); finishWork(); } } void ended(Coordination c) { finishWork(); } void failed(Coordination c) { undoWork(); }@ThreadSafe @noimplement @author $Id: e2e1850c645234dd7a546a2f6a77ba6fc8d3c73b $
|
|
|
|
|
|