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
public abstract class AbstractSequencingTaskGenerator extends AbstractTaskGenerator
Extension of theAbstractTaskGeneratorthat 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
Fields Modifier and Type Field Description protected com.rabbitmq.client.ChannelackChannelChannel on which the acknowledgments are received.private longackTimeoutTimeout for the acknowledgement.private static longDEFAULT_ACK_TIMEOUTDefault timeout for the acknowledgement.private static org.slf4j.LoggerLOGGERprivate StringseqTaskIdId of the task the generator is waiting for an acknowledgement.private SemaphoretaskIdMutexSemaphore used to wait for the acknowledgement.-
Fields inherited from class org.hobbit.core.components.AbstractTaskGenerator
consumer, dataGenReceiver, runFlag, sender2EvalStore, sender2System
-
Fields inherited from class org.hobbit.core.components.AbstractCommandReceivingComponent
cmdChannel, cmdQueueFactory, cmdResponseTimeout, DEFAULT_CMD_RESPONSE_TIMEOUT, defaultContainerType
-
Fields inherited from class org.hobbit.core.components.AbstractComponent
connectionFactory, incomingDataQueueFactory, NUMBER_OF_RETRIES_TO_CONNECT_TO_RABBIT_MQ, outgoingDataQueuefactory, rabbitMQHostName, START_WAITING_TIME_BEFORE_RETRY
-
-
Constructor Summary
Constructors Constructor Description AbstractSequencingTaskGenerator()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclose()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.It is not necessary anymore since its usage has been integrated into thesendTaskToSystemAdapterInSequence(String, byte[])method.private booleanwaitForAck()Method 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, sendTaskToEvalStorage
-
Methods inherited from class org.hobbit.core.components.AbstractPlatformConnectorComponent
addContainerObserver, createContainer, getFactoryForIncomingCmdQueues, getFactoryForIncomingDataQueues, getFactoryForOutgoingCmdQueues, getFactoryForOutgoingDataQueues, stopContainer
-
Methods inherited from class org.hobbit.core.components.AbstractCommandReceivingComponent
addCommandHeaderId, createContainer, createContainer, getCmdResponseTimeout, handleCmd, sendToCmdQueue, sendToCmdQueue, sendToCmdQueue, setCmdResponseTimeout
-
Methods inherited from class org.hobbit.core.components.AbstractComponent
createConnection, generateSessionQueueName, getHobbitSessionId
-
-
-
-
Field Detail
-
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:
- Constant Field Values
-
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.
-
-
Method Detail
-
init
public void init() throws ExceptionDescription 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
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 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 protected void setTaskIdToWaitFor(String taskId)
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
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classAbstractTaskGenerator- Throws:
IOException
-
-