Package it.tidalwave.actor
Interface Collaboration
-
public interface Collaboration
Represents a single task that is possibly decomposed in multiple subtasks and provides support for waiting for it completion.- Author:
- Fabrizio Giudici
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
Collaboration.Provider
A provider of aCollaboration
.
-
Field Summary
Fields Modifier and Type Field Description static Collaboration
NULL_COLLABORATION
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description int
getDeliveringMessagesCount()
Returns the number of messages related to thisCollaboration
not yet delivered.org.joda.time.Duration
getDuration()
Return the duration of thisCollaboration
.java.lang.Object
getOriginatingMessage()
Returns the message that originated thisCollaboration
.int
getPendingMessagesCount()
Returns the number of messages related to thisCollaboration
not yet consumed.int
getRunningThreadsCount()
Returns the number of running threads assigned to thisCollaboration
.org.joda.time.DateTime
getStartTime()
Return the time when thisCollaboration
has been created.boolean
isCompleted()
Returnstrue
if theCollaboration
has been completed.boolean
isSuspended()
Returnstrue
when the currentCollaboration
is suspended.void
resume(java.lang.Object suspensionToken, java.lang.Runnable resumerTask)
Resumes a suspendedCollaboration
.void
resumeAndDie(java.lang.Object suspensionToken)
Resumes a suspendedCollaboration
and lets it terminate without any further operation.java.lang.Object
suspend()
Sometimes aCollaboration
must coordinate with the external world, waiting for an external asynchronous event that cannot be modeled with agents.void
waitForCompletion()
Waits for the completion of thisCollaboration
.
-
-
-
Field Detail
-
NULL_COLLABORATION
static final Collaboration NULL_COLLABORATION
-
-
Method Detail
-
getOriginatingMessage
@Nonnull java.lang.Object getOriginatingMessage()
Returns the message that originated thisCollaboration
.- Returns:
- the message
-
isCompleted
boolean isCompleted()
Returnstrue
if theCollaboration
has been completed.- Returns:
true
if theCollaboration
has been completed
-
waitForCompletion
void waitForCompletion() throws java.lang.InterruptedException
Waits for the completion of thisCollaboration
.- Throws:
java.lang.InterruptedException
- if the wait is interrupted
-
getStartTime
@Nonnull org.joda.time.DateTime getStartTime()
Return the time when thisCollaboration
has been created.- Returns:
- the creation time
-
getDuration
@Nonnull org.joda.time.Duration getDuration()
Return the duration of thisCollaboration
.- Returns:
- the duration
-
suspend
java.lang.Object suspend()
Sometimes aCollaboration
must coordinate with the external world, waiting for an external asynchronous event that cannot be modeled with agents. For instance, a user intervention (e.g. by clicking a button) or an external piece of software that is not part of theCollaboration
model. In this case, it can be marked as 'suspended' and in this case it won't be considered completed, even though there are no related pending messages or working threads. When the external event occurs, callresume(java.lang.Object, java.lang.Runnable)
. In order to support multiple reasons for suspension, a token is generated and returned. It must be passed toresume()
for resuming.- Returns:
- a token representing the reason for the suspension
- See Also:
resume(java.lang.Object, java.lang.Runnable)
,isSuspended()
-
resume
void resume(@Nonnull java.lang.Object suspensionToken, @Nonnull java.lang.Runnable resumerTask)
Resumes a suspendedCollaboration
. It executes the givenRunnable
which is expected to send new messages.- Parameters:
suspensionToken
- the token representing the reason for the suspensionresumerTask
- the code which resumes theCollaboration
- See Also:
suspend()
,isSuspended()
-
resumeAndDie
void resumeAndDie(@Nonnull java.lang.Object suspensionToken)
Resumes a suspendedCollaboration
and lets it terminate without any further operation.- Parameters:
suspensionToken
- the token representing the reason for the suspension- See Also:
suspend()
,resume(java.lang.Object, java.lang.Runnable)
,isSuspended()
-
isSuspended
boolean isSuspended()
Returnstrue
when the currentCollaboration
is suspended.- Returns:
true
when it's suspended- See Also:
suspend()
,resume(java.lang.Object, java.lang.Runnable)
-
getDeliveringMessagesCount
@Nonnegative int getDeliveringMessagesCount()
Returns the number of messages related to thisCollaboration
not yet delivered.- Returns:
- the number of messages not yet delivered
-
getPendingMessagesCount
@Nonnegative int getPendingMessagesCount()
Returns the number of messages related to thisCollaboration
not yet consumed.- Returns:
- the number of messages not yet consumed
-
getRunningThreadsCount
@Nonnegative int getRunningThreadsCount()
Returns the number of running threads assigned to thisCollaboration
.- Returns:
- the number of threads
-
-