Class AbstractCommandReceivingComponent

    • 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.
    • Constructor Detail

      • AbstractCommandReceivingComponent

        public AbstractCommandReceivingComponent()
    • Method Detail

      • sendToCmdQueue

        protected void sendToCmdQueue​(byte command)
                               throws IOException
        Sends 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 IOException
        Sends the given command to the command queue with the given data appended.
        Parameters:
        command - the command that should be sent
        data - 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 sent
        data - data that should be appended to the command
        props - 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 a Commands.DOCKER_CONTAINER_START command 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 container
        envVariables - 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 a 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.

        Parameters:
        imageName - the name of the image of the docker container
        containerType - the type of the container
        envVariables - 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 a Commands.DOCKER_CONTAINER_STOP command to stop the container with the given id.
        Parameters:
        containerName - the name of the container instance that should be stopped
      • getCmdResponseTimeout

        public long getCmdResponseTimeout()
        Returns:
        the cmdResponseTimeout
      • setCmdResponseTimeout

        public void setCmdResponseTimeout​(long cmdResponseTimeout)
        Parameters:
        cmdResponseTimeout - the cmdResponseTimeout to set