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);
}
}
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);
}
}
}
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);
}
}
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);
}
}
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;
}
Aggregations