Search in sources :

Example 16 with DistributedTestException

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

the class ClientJmsDelegate method createConsumer.

public void createConsumer(final CreateConsumerCommand command) {
    try {
        final Session session = _testSessions.get(command.getSessionName());
        if (session == null) {
            throw new DistributedTestException("No test session found called: " + command.getSessionName(), command);
        }
        synchronized (session) {
            Destination destination;
            MessageConsumer jmsConsumer;
            if (command.isTopic()) {
                Topic topic = session.createTopic(command.getDestinationName());
                if (command.isDurableSubscription()) {
                    String subscription = "subscription-" + command.getParticipantName() + System.currentTimeMillis();
                    jmsConsumer = session.createDurableSubscriber(topic, subscription);
                    addSubscription(subscription, session);
                    LOGGER.debug("created durable subscription " + subscription + " to topic " + topic);
                } else {
                    jmsConsumer = session.createConsumer(topic, command.getSelector());
                }
                destination = topic;
            } else {
                destination = session.createQueue(command.getDestinationName());
                jmsConsumer = session.createConsumer(destination, command.getSelector());
            }
            addConsumer(command.getParticipantName(), jmsConsumer);
        }
    } catch (final JMSException jmse) {
        throw new DistributedTestException("Unable to create new consumer: " + command, jmse);
    }
}
Also used : Destination(javax.jms.Destination) DistributedTestException(org.apache.qpid.disttest.DistributedTestException) MessageConsumer(javax.jms.MessageConsumer) JMSException(javax.jms.JMSException) Topic(javax.jms.Topic) Session(javax.jms.Session)

Example 17 with DistributedTestException

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

the class ClientJmsDelegate method closeTestConsumer.

public void closeTestConsumer(String consumerName) {
    MessageConsumer consumer = _testConsumers.get(consumerName);
    if (consumer != null) {
        try {
            consumer.close();
            LOGGER.debug("Closed test consumer " + consumerName);
        } catch (JMSException e) {
            throw new DistributedTestException("Failed to close consumer: " + consumerName, e);
        }
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) DistributedTestException(org.apache.qpid.disttest.DistributedTestException) JMSException(javax.jms.JMSException)

Example 18 with DistributedTestException

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

the class ClientJmsDelegate method createProducer.

public void createProducer(final CreateProducerCommand command) {
    try {
        final Session session = _testSessions.get(command.getSessionName());
        if (session == null) {
            throw new DistributedTestException("No test session found called: " + command.getSessionName(), command);
        }
        synchronized (session) {
            final Destination destination;
            if (command.isTopic()) {
                destination = session.createTopic(command.getDestinationName());
            } else {
                destination = session.createQueue(command.getDestinationName());
            }
            final MessageProducer jmsProducer = session.createProducer(destination);
            if (command.getPriority() != -1) {
                jmsProducer.setPriority(command.getPriority());
            }
            if (command.getTimeToLive() > 0) {
                jmsProducer.setTimeToLive(command.getTimeToLive());
            }
            if (command.getDeliveryMode() == DeliveryMode.NON_PERSISTENT || command.getDeliveryMode() == DeliveryMode.PERSISTENT) {
                jmsProducer.setDeliveryMode(command.getDeliveryMode());
            }
            addProducer(command.getParticipantName(), jmsProducer);
        }
    } catch (final JMSException jmse) {
        throw new DistributedTestException("Unable to create new producer: " + command, jmse);
    }
}
Also used : Destination(javax.jms.Destination) DistributedTestException(org.apache.qpid.disttest.DistributedTestException) JMSException(javax.jms.JMSException) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session)

Example 19 with DistributedTestException

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

the class ClientJmsDelegate method sendNextMessage.

public Message sendNextMessage(final CreateProducerCommand command) {
    final String messageProviderName = command.getMessageProviderName();
    final MessageProvider messageProvider = getMessageProvider(messageProviderName);
    final Session session = _testSessions.get(command.getSessionName());
    final MessageProducer producer = _testProducers.get(command.getParticipantName());
    try {
        Message message = messageProvider.nextMessage(session, command);
        int deliveryMode = producer.getDeliveryMode();
        int priority = producer.getPriority();
        long ttl = producer.getTimeToLive();
        if (messageProvider.isPropertySet(MessageProvider.PRIORITY)) {
            priority = message.getJMSPriority();
        }
        if (messageProvider.isPropertySet(MessageProvider.DELIVERY_MODE)) {
            deliveryMode = message.getJMSDeliveryMode();
        }
        if (messageProvider.isPropertySet(MessageProvider.TTL)) {
            ttl = message.getLongProperty(MessageProvider.TTL);
        }
        producer.send(message, deliveryMode, priority, ttl);
        return message;
    } catch (final JMSException jmse) {
        throw new DistributedTestException("Unable to create and send message with producer: " + command.getParticipantName() + " on session: " + command.getSessionName(), jmse);
    }
}
Also used : DistributedTestException(org.apache.qpid.disttest.DistributedTestException) MessageProvider(org.apache.qpid.disttest.client.MessageProvider) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) JMSException(javax.jms.JMSException) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session)

Example 20 with DistributedTestException

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

the class MessageProvider method getMessagePayload.

protected String getMessagePayload(final CreateProducerCommand command) {
    FutureTask<String> createTextFuture = new FutureTask<String>(new Callable<String>() {

        @Override
        public String call() throws Exception {
            final int messageSize = command.getMessageSize();
            char[] chars = new char[messageSize];
            Arrays.fill(chars, 'a');
            return new String(chars);
        }
    });
    Future<String> future = _payloads.putIfAbsent(command.getMessageSize(), createTextFuture);
    if (future == null) {
        createTextFuture.run();
        future = createTextFuture;
    }
    String payload = null;
    try {
        payload = future.get();
    } catch (Exception e) {
        throw new DistributedTestException("Unable to create message payload :" + e.getMessage(), e);
    }
    return payload;
}
Also used : DistributedTestException(org.apache.qpid.disttest.DistributedTestException) FutureTask(java.util.concurrent.FutureTask) JMSException(javax.jms.JMSException) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DistributedTestException(org.apache.qpid.disttest.DistributedTestException)

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