Class AbstractSequencingTaskGenerator

All Implemented Interfaces:
Closeable, AutoCloseable, CommandReceivingComponent, Component, GeneratedDataReceivingComponent, PlatformConnector

public abstract class AbstractSequencingTaskGenerator extends AbstractTaskGenerator
Extension of the AbstractTaskGenerator that offers methods to wait for acknowledgements for single tasks. The workflow for waiting for a task is

Note that the acknowledgements only work if the evaluation storage is configured to send acknowledgements for the single tasks.

Author:
Michael Röder (roeder@informatik.uni-leipzig.de)
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • DEFAULT_ACK_TIMEOUT

      private static final long DEFAULT_ACK_TIMEOUT
      Default timeout for the acknowledgement.
      See Also:
    • ackTimeout

      private long ackTimeout
      Timeout for the acknowledgement.
    • seqTaskId

      private String seqTaskId
      Id of the task the generator is waiting for an acknowledgement.
    • taskIdMutex

      private Semaphore taskIdMutex
      Semaphore used to wait for the acknowledgement.
    • ackChannel

      protected com.rabbitmq.client.Channel ackChannel
      Channel on which the acknowledgments are received.
  • Constructor Details

    • AbstractSequencingTaskGenerator

      public AbstractSequencingTaskGenerator()
  • Method Details

    • init

      public void init() throws Exception
      Description copied from interface: Component
      This method initializes the component.
      Specified by:
      init in interface Component
      Overrides:
      init in class AbstractTaskGenerator
      Throws:
      Exception - if an error occurs during the initialization
    • handleAck

      protected void handleAck(byte[] body)
      Handles the acknowledgement messages.
      Parameters:
      body - the body of the acknowledgement message
    • sendTaskToSystemAdapter

      protected void sendTaskToSystemAdapter(String taskIdString, byte[] data) throws IOException
      Sends the given task with the given task id and data to the system and blocks until an acknowledgement has been received for the task or the timeout has been reached. If an information is needed which of these two cases happened sendTaskToSystemAdapterInSequence(String, byte[]) should be used.
      Overrides:
      sendTaskToSystemAdapter in class AbstractTaskGenerator
      Parameters:
      taskIdString - the id of the task
      data - the data of the task
      Throws:
      IOException - if there is an error during the sending
    • sendTaskToSystemAdapterInSequence

      protected boolean sendTaskToSystemAdapterInSequence(String taskIdString, byte[] data) throws IOException
      Sends the given task with the given task id and data to the system and blocks until an acknowledgement has been received for the task or the timeout has been reached. The return value shows which of these two cases happened.
      Parameters:
      taskIdString - the task id
      data - the data of the task
      Returns:
      true if the acknowledgement has been received, false if the timeout has been reached or the method has been interrupted.
      Throws:
      IOException - if there is an error during the sending
    • setTaskIdToWaitFor

      @Deprecated protected void setTaskIdToWaitFor(String taskId)
      Deprecated.
      It is not necessary anymore since its usage has been integrated into the sendTaskToSystemAdapterInSequence(String, byte[]) method.
      Method to set the task id for which the task generator will wait when calling waitForAck().
      Parameters:
      taskId - id of the task for which the acknowledgement should be received
    • waitForAck

      private boolean waitForAck()
      Method to wait for the acknowledgement of a task with the given Id.
      Returns:
      true if the acknowledgement has been received, false if the timeout has been reached or the method has been interrupted.
    • setAckTimeout

      public void setAckTimeout(long ackTimeout)
      Setter for the maximum time the task generator waits for an acknowledgement.
      Parameters:
      ackTimeout - the new timeout in milliseconds
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class AbstractTaskGenerator
      Throws:
      IOException