public abstract class AbstractCommandReceivingComponent extends AbstractComponent implements CommandReceivingComponent
| Modifier and Type | Field and Description |
|---|---|
private Set<String> |
acceptedCmdHeaderIds
Set of command headers that are expected by this component.
|
protected com.rabbitmq.client.Channel |
cmdChannel
Channel that is used for the command queue.
|
protected RabbitQueueFactory |
cmdQueueFactory
Factory for generating queues with which the commands are sent and
received.
|
private String |
containerName
Name of this Docker container.
|
static long |
DEFAULT_CMD_RESPONSE_TIMEOUT |
protected String |
defaultContainerType
Default type of containers created by this container
|
private com.google.gson.Gson |
gson
Threadsafe JSON parser.
|
private static org.slf4j.Logger |
LOGGER |
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.
|
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.
|
connectionFactory, incomingDataQueueFactory, NUMBER_OF_RETRIES_TO_CONNECT_TO_RABBIT_MQ, outgoingDataQueuefactory, rabbitMQHostName, START_WAITING_TIME_BEFORE_RETRY| Constructor and Description |
|---|
AbstractCommandReceivingComponent() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addCommandHeaderId(String sessionId)
Adds the given session id to the set of ids this component is reacting
to.
|
void |
close() |
protected String |
createContainer(String imageName,
String[] envVariables)
This method sends a
Commands.DOCKER_CONTAINER_START command to
create and start an instance of the given image using the given
environment variables. |
protected String |
createContainer(String imageName,
String containerType,
String[] envVariables)
This method sends a
Commands.DOCKER_CONTAINER_START command to
create and start an instance of the given image using the given
environment variables. |
protected void |
handleCmd(byte[] bytes,
String replyTo) |
void |
init()
This method initializes the component.
|
private void |
initResponseQueue()
Internal method for initializing the
responseQueueName and the
responseConsumer if they haven't been initialized before. |
protected void |
sendToCmdQueue(byte command)
Sends the given command to the command queue.
|
protected void |
sendToCmdQueue(byte command,
byte[] data)
Sends the given command to the command queue with the given data
appended.
|
protected void |
sendToCmdQueue(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.
|
protected void |
stopContainer(String containerName)
This method sends a
Commands.DOCKER_CONTAINER_STOP command to
stop the container with the given id. |
createConnection, generateSessionQueueName, getHobbitSessionIdclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitreceiveCommandprivate static final org.slf4j.Logger LOGGER
public static final long DEFAULT_CMD_RESPONSE_TIMEOUT
private String containerName
private String responseQueueName
private com.rabbitmq.client.QueueingConsumer responseConsumer
protected RabbitQueueFactory cmdQueueFactory
protected com.rabbitmq.client.Channel cmdChannel
protected String defaultContainerType
private Set<String> acceptedCmdHeaderIds
private com.google.gson.Gson gson
public void init()
throws Exception
Componentinit in interface Componentinit in class AbstractComponentException - if an error occurs during the initializationprotected void sendToCmdQueue(byte command)
throws IOException
command - the command that should be sentIOException - if a communication problem occursprotected void sendToCmdQueue(byte command,
byte[] data)
throws IOException
command - the command that should be sentdata - data that should be appended to the commandIOException - if a communication problem occursprotected void sendToCmdQueue(byte command,
byte[] data,
com.rabbitmq.client.AMQP.BasicProperties props)
throws IOException
command - the command that should be sentdata - data that should be appended to the commandprops - properties that should be used for the messageIOException - if a communication problem occursprotected void addCommandHeaderId(String sessionId)
sessionId - session id that should be added to the set of accepted ids.protected void handleCmd(byte[] bytes,
String replyTo)
protected String createContainer(String imageName, String[] envVariables)
Commands.DOCKER_CONTAINER_START command to
create and start an instance of the given image using the given
environment variables.imageName - the name of the image of the docker containerenvVariables - environment variables that should be added to the created
containerprotected String createContainer(String imageName, String containerType, String[] envVariables)
Commands.DOCKER_CONTAINER_START command 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_BENCHMARK if this container is part
of a benchmark.Constants.CONTAINER_TYPE_DATABASE if this container is part
of a benchmark but should be located on a storage node.Constants.CONTAINER_TYPE_SYSTEM if this container is part of
a benchmarked system.imageName - the name of the image of the docker containercontainerType - the type of the containerenvVariables - environment variables that should be added to the created
containerprotected void stopContainer(String containerName)
Commands.DOCKER_CONTAINER_STOP command to
stop the container with the given id.containerName - the name of the container instance that should be stoppedprivate void initResponseQueue()
throws IOException
responseQueueName and the
responseConsumer if they haven't been initialized before.IOException - if a communication problem occurspublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class AbstractComponentIOExceptionCopyright © 2017–2018. All rights reserved.