Package org.hobbit.core.components
Class AbstractCommandReceivingComponent
- java.lang.Object
-
- org.hobbit.core.components.AbstractComponent
-
- org.hobbit.core.components.AbstractCommandReceivingComponent
-
- All Implemented Interfaces:
Closeable,AutoCloseable,CommandReceivingComponent,Component
- Direct Known Subclasses:
AbstractPlatformConnectorComponent
public abstract class AbstractCommandReceivingComponent extends AbstractComponent implements CommandReceivingComponent
-
-
Field Summary
Fields Modifier and Type Field Description private Set<String>acceptedCmdHeaderIdsSet of command headers that are expected by this component.protected com.rabbitmq.client.ChannelcmdChannelChannel that is used for the command queue.protected RabbitQueueFactorycmdQueueFactoryFactory for generating queues with which the commands are sent and received.protected longcmdResponseTimeoutTime the component waits for a response of the platform controller.private StringcontainerNameName of this Docker container.static longDEFAULT_CMD_RESPONSE_TIMEOUTprotected StringdefaultContainerTypeDefault type of containers created by this containerprivate com.google.gson.GsongsonThreadsafe JSON parser.private static org.slf4j.LoggerLOGGERprivate com.rabbitmq.client.QueueingConsumerresponseConsumerConsumer of the queue that is used to receive responses for messages that are sent via the command queue and for which an answer is expected.private StringresponseQueueNameName of the queue that is used to receive responses for messages that are sent via the command queue and for which an answer is expected.-
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 AbstractCommandReceivingComponent()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddCommandHeaderId(String sessionId)Adds the given session id to the set of ids this component is reacting to.voidclose()protected StringcreateContainer(String imageName, String[] envVariables)This method sends aCommands.DOCKER_CONTAINER_STARTcommand to create and start an instance of the given image using the given environment variables.protected StringcreateContainer(String imageName, String containerType, String[] envVariables)This method sends aCommands.DOCKER_CONTAINER_STARTcommand to create and start an instance of the given image using the given environment variables.longgetCmdResponseTimeout()protected voidhandleCmd(byte[] bytes, String replyTo)voidinit()This method initializes the component.private voidinitResponseQueue()Internal method for initializing theresponseQueueNameand theresponseConsumerif they haven't been initialized before.protected voidsendToCmdQueue(byte command)Sends the given command to the command queue.protected voidsendToCmdQueue(byte command, byte[] data)Sends the given command to the command queue with the given data appended.protected voidsendToCmdQueue(byte command, byte[] data, com.rabbitmq.client.AMQP.BasicProperties props)Sends the given command to the command queue with the given data appended and using the given properties.voidsetCmdResponseTimeout(long cmdResponseTimeout)protected voidstopContainer(String containerName)This method sends aCommands.DOCKER_CONTAINER_STOPcommand to stop the container with the given id.-
Methods inherited from class org.hobbit.core.components.AbstractComponent
createConnection, generateSessionQueueName, getHobbitSessionId
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.hobbit.core.components.CommandReceivingComponent
receiveCommand
-
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
DEFAULT_CMD_RESPONSE_TIMEOUT
public static final long DEFAULT_CMD_RESPONSE_TIMEOUT
- See Also:
- Constant Field Values
-
containerName
private String containerName
Name of this Docker container.
-
responseQueueName
private String responseQueueName
Name of the queue that is used to receive responses for messages that are sent via the command queue and for which an answer is expected.
-
responseConsumer
private com.rabbitmq.client.QueueingConsumer responseConsumer
Consumer of the queue that is used to receive responses for messages that are sent via the command queue and for which an answer is expected.
-
cmdQueueFactory
protected RabbitQueueFactory cmdQueueFactory
Factory for generating queues with which the commands are sent and received. It is separated from the data connections since otherwise the component can get stuck waiting for a command while the connection is busy handling incoming or outgoing data.
-
cmdChannel
protected com.rabbitmq.client.Channel cmdChannel
Channel that is used for the command queue.
-
defaultContainerType
protected String defaultContainerType
Default type of containers created by this container
-
acceptedCmdHeaderIds
private Set<String> acceptedCmdHeaderIds
Set of command headers that are expected by this component.
-
gson
private com.google.gson.Gson gson
Threadsafe JSON parser.
-
cmdResponseTimeout
protected long cmdResponseTimeout
Time the component waits for a response of the platform controller.
-
-
Method Detail
-
init
public void init() throws ExceptionDescription copied from interface:ComponentThis method initializes the component.- Specified by:
initin interfaceComponent- Overrides:
initin classAbstractComponent- Throws:
Exception- if an error occurs during the initialization
-
sendToCmdQueue
protected void sendToCmdQueue(byte command) throws IOExceptionSends the given command to the command queue.- Parameters:
command- the command that should be sent- Throws:
IOException- if a communication problem occurs
-
sendToCmdQueue
protected void sendToCmdQueue(byte command, byte[] data) throws IOExceptionSends the given command to the command queue with the given data appended.- Parameters:
command- the command that should be sentdata- data that should be appended to the command- Throws:
IOException- if a communication problem occurs
-
sendToCmdQueue
protected void sendToCmdQueue(byte command, byte[] data, com.rabbitmq.client.AMQP.BasicProperties props) throws IOExceptionSends the given command to the command queue with the given data appended and using the given properties.- Parameters:
command- the command that should be sentdata- data that should be appended to the commandprops- properties that should be used for the message- Throws:
IOException- if a communication problem occurs
-
addCommandHeaderId
protected void addCommandHeaderId(String sessionId)
Adds the given session id to the set of ids this component is reacting to.- Parameters:
sessionId- session id that should be added to the set of accepted ids.
-
handleCmd
protected void handleCmd(byte[] bytes, String replyTo)
-
createContainer
protected String createContainer(String imageName, String[] envVariables)
This method sends aCommands.DOCKER_CONTAINER_STARTcommand to create and start an instance of the given image using the given environment variables.- Parameters:
imageName- the name of the image of the docker containerenvVariables- environment variables that should be added to the created container- Returns:
- the name of the container instance or null if an error occurred
-
createContainer
protected String createContainer(String imageName, String containerType, String[] envVariables)
This method sends aCommands.DOCKER_CONTAINER_STARTcommand to create and start an instance of the given image using the given environment variables.Note that the containerType parameter should have one of the following values.
Constants.CONTAINER_TYPE_BENCHMARKif this container is part of a benchmark.Constants.CONTAINER_TYPE_DATABASEif this container is part of a benchmark but should be located on a storage node.Constants.CONTAINER_TYPE_SYSTEMif this container is part of a benchmarked system.
- Parameters:
imageName- the name of the image of the docker containercontainerType- the type of the containerenvVariables- environment variables that should be added to the created container- Returns:
- the name of the container instance or null if an error occurred
-
stopContainer
protected void stopContainer(String containerName)
This method sends aCommands.DOCKER_CONTAINER_STOPcommand to stop the container with the given id.- Parameters:
containerName- the name of the container instance that should be stopped
-
initResponseQueue
private void initResponseQueue() throws IOExceptionInternal method for initializing theresponseQueueNameand theresponseConsumerif they haven't been initialized before.- Throws:
IOException- if a communication problem occurs
-
getCmdResponseTimeout
public long getCmdResponseTimeout()
- Returns:
- the cmdResponseTimeout
-
setCmdResponseTimeout
public void setCmdResponseTimeout(long cmdResponseTimeout)
- Parameters:
cmdResponseTimeout- the cmdResponseTimeout to set
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classAbstractComponent- Throws:
IOException
-
-