Package org.hobbit.core.components
Class AbstractSequencingTaskGenerator
java.lang.Object
org.hobbit.core.components.AbstractComponent
org.hobbit.core.components.AbstractCommandReceivingComponent
org.hobbit.core.components.AbstractPlatformConnectorComponent
org.hobbit.core.components.AbstractTaskGenerator
org.hobbit.core.components.AbstractSequencingTaskGenerator
- All Implemented Interfaces:
Closeable,AutoCloseable,CommandReceivingComponent,Component,GeneratedDataReceivingComponent,PlatformConnector
Extension of the
AbstractTaskGenerator that offers methods to wait
for acknowledgements for single tasks. The workflow for waiting for a task is
- generate a task and a task id (for the latter
AbstractTaskGenerator.getNextTaskId()should be used) - set the task id which will be sent next using
setTaskIdToWaitFor(String) - send the task to the system with
sendTaskToSystemAdapter(String, byte[])andAbstractTaskGenerator.sendTaskToEvalStorage(String, long, byte[]) - wait for the acknowledgement using
waitForAck()
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 Summary
FieldsModifier and TypeFieldDescriptionprotected com.rabbitmq.client.ChannelChannel on which the acknowledgments are received.private longTimeout for the acknowledgement.private static final longDefault timeout for the acknowledgement.private static final org.slf4j.Loggerprivate StringId of the task the generator is waiting for an acknowledgement.private SemaphoreSemaphore used to wait for the acknowledgement.Fields inherited from class org.hobbit.core.components.AbstractTaskGenerator
consumer, dataGenReceiver, runFlag, sender2EvalStore, sender2SystemFields inherited from class org.hobbit.core.components.AbstractCommandReceivingComponent
cmdChannel, cmdQueueFactory, cmdResponseTimeout, DEFAULT_CMD_RESPONSE_TIMEOUT, defaultContainerType, gson, reportUnhandledExceptionsFields inherited from class org.hobbit.core.components.AbstractComponent
configuration, connectionFactory, incomingDataQueueFactory, NUMBER_OF_RETRIES_TO_CONNECT_TO_RABBIT_MQ, outgoingDataQueuefactory, rabbitMQHostName, START_WAITING_TIME_BEFORE_RETRY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()protected voidhandleAck(byte[] body) Handles the acknowledgement messages.voidinit()This method initializes the component.protected voidsendTaskToSystemAdapter(String taskIdString, byte[] data) 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.protected booleansendTaskToSystemAdapterInSequence(String taskIdString, byte[] data) 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.voidsetAckTimeout(long ackTimeout) Setter for the maximum time the task generator waits for an acknowledgement.protected voidsetTaskIdToWaitFor(String taskId) Deprecated.private booleanMethod to wait for the acknowledgement of a task with the given Id.Methods inherited from class org.hobbit.core.components.AbstractTaskGenerator
generateTask, getGeneratorId, getNextTaskId, getNumberOfGenerators, receiveCommand, receiveGeneratedData, run, sendTaskToEvalStorageMethods inherited from class org.hobbit.core.components.AbstractPlatformConnectorComponent
addContainerObserver, createContainer, getFactoryForIncomingCmdQueues, getFactoryForIncomingDataQueues, getFactoryForOutgoingCmdQueues, getFactoryForOutgoingDataQueues, stopContainerMethods inherited from class org.hobbit.core.components.AbstractCommandReceivingComponent
addCommandHeaderId, createContainer, createContainer, createContainer, createContainerAsync, createContainerAsync, extendContainerEnvVariables, getCmdResponseTimeout, handleCmd, handleCmd, isReportUnhandledExceptions, reportAndWrap, reportError, reportErrorSavely, reportExceptionSavely, reportUnhandledExceptionSavely, sendToCmdQueue, sendToCmdQueue, sendToCmdQueue, setCmdResponseTimeout, setReportUnhandledExceptionsMethods inherited from class org.hobbit.core.components.AbstractComponent
createConnection, generateSessionQueueName, getConfiguration, getHobbitSessionId, setConfigurationMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.hobbit.core.components.Component
setConfiguration
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
DEFAULT_ACK_TIMEOUT
private static final long DEFAULT_ACK_TIMEOUTDefault timeout for the acknowledgement.- See Also:
-
ackTimeout
private long ackTimeoutTimeout for the acknowledgement. -
seqTaskId
Id of the task the generator is waiting for an acknowledgement. -
taskIdMutex
Semaphore used to wait for the acknowledgement. -
ackChannel
protected com.rabbitmq.client.Channel ackChannelChannel on which the acknowledgments are received.
-
-
Constructor Details
-
AbstractSequencingTaskGenerator
public AbstractSequencingTaskGenerator()
-
-
Method Details
-
init
Description copied from interface:ComponentThis method initializes the component.- Specified by:
initin interfaceComponent- Overrides:
initin classAbstractTaskGenerator- 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
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 happenedsendTaskToSystemAdapterInSequence(String, byte[])should be used.- Overrides:
sendTaskToSystemAdapterin classAbstractTaskGenerator- Parameters:
taskIdString- the id of the taskdata- 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 iddata- the data of the task- Returns:
trueif the acknowledgement has been received,falseif the timeout has been reached or the method has been interrupted.- Throws:
IOException- if there is an error during the sending
-
setTaskIdToWaitFor
Deprecated.It is not necessary anymore since its usage has been integrated into thesendTaskToSystemAdapterInSequence(String, byte[])method.Method to set the task id for which the task generator will wait when callingwaitForAck().- 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:
trueif the acknowledgement has been received,falseif 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
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classAbstractTaskGenerator- Throws:
IOException
-
sendTaskToSystemAdapterInSequence(String, byte[])method.