Search in sources :

Example 11 with DistributedTestException

use of org.apache.qpid.disttest.DistributedTestException in project qpid-broker-j by apache.

the class ClientJmsDelegate method setInstructionListener.

public void setInstructionListener(final Client client) {
    try {
        _instructionQueue = _instructionListenerSession.createTemporaryQueue();
        final MessageConsumer instructionConsumer = _instructionListenerSession.createConsumer(_instructionQueue);
        instructionConsumer.setMessageListener(new MessageListener() {

            @Override
            public void onMessage(final Message message) {
                client.processInstruction(JmsMessageAdaptor.messageToCommand(message));
            }
        });
    } catch (final JMSException jmse) {
        throw new DistributedTestException("Unable to setup instruction listener", jmse);
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) DistributedTestException(org.apache.qpid.disttest.DistributedTestException) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) MessageListener(javax.jms.MessageListener) JMSException(javax.jms.JMSException)

Example 12 with DistributedTestException

use of org.apache.qpid.disttest.DistributedTestException in project qpid-broker-j by apache.

the class ClientJmsDelegate method sendRegistrationMessage.

public void sendRegistrationMessage() {
    Command command;
    try {
        command = new RegisterClientCommand(_clientName, _instructionQueue.getQueueName());
    } catch (final JMSException e) {
        throw new DistributedTestException(e);
    }
    sendCommand(command);
}
Also used : DistributedTestException(org.apache.qpid.disttest.DistributedTestException) RegisterClientCommand(org.apache.qpid.disttest.message.RegisterClientCommand) CreateProducerCommand(org.apache.qpid.disttest.message.CreateProducerCommand) RegisterClientCommand(org.apache.qpid.disttest.message.RegisterClientCommand) CreateSessionCommand(org.apache.qpid.disttest.message.CreateSessionCommand) CreateConsumerCommand(org.apache.qpid.disttest.message.CreateConsumerCommand) CreateMessageProviderCommand(org.apache.qpid.disttest.message.CreateMessageProviderCommand) Command(org.apache.qpid.disttest.message.Command) CreateConnectionCommand(org.apache.qpid.disttest.message.CreateConnectionCommand) JMSException(javax.jms.JMSException)

Example 13 with DistributedTestException

use of org.apache.qpid.disttest.DistributedTestException in project qpid-broker-j by apache.

the class ClientJmsDelegate method destroy.

/**
 * destroy the client. Don't call from the Dispatcher thread.
 */
public void destroy() {
    try {
        // Stopping the connection allows in-flight onMessage calls to
        // finish.
        _controllerConnection.stop();
        if (_instructionListenerSession != null) {
            _instructionListenerSession.close();
        }
        if (_controllerSession != null) {
            _controllerSession.close();
        }
        _controllerConnection.close();
    } catch (final JMSException jmse) {
        throw new DistributedTestException("Unable to destroy cleanly", jmse);
    }
}
Also used : DistributedTestException(org.apache.qpid.disttest.DistributedTestException) JMSException(javax.jms.JMSException)

Example 14 with DistributedTestException

use of org.apache.qpid.disttest.DistributedTestException in project qpid-broker-j by apache.

the class ClientJmsDelegate method consumeMessage.

public Message consumeMessage(String consumerName, long receiveInterval) {
    Message consumedMessage = null;
    MessageConsumer consumer = _testConsumers.get(consumerName);
    try {
        consumedMessage = consumer.receive(receiveInterval);
    } catch (JMSException e) {
        throw new DistributedTestException("Unable to consume message with consumer: " + consumerName, e);
    }
    return consumedMessage;
}
Also used : MessageConsumer(javax.jms.MessageConsumer) DistributedTestException(org.apache.qpid.disttest.DistributedTestException) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) JMSException(javax.jms.JMSException)

Example 15 with DistributedTestException

use of org.apache.qpid.disttest.DistributedTestException in project qpid-broker-j by apache.

the class ClientJmsDelegate method createSession.

public void createSession(final CreateSessionCommand command) {
    try {
        final Connection connection = _testConnections.get(command.getConnectionName());
        if (connection == null) {
            throw new DistributedTestException("No test connection found called: " + command.getConnectionName(), command);
        }
        final boolean transacted = command.getAcknowledgeMode() == Session.SESSION_TRANSACTED;
        final Session newSession = connection.createSession(transacted, command.getAcknowledgeMode());
        LOGGER.debug("Created session {} with transacted = {} and acknowledgeMode = {}", command.getSessionName(), newSession.getTransacted(), newSession.getAcknowledgeMode());
        addSession(command.getSessionName(), newSession);
        _testSessionToConnections.put(newSession, connection);
    } catch (final JMSException jmse) {
        throw new DistributedTestException("Unable to create new session: " + command, jmse);
    }
}
Also used : DistributedTestException(org.apache.qpid.disttest.DistributedTestException) Connection(javax.jms.Connection) JMSException(javax.jms.JMSException) Session(javax.jms.Session)

Aggregations

DistributedTestException (org.apache.qpid.disttest.DistributedTestException)25 JMSException (javax.jms.JMSException)18 Message (javax.jms.Message)7 MessageConsumer (javax.jms.MessageConsumer)5 Session (javax.jms.Session)5 IOException (java.io.IOException)4 TextMessage (javax.jms.TextMessage)4 Connection (javax.jms.Connection)3 Destination (javax.jms.Destination)3 MessageProducer (javax.jms.MessageProducer)3 Command (org.apache.qpid.disttest.message.Command)3 MessageListener (javax.jms.MessageListener)2 NamingException (javax.naming.NamingException)2 JsonHandler (org.apache.qpid.disttest.json.JsonHandler)2 CreateProducerCommand (org.apache.qpid.disttest.message.CreateProducerCommand)2 RegisterClientCommand (org.apache.qpid.disttest.message.RegisterClientCommand)2 Test (org.junit.Test)2 IntrospectionException (java.beans.IntrospectionException)1 File (java.io.File)1 FileReader (java.io.FileReader)1