Class AbstractTaskGenerator

All Implemented Interfaces:
Closeable, AutoCloseable, CommandReceivingComponent, Component, GeneratedDataReceivingComponent, PlatformConnector
Direct Known Subclasses:
AbstractSequencingTaskGenerator

public abstract class AbstractTaskGenerator extends AbstractPlatformConnectorComponent implements GeneratedDataReceivingComponent
This abstract class implements basic functions that can be used to implement a task generator. The following environment variables are expected:
Author:
Michael Röder (roeder@informatik.uni-leipzig.de)
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • DEFAULT_MAX_PARALLEL_PROCESSED_MESSAGES

      private static final int DEFAULT_MAX_PARALLEL_PROCESSED_MESSAGES
      Default value of the maxParallelProcessedMsgs attribute.
      See Also:
    • currentlyProcessedMessages

      private final Semaphore currentlyProcessedMessages
      Mutex used to provide control to Benchmark Controller over task generation.
    • startTaskGenMutex

      private Semaphore startTaskGenMutex
      Mutex used to wait for the start signal after the component has been started and initialized.
    • terminateMutex

      private Semaphore terminateMutex
      Mutex used to wait for the terminate signal.
    • generatorId

      private int generatorId
      The id of this generator.
    • numberOfGenerators

      private int numberOfGenerators
      The number of task generators created by the benchmark controller.
    • nextTaskId

      private long nextTaskId
      The task id that will be assigned to the next task generated by this generator.
    • maxParallelProcessedMsgs

      private final int maxParallelProcessedMsgs
      The maximum number of incoming messages that are processed in parallel. Additional messages have to wait.
    • sender2System

      protected DataSender sender2System
    • sender2EvalStore

      protected DataSender sender2EvalStore
    • dataGenReceiver

      protected DataReceiver dataGenReceiver
    • consumer

      @Deprecated protected QueueingConsumer consumer
      Deprecated.
    • runFlag

      protected boolean runFlag
  • Constructor Details

    • AbstractTaskGenerator

      public AbstractTaskGenerator()
      Default constructor creating an AbstractTaskGenerator processing up to DEFAULT_MAX_PARALLEL_PROCESSED_MESSAGES= 1 messages in parallel.
    • AbstractTaskGenerator

      public AbstractTaskGenerator(int maxParallelProcessedMsgs)
      Constructor setting the maximum number of parallel processed messages. Note that this parameter has to be larger or equal to 1 or the init() method will throw an exception. Setting maxParallelProcessedMsgs=1 leads to the usage of a QueueingConsumer.
      Parameters:
      maxParallelProcessedMsgs - the number of messaegs that are processed in parallel
  • 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 AbstractCommandReceivingComponent
      Throws:
      Exception - if an error occurs during the initialization
    • run

      public void run() throws Exception
      Description copied from interface: Component
      This method executes the component.
      Specified by:
      run in interface Component
      Throws:
      Exception - if an error occurs during the execution
    • receiveGeneratedData

      public void receiveGeneratedData(byte[] data)
      Description copied from interface: GeneratedDataReceivingComponent
      This method is called if data is received from a data generator.
      Specified by:
      receiveGeneratedData in interface GeneratedDataReceivingComponent
      Parameters:
      data - the data received from a data generator
    • generateTask

      protected abstract void generateTask(byte[] data) throws Exception
      Generates a task from the given data, sends it to the system, takes the timestamp of the moment at which the message has been sent to the system and sends it together with the expected response to the evaluation storage.
      Parameters:
      data - incoming data generated by a data generator
      Throws:
      Exception - if a sever error occurred
    • getNextTaskId

      protected String getNextTaskId()
      Generates the next unique ID for a task.
      Returns:
      the next unique task ID
    • receiveCommand

      public void receiveCommand(byte command, byte[] data)
      Description copied from interface: CommandReceivingComponent
      This method is called if a command is received and might be interesting for this particular component.
      Specified by:
      receiveCommand in interface CommandReceivingComponent
      Overrides:
      receiveCommand in class AbstractPlatformConnectorComponent
      Parameters:
      command - the byte encoding the command
      data - additional data that was sent together with the command
    • sendTaskToEvalStorage

      protected void sendTaskToEvalStorage(String taskIdString, long timestamp, byte[] data) throws IOException
      This method sends the given data and the given timestamp of the task with the given task id to the evaluation storage.
      Parameters:
      taskIdString - the id of the task
      timestamp - the timestamp of the moment in which the task has been sent to the system
      data - the expected response for the task with the given id
      Throws:
      IOException - if there is an error during the sending
    • sendTaskToSystemAdapter

      protected void sendTaskToSystemAdapter(String taskIdString, byte[] data) throws IOException
      Sends the given task with the given task id and data to the system.
      Parameters:
      taskIdString - the id of the task
      data - the data of the task
      Throws:
      IOException - if there is an error during the sending
    • getGeneratorId

      public int getGeneratorId()
    • getNumberOfGenerators

      public int getNumberOfGenerators()
    • close

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