Interface Collaboration


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
    Modifier and Type
    Interface
    Description
    static interface 
    A provider of a Collaboration.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Collaboration
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the number of messages related to this Collaboration not yet delivered.
    Return the duration of this Collaboration.
    Returns the message that originated this Collaboration.
    int
    Returns the number of messages related to this Collaboration not yet consumed.
    int
    Returns the number of running threads assigned to this Collaboration.
    Return the time when this Collaboration has been created.
    boolean
    Returns true if the Collaboration has been completed.
    boolean
    Returns true when the current Collaboration is suspended.
    void
    resume(Object suspensionToken, Runnable resumerTask)
    Resumes a suspended Collaboration.
    void
    resumeAndDie(Object suspensionToken)
    Resumes a suspended Collaboration and lets it terminate without any further operation.
    Sometimes a Collaboration must coordinate with the external world, waiting for an external asynchronous event that cannot be modeled with agents.
    void
    Waits for the completion of this Collaboration.
  • Field Details

    • NULL_COLLABORATION

      static final Collaboration NULL_COLLABORATION
  • Method Details

    • getOriginatingMessage

      @Nonnull Object getOriginatingMessage()
      Returns the message that originated this Collaboration.
      Returns:
      the message
    • isCompleted

      boolean isCompleted()
      Returns true if the Collaboration has been completed.
      Returns:
      true if the Collaboration has been completed
    • waitForCompletion

      void waitForCompletion() throws InterruptedException
      Waits for the completion of this Collaboration.
      Throws:
      InterruptedException - if the wait is interrupted
    • getStartTime

      @Nonnull ZonedDateTime getStartTime()
      Return the time when this Collaboration has been created.
      Returns:
      the creation time
    • getDuration

      @Nonnull Duration getDuration()
      Return the duration of this Collaboration.
      Returns:
      the duration
    • suspend

      Object suspend()
      Sometimes a Collaboration 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 the Collaboration 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, call resume(java.lang.Object, java.lang.Runnable). In order to support multiple reasons for suspension, a token is generated and returned. It must be passed to resume() for resuming.
      Returns:
      a token representing the reason for the suspension
      See Also:
    • resume

      void resume(@Nonnull Object suspensionToken, @Nonnull Runnable resumerTask)
      Resumes a suspended Collaboration. It executes the given Runnable which is expected to send new messages.
      Parameters:
      suspensionToken - the token representing the reason for the suspension
      resumerTask - the code which resumes the Collaboration
      See Also:
    • resumeAndDie

      void resumeAndDie(@Nonnull Object suspensionToken)
      Resumes a suspended Collaboration and lets it terminate without any further operation.
      Parameters:
      suspensionToken - the token representing the reason for the suspension
      See Also:
    • isSuspended

      boolean isSuspended()
      Returns true when the current Collaboration is suspended.
      Returns:
      true when it's suspended
      See Also:
    • getDeliveringMessagesCount

      @Nonnegative int getDeliveringMessagesCount()
      Returns the number of messages related to this Collaboration not yet delivered.
      Returns:
      the number of messages not yet delivered
    • getPendingMessagesCount

      @Nonnegative int getPendingMessagesCount()
      Returns the number of messages related to this Collaboration not yet consumed.
      Returns:
      the number of messages not yet consumed
    • getRunningThreadsCount

      @Nonnegative int getRunningThreadsCount()
      Returns the number of running threads assigned to this Collaboration.
      Returns:
      the number of threads