use of com.swiftmq.jms.QueueImpl in project swiftmq-ce by iitsoftware.
the class MessageInterfaceListener method run.
public void run() {
try {
pullTransaction.commit();
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/run, exception committing tx: " + e + ", exiting");
return;
}
try {
MessageImpl request = entry.getMessage();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/run, new message: " + request);
String result = null;
boolean showCommands = !request.propertyExists(PROP_SHOW_CMD_RESULT) || request.getBooleanProperty(PROP_SHOW_CMD_RESULT);
if (request instanceof TextMessageImpl)
result = executeCommands(((TextMessageImpl) request).getText(), showCommands);
else
result = "Invalid message type (" + request.getClass().getName() + "). Expect TextMessage!";
QueueImpl queue = getReplyQueue(request);
if (queue != null)
sendReply(queue, request, result);
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/run, exception during processing: " + e);
ctx.logSwiftlet.logError(ctx.mgmtSwiftlet.getName(), toString() + "/run, exception during processing: " + e);
}
if (closed)
return;
try {
pullTransaction = receiver.createTransaction(false);
pullTransaction.registerMessageProcessor(this);
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/run, exception creating new tx: " + e + ", exiting");
return;
}
}
use of com.swiftmq.jms.QueueImpl in project swiftmq-ce by iitsoftware.
the class NontransactedQueueSession method visitCreateConsumerRequest.
public void visitCreateConsumerRequest(CreateConsumerRequest req) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitCreateConsumerRequest");
CreateConsumerReply reply = (CreateConsumerReply) req.createReply();
try {
ctx.activeLogin.getResourceLimitGroup().incConsumers();
} catch (ResourceLimitException e) {
reply.setOk(false);
reply.setException(new JMSException(e.toString()));
reply.send();
return;
}
QueueImpl queue = req.getQueue();
String messageSelector = req.getMessageSelector();
String queueName = null;
try {
queueName = queue.getQueueName();
} catch (JMSException ignored) {
}
try {
if (!queueName.endsWith('@' + SwiftletManager.getInstance().getRouterName()))
throw new InvalidDestinationException("Queue '" + queueName + "' is not local! Can't create a Consumer on it!");
int consumerId = 0;
QueueConsumer consumer = null;
consumerId = ArrayListTool.setFirstFreeOrExpand(consumerList, null);
consumer = new QueueConsumer(ctx, queueName, messageSelector);
consumerList.set(consumerId, consumer);
consumer.createReadTransaction();
consumer.createTransaction();
reply.setOk(true);
reply.setQueueConsumerId(consumerId);
if (receiverEntityList != null) {
Entity consEntity = receiverEntityList.createEntity();
consEntity.setName(queueName + "-" + consumerId);
consEntity.setDynamicObject(consumer);
consEntity.createCommands();
Property prop = consEntity.getProperty("queue");
prop.setValue(queueName);
prop.setReadOnly(true);
prop = consEntity.getProperty("selector");
if (messageSelector != null) {
prop.setValue(messageSelector);
}
prop.setReadOnly(true);
receiverEntityList.addEntity(consEntity);
}
} catch (InvalidSelectorException e) {
ctx.activeLogin.getResourceLimitGroup().decConsumers();
ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/CreateConsumer has invalid Selector: " + e);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/CreateConsumer has invalid Selector: " + e);
reply.setOk(false);
reply.setException(e);
} catch (Exception e1) {
ctx.activeLogin.getResourceLimitGroup().decConsumers();
ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/Exception during create consumer: " + e1);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/Exception during create consumer: " + e1);
reply.setOk(false);
reply.setException((e1 instanceof JMSException) ? e1 : new javax.jms.JMSException(e1.toString()));
}
reply.send();
}
use of com.swiftmq.jms.QueueImpl in project swiftmq-ce by iitsoftware.
the class TransactedQueueSession method visitCommitRequest.
public void visitCommitRequest(CommitRequest req) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitCommitRequest");
CommitReply reply = (CommitReply) req.createReply();
reply.setOk(true);
try {
// first: produce all messages
Object[] wrapper = req.getMessages();
ctx.incMsgsSent(wrapper.length);
req.setMessages(null);
long fcDelay = 0;
RingBuffer tempProducers = null;
for (int i = 0; i < wrapper.length; i++) {
DataByteArrayInputStream dis = new DataByteArrayInputStream((byte[]) wrapper[i]);
int producerId = dis.readInt();
int type = dis.readInt();
MessageImpl msg = MessageImpl.createInstance(type);
msg.readContent(dis);
dis.close();
Producer producer = null;
if (producerId == -1) {
String queueName = ((QueueImpl) msg.getJMSDestination()).getQueueName();
if (!ctx.queueManager.isQueueRunning(queueName))
throw new InvalidDestinationException("Invalid destination: " + queueName);
producer = new QueueProducer(ctx, queueName);
if (tempProducers == null)
tempProducers = new RingBuffer(8);
tempProducers.add(producer);
transactionManager.addTransactionFactory(producer);
} else {
producer = (Producer) producerList.get(producerId);
}
QueuePushTransaction transaction = (QueuePushTransaction) producer.getTransaction();
transaction.putMessage(msg);
fcDelay = Math.max(fcDelay, transaction.getFlowControlDelay());
if (producerId == -1)
producer.markForClose();
}
// Next: do the commit
transactionManager.commit();
if (tempProducers != null) {
int size = tempProducers.getSize();
for (int i = 0; i < size; i++) {
((Producer) tempProducers.remove()).close();
}
}
reply.setDelay(fcDelay);
purgeMarkedProducers();
purgeMarkedConsumers();
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/commit produced messages failed: " + e.getMessage());
reply.setOk(false);
reply.setException((e instanceof JMSException) ? e : new javax.jms.JMSException(e.toString()));
}
reply.send();
}
use of com.swiftmq.jms.QueueImpl in project swiftmq-ce by iitsoftware.
the class TransactedQueueSession method visitCreateConsumerRequest.
public void visitCreateConsumerRequest(CreateConsumerRequest req) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitCreateConsumerRequest");
CreateConsumerReply reply = (CreateConsumerReply) req.createReply();
try {
ctx.activeLogin.getResourceLimitGroup().incConsumers();
} catch (ResourceLimitException e) {
reply.setOk(false);
reply.setException(new JMSException(e.toString()));
reply.send();
return;
}
QueueImpl queue = req.getQueue();
String messageSelector = req.getMessageSelector();
String queueName = null;
try {
queueName = queue.getQueueName();
} catch (JMSException ignored) {
}
try {
if (!queueName.endsWith('@' + SwiftletManager.getInstance().getRouterName()))
throw new InvalidDestinationException("Queue '" + queueName + "' is not local! Can't create a Consumer on it!");
int consumerId = 0;
QueueConsumer consumer = null;
consumerId = ArrayListTool.setFirstFreeOrExpand(consumerList, null);
consumer = new QueueConsumer(ctx, queueName, messageSelector);
consumerList.set(consumerId, consumer);
reply.setOk(true);
reply.setQueueConsumerId(consumerId);
if (receiverEntityList != null) {
Entity consEntity = receiverEntityList.createEntity();
consEntity.setName(queueName + "-" + consumerId);
consEntity.setDynamicObject(consumer);
consEntity.createCommands();
Property prop = consEntity.getProperty("queue");
prop.setValue(queueName);
prop.setReadOnly(true);
prop = consEntity.getProperty("selector");
if (messageSelector != null) {
prop.setValue(messageSelector);
}
prop.setReadOnly(true);
receiverEntityList.addEntity(consEntity);
}
consumer.createReadTransaction();
// enlist it at the transaction manager
transactionManager.addTransactionFactory(consumer);
} catch (InvalidSelectorException e) {
ctx.activeLogin.getResourceLimitGroup().decConsumers();
ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/CreateConsumer has invalid Selector: " + e);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/CreateConsumer has invalid Selector: " + e);
reply.setOk(false);
reply.setException(e);
} catch (Exception e1) {
ctx.activeLogin.getResourceLimitGroup().decConsumers();
ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/Exception during create consumer: " + e1);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/Exception during create consumer: " + e1);
reply.setOk(false);
reply.setException((e1 instanceof JMSException) ? e1 : new javax.jms.JMSException(e1.toString()));
}
reply.send();
}
use of com.swiftmq.jms.QueueImpl in project swiftmq-ce by iitsoftware.
the class TransactedQueueSession method visitCreateProducerRequest.
public void visitCreateProducerRequest(CreateProducerRequest req) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitCreateProducerRequest");
CreateProducerReply reply = (CreateProducerReply) req.createReply();
try {
ctx.activeLogin.getResourceLimitGroup().incProducers();
} catch (ResourceLimitException e) {
reply.setOk(false);
reply.setException(new JMSException(e.toString()));
reply.send();
return;
}
QueueImpl queue = req.getQueue();
try {
int producerId;
QueueProducer producer;
producerId = ArrayListTool.setFirstFreeOrExpand(producerList, null);
producer = new QueueProducer(ctx, queue.getQueueName());
producerList.set(producerId, producer);
reply.setQueueProducerId(producerId);
reply.setOk(true);
if (senderEntityList != null) {
Entity senderEntity = senderEntityList.createEntity();
senderEntity.setName(queue.getQueueName() + "-" + producerId);
senderEntity.setDynamicObject(producer);
senderEntity.createCommands();
Property prop = senderEntity.getProperty("queue");
prop.setValue(queue.getQueueName());
prop.setReadOnly(true);
senderEntityList.addEntity(senderEntity);
}
// enlist it at the transaction manager
transactionManager.addTransactionFactory(producer);
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/exception creating producer: " + e.getMessage());
ctx.logSwiftlet.logError("sys$jms", ctx.tracePrefix + "/exception creating producer: " + e.getMessage());
reply.setOk(false);
reply.setException((e instanceof JMSException) ? e : new javax.jms.JMSException(e.toString()));
ctx.activeLogin.getResourceLimitGroup().decProducers();
}
reply.send();
}
Aggregations