public interface Collaboration
Represents a single task that is possibly decomposed in multiple subtasks and provides support for waiting for its
completion.
- Author:
- Fabrizio Giudici
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of messages related to thisCollaborationnot yet delivered.Return the duration of thisCollaboration.Returns the message that originated thisCollaboration.intReturns the number of messages related to thisCollaborationnot yet consumed.intReturns the number of running threads assigned to thisCollaboration.Return the time when thisCollaborationhas been created.booleanReturnstrueif theCollaborationhas been completed.booleanReturnstruewhen the currentCollaborationis suspended.voidResumes a suspendedCollaboration.voidresumeAndDie(Object suspensionToken) Resumes a suspendedCollaborationand lets it terminate without any further operation.suspend()Sometimes aCollaborationmust coordinate with the external world, waiting for an external asynchronous event that cannot be modeled with agents.voidWaits for the completion of thisCollaboration.
-
Field Details
-
NULL_COLLABORATION
-
-
Method Details
-
getOriginatingMessage
Returns the message that originated thisCollaboration.- Returns:
- the message
-
isCompleted
boolean isCompleted()Returnstrueif theCollaborationhas been completed.- Returns:
trueif theCollaborationhas been completed
-
waitForCompletion
Waits for the completion of thisCollaboration.- Throws:
InterruptedException- if the wait is interrupted
-
getStartTime
Return the time when thisCollaborationhas been created.- Returns:
- the creation time
-
getDuration
Return the duration of thisCollaboration.- Returns:
- the duration
-
suspend
Object suspend()Sometimes aCollaborationmust 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 theCollaborationmodel. 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
Resumes a suspendedCollaboration. It executes the givenRunnablewhich is expected to send new messages.- Parameters:
suspensionToken- the token representing the reason for the suspensionresumerTask- the code which resumes theCollaboration- See Also:
-
resumeAndDie
Resumes a suspendedCollaborationand lets it terminate without any further operation.- Parameters:
suspensionToken- the token representing the reason for the suspension- See Also:
-
isSuspended
boolean isSuspended()Returnstruewhen the currentCollaborationis suspended.- Returns:
truewhen it's suspended- See Also:
-
getDeliveringMessagesCount
int getDeliveringMessagesCount()Returns the number of messages related to thisCollaborationnot yet delivered.- Returns:
- the number of messages not yet delivered
-
getPendingMessagesCount
int getPendingMessagesCount()Returns the number of messages related to thisCollaborationnot yet consumed.- Returns:
- the number of messages not yet consumed
-
getRunningThreadsCount
int getRunningThreadsCount()Returns the number of running threads assigned to thisCollaboration.- Returns:
- the number of threads
-