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
FieldsModifier and TypeFieldDescriptionSet of command headers that are expected by this component.protected com.rabbitmq.client.ChannelChannel that is used for the command queue.protected RabbitQueueFactoryFactory for generating queues with which the commands are sent and received.protected longTime the component waits for a response of the platform controller.private ExecutorServiceprivate StringName of this Docker container.static final longprotected StringDefault type of containers created by this containerprivate booleanprotected com.google.gson.GsonThreadsafe JSON parser.private static final org.slf4j.Loggerprotected booleanFlag that is used to control whether thereportUnhandledExceptionSavely(Exception)method should report exceptions or not.private com.rabbitmq.client.ConsumerConsumer 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.Mapping of RabbitMQ's correlationIDs to Future objects corresponding to that RPC call.private StringName 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
configuration, connectionFactory, incomingDataQueueFactory, NUMBER_OF_RETRIES_TO_CONNECT_TO_RABBIT_MQ, outgoingDataQueuefactory, rabbitMQHostName, START_WAITING_TIME_BEFORE_RETRY -
Constructor Summary
ConstructorsConstructorDescriptionConstructor.AbstractCommandReceivingComponent(boolean execCommandsInParallel) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected 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.protected StringcreateContainer(String imageName, String containerType, String[] envVariables, String[] netAliases) This method sends aCommands.DOCKER_CONTAINER_STARTcommand to create and start an instance of the given image using the given environment variables.createContainerAsync(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.createContainerAsync(String imageName, String containerType, String[] envVariables, String[] netAliases) This method sends aCommands.DOCKER_CONTAINER_STARTcommand to create and start an instance of the given image using the given environment variables.protected String[]extendContainerEnvVariables(String[] envVariables) This method extends (if needed) the array of environment variables for the container with HOBBIT specific variables.longprotected voidhandleCmd(byte[] bytes, com.rabbitmq.client.AMQP.BasicProperties props) This method is called if a message is received from the command queue.protected voidThis method is called if a message is received from the command queue.voidinit()This method initializes the component.private voidInternal method for initializing theresponseQueueNameand theresponseConsumerif they haven't been initialized before.booleanReport the given unhandled exception usingreportUnhandledExceptionSavely(Exception)and return a new instance ofReportedExceptionthat can be thrown.voidreportError(ErrorData error) This method sends the given error report on the command queue.voidreportErrorSavely(ErrorData error) This method sends the given error report on the command queue without throwing an exception.voidThis method sends a report about the given exception.voidThis method sends a report about the given unhandled exception using thereportExceptionSavely(Exception)method unless the flagreportUnhandledExceptionsis set tofalse.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) voidsetReportUnhandledExceptions(boolean reportUnhandledExceptions) 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, 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.CommandReceivingComponent
receiveCommandMethods inherited from interface org.hobbit.core.components.Component
run, setConfiguration
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
DEFAULT_CMD_RESPONSE_TIMEOUT
public static final long DEFAULT_CMD_RESPONSE_TIMEOUT- See Also:
-
containerName
Name of this Docker container. -
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. -
responseFutures
Mapping of RabbitMQ's correlationIDs to Future objects corresponding to that RPC call. -
responseConsumer
private com.rabbitmq.client.Consumer responseConsumerConsumer 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
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 cmdChannelChannel that is used for the command queue. -
defaultContainerType
Default type of containers created by this container -
acceptedCmdHeaderIds
Set of command headers that are expected by this component. -
gson
protected com.google.gson.Gson gsonThreadsafe JSON parser. -
cmdResponseTimeout
protected long cmdResponseTimeoutTime the component waits for a response of the platform controller. -
cmdThreadPool
-
errorLogged
private boolean errorLogged -
reportUnhandledExceptions
protected boolean reportUnhandledExceptionsFlag that is used to control whether thereportUnhandledExceptionSavely(Exception)method should report exceptions or not. It can be set to false to provide better, more detailed reports while skipping the general reporting of unhandled exceptions.
-
-
Constructor Details
-
AbstractCommandReceivingComponent
public AbstractCommandReceivingComponent()Constructor. -
AbstractCommandReceivingComponent
public AbstractCommandReceivingComponent(boolean execCommandsInParallel) Constructor.- Parameters:
execCommandsInParallel- flag allowing the processing of commands in parallel
-
-
Method Details
-
init
Description 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
Sends the given command to the command queue.- Parameters:
command- the command that should be sent- Throws:
IOException- if a communication problem occurs
-
sendToCmdQueue
Sends 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 IOException Sends 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
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, com.rabbitmq.client.AMQP.BasicProperties props) This method is called if a message is received from the command queue.- Parameters:
bytes- data from the RabbitMQ messageprops- properties of the RabbitMQ message
-
handleCmd
This method is called if a message is received from the command queue.- Parameters:
bytes- data from the RabbitMQ messagereplyTo- name of the queue in which response is expected
-
createContainer
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
-
extendContainerEnvVariables
This method extends (if needed) the array of environment variables for the container with HOBBIT specific variables.- Parameters:
envVariables- user-provided array of environment variables- Returns:
- the extended array of environment variables
-
createContainer
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
-
createContainer
protected String createContainer(String imageName, String containerType, String[] envVariables, String[] netAliases) 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 containernetAliases- network aliases that should be added to the created container- Returns:
- the name of the container instance or null if an error occurred
-
createContainerAsync
protected Future<String> createContainerAsync(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 Future object with the name of the container instance or null if an error occurred
-
createContainerAsync
protected Future<String> createContainerAsync(String imageName, String containerType, String[] envVariables, String[] netAliases) 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 containernetAliases- network aliases that should be added to the created container- Returns:
- the Future object with the name of the container instance or null if an error occurred
-
stopContainer
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
Internal 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
-
reportError
This method sends the given error report on the command queue.- Parameters:
error- the data of the error that should be reported- Throws:
IOException- if sending the report fails
-
reportErrorSavely
This method sends the given error report on the command queue without throwing an exception. This can be helpful in situations, in which the reported error may lead to a crash of the system and the reporting mechanism itself may not work anymore.- Parameters:
error- the data of the error that should be reported
-
reportExceptionSavely
This method sends a report about the given exception. The container name is derived from the configuration and the error report is generated based on the data provided by the exception. Note that instances ofReportedExceptionare not reported.- Parameters:
e- the severe exception that should be reported as error
-
reportUnhandledExceptionSavely
This method sends a report about the given unhandled exception using thereportExceptionSavely(Exception)method unless the flagreportUnhandledExceptionsis set tofalse.- Parameters:
e- the severe exception that should be reported as error
-
reportAndWrap
Report the given unhandled exception usingreportUnhandledExceptionSavely(Exception)and return a new instance ofReportedExceptionthat can be thrown.- Parameters:
e- the severe exception that should be reported as error- Returns:
- the new exception instance that can be thrown
-
isReportUnhandledExceptions
public boolean isReportUnhandledExceptions()- Returns:
- the reportUnhandledExceptions
-
setReportUnhandledExceptions
public void setReportUnhandledExceptions(boolean reportUnhandledExceptions) - Parameters:
reportUnhandledExceptions- the reportUnhandledExceptions to set
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classAbstractComponent- Throws:
IOException
-