Once a Coordination is created, it
can be used to add Participant objects. When the Coordination is
ended, the participants are notified.
A Coordination can also fail for various reasons. When this occurs, the
participants are notified of the
failure.
A Coordination must be in one of two states, either ACTIVE or TERMINATED. The transition between ACTIVE and TERMINATED must be atomic, ensuring that a Participant can be guaranteed of either receiving an exception when adding itself to a Coordination or of receiving notification the Coordination has terminated.
A Coordination object is thread safe and can be passed as a parameter to other parties regardless of the threads these parties use.
The following example code shows how a Coordination should be used.
void foo() {
Coordination c = coordinator.create("work", 0);
try {
doWork(c);
}
catch (Exception e) {
c.fail(e);
}
finally {
c.end();
}
}
| Modifier and Type | Field and Description |
|---|---|
| public static final Exception | ORPHANED
A singleton exception that will be the failure cause when a Coordination has been orphaned. |
| public static final Exception | RELEASED
A singleton exception that will be the failure cause when the Coordinations created by a bundle are terminated because the bundle released the Coordinator service. |
| public static final Exception | TIMEOUT
A singleton exception that will be the failure cause when a Coordination times out. |
| Modifier and Type | Method and Description |
|---|---|
| public void | addParticipant(Participant
The Participant to register with this Coordination.
The participant must not be participant)null.Register a Participant with this Coordination. |
| public void | |
| public long | Returns: The new deadline in milliseconds. If the specified time is 0, the existing deadline is returned. If this Coordination was created with an initial timeout of 0, no timeout is set and 0 is returned.The time in milliseconds to extend the current timeout.
If the initial timeout was specified as 0, no extension must take
place. A zero must have no effect. timeMillis)Extend the time out of this Coordination. |
| public boolean | |
| public Bundle | Returns: The bundle that created this Coordination.Returns the bundle that created this Coordination. |
| public Coordination | Returns: The Coordination enclosing this Coordination if this Coordination is on the thread local Coordination stack ornull if this
Coordination is not on the thread local Coordination stack or has
no enclosing Coordination.Returns the Coordination enclosing this Coordination if this Coordination is on the thread local Coordination stack. |
| public Throwable | Returns: The failure cause of this Coordination ornull if this
Coordination has not terminated as a failure.Returns the failure cause of this Coordination. |
| public long | |
| public String | |
| public List | Returns: A snapshot of the Participants registered with this Coordination. If no Participants are registered with this Coordination, the returned list will be empty. The list is ordered in the order the Participants were registered. The returned list is the property of the caller and can be modified by the caller.Returns a snapshot of the Participants registered with this Coordination. |
| public Thread | |
| public Map | Returns: The variable map associated with this Coordination.Returns the variable map associated with this Coordination. |
| public boolean | Returns: true if this Coordination is terminated, otherwise
false if this Coordination is active.Returns whether this Coordination is terminated. |
| public void | join(long
Maximum time in milliseconds to wait. Specifying a time
of 0 will wait until this Coordination is terminated. timeMillis)Wait until this Coordination is terminated and all registered Participants have been notified. |
| public Coordination | Returns: This Coordination.Push this Coordination object onto the thread local Coordination stack to
make it the |
| ORPHANED | back to summary |
|---|---|
| public static final Exception ORPHANED A singleton exception that will be the failure cause when a Coordination has been orphaned. | |
| RELEASED | back to summary |
|---|---|
| public static final Exception RELEASED A singleton exception that will be the failure cause when the Coordinations created by a bundle are terminated because the bundle released the Coordinator service. | |
| TIMEOUT | back to summary |
|---|---|
| public static final Exception TIMEOUT A singleton exception that will be the failure cause when a Coordination times out. | |
| addParticipant | back to summary |
|---|---|
| public void addParticipant(Participant participant) Register a Participant with this Coordination.
Once a Participant is registered with this Coordination, it is guaranteed
to receive a notification for either
Participants are registered using their object identity. Once a Participant is registered with this Coordination, subsequent attempts to register the Participant again with this Coordination are ignored and the Participant is only notified once when this Coordination is terminated. A Participant can only be registered with a single active Coordination at a time. If a Participant is already registered with an active Coordination, attempts to register the Participation with another active Coordination will block until the Coordination the Participant is registered with terminates. Notice that in edge cases the notification to the Participant that this Coordination has terminated can happen before this method returns.
Attempting to register a Participant with a The ordering of notifying Participants must follow the reverse order in which the Participants were registered.
| |
| end | back to summary |
|---|---|
| public void end() Terminate this Coordination normally.
If this Coordination has been
If this Coordination has been
If this Coordination is the
If this Coordination is already terminated, a CoordinationException is
thrown. If this Coordination was terminated as a failure, the
Otherwise, this Coordination is terminated normally and then all
registered
It is possible that one of the Participants throws an exception during
notification. If this happens, this Coordination is considered to have
partially failed and this method must throw a CoordinationException of
type
| |
| extendTimeout | back to summary |
|---|---|
| public long extendTimeout(long timeMillis) Extend the time out of this Coordination. Participants can call this method to extend the timeout of this Coordination with at least the specified time. This can be done by Participants when they know a task will take more than normal time. This method will return the new deadline if an extension took place or the current deadline if, for whatever reason, no extension takes place. Note that if a maximum timeout is in effect, the deadline may not be extended by as much as was requested, if at all. If there is no deadline, zero is returned. Specifying a timeout extension of 0 will return the existing deadline.
| |
| fail | back to summary |
|---|---|
| public boolean fail(Throwable cause) Terminate this Coordination as a failure with the specified failure cause.
If this Coordination is already
Otherwise, this Coordination is terminated as a failure with the
specified failure cause and then all registered
If this Coordination has been
| |
| getBundle | back to summary |
|---|---|
| public Bundle getBundle() Returns the bundle that created this Coordination. This is the bundle
that obtained the
| |
| getEnclosingCoordination | back to summary |
|---|---|
| public Coordination getEnclosingCoordination() Returns the Coordination enclosing this Coordination if this Coordination is on the thread local Coordination stack.
When a Coordination is
| |
| getFailure | back to summary |
|---|---|
| public Throwable getFailure() Returns the failure cause of this Coordination.
If this Coordination has
If this Coordination timed out, this method will return
| |
| getId | back to summary |
|---|---|
| public long getId() Returns the id assigned to this Coordination.
The id is assigned by the
| |
| getName | back to summary |
|---|---|
| public String getName() Returns the name of this Coordination. The name is specified when this Coordination was created.
| |
| getParticipants | back to summary |
|---|---|
| public List Returns a snapshot of the Participants registered with this Coordination.
| |
| getThread | back to summary |
|---|---|
| public Thread getThread() Returns the thread in whose thread local Coordination stack this
Coordination has been
| |
| getVariables | back to summary |
|---|---|
| public Map Returns the variable map associated with this Coordination. Each Coordination has a map that can be used for communicating between different Participants. The key of the map is a class, allowing for private data to be stored in the map by using implementation classes or shared data by using shared interfaces. The returned map is not synchronized. Users of the map must synchronize on the Map object while making changes.
| |
| isTerminated | back to summary |
|---|---|
| public boolean isTerminated() Returns whether this Coordination is terminated.
| |
| join | back to summary |
|---|---|
| public void join(long timeMillis) throws InterruptedException Wait until this Coordination is terminated and all registered Participants have been notified.
| |
| push | back to summary |
|---|---|
| public Coordination push() Push this Coordination object onto the thread local Coordination stack to
make it the
| |