use of com.swiftmq.jms.MessageImpl in project swiftmq-ce by iitsoftware.
the class NontransactedQueueSession method visit.
public void visit(ProduceMessageRequest req) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitProduceMessageRequest");
ctx.incMsgsSent(1);
ProduceMessageReply reply = null;
if (req.isReplyRequired())
reply = (ProduceMessageReply) req.createReply();
int producerId = req.getQueueProducerId();
Producer producer = null;
try {
MessageImpl msg = SMQPUtil.getMessage(req);
long ttl = msg.getJMSExpiration();
if (ttl > 0)
msg.setJMSExpiration(System.currentTimeMillis() + ttl);
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);
} else {
producer = (Producer) producerList.get(producerId);
}
QueuePushTransaction transaction = (QueuePushTransaction) producer.createTransaction();
transaction.putMessage(msg);
transaction.commit();
if (req.isReplyRequired()) {
reply.setDelay(transaction.getFlowControlDelay());
reply.setOk(true);
}
if (producerId == -1)
producer.close();
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/produce messages failed: " + e.getMessage());
if (req.isReplyRequired()) {
reply.setOk(false);
reply.setException(e);
}
}
if (req.isReplyRequired())
reply.send();
}
use of com.swiftmq.jms.MessageImpl in project swiftmq-client by iitsoftware.
the class WireTap method copyMessage.
private MessageImpl copyMessage(MessageImpl msg) {
try {
DataByteArrayOutputStream dbos = new DataByteArrayOutputStream();
DataByteArrayInputStream dbis = new DataByteArrayInputStream();
msg.writeContent(dbos);
dbis.reset();
dbis.setBuffer(dbos.getBuffer(), 0, dbos.getCount());
MessageImpl msgCopy = MessageImpl.createInstance(dbis.readInt());
msgCopy.readContent(dbis);
return msgCopy;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
use of com.swiftmq.jms.MessageImpl 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.MessageImpl in project swiftmq-ce by iitsoftware.
the class SessionStore method remove.
public synchronized void remove(String clientid) throws Exception {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", remove, clientid=" + clientid);
QueueReceiver receiver = ctx.queueManager.createQueueReceiver(STORE_QUEUE, null, null);
QueuePullTransaction t = receiver.createTransaction(false);
MessageEntry entry = null;
while ((entry = t.getMessage(0)) != null) {
MessageImpl msg = entry.getMessage();
String cid = msg.getStringProperty(PROP_CLIENTID);
if (cid.equals(clientid)) {
QueuePullTransaction t2 = receiver.createTransaction(false);
t2.moveToTransaction(entry.getMessageIndex(), t);
t2.commit();
break;
}
}
t.rollback();
receiver.close();
}
use of com.swiftmq.jms.MessageImpl in project swiftmq-client by iitsoftware.
the class MessageConsumerImpl method invokeMessageListener.
private void invokeMessageListener() {
if (isClosed())
return;
AsyncMessageDeliveryRequest request = (AsyncMessageDeliveryRequest) messageCache.remove();
MessageEntry messageEntry = request.getMessageEntry();
MessageImpl msg = messageEntry.getMessage();
messageEntry.moveMessageAttributes();
MessageIndex msgIndex = msg.getMessageIndex();
msg.setMessageConsumerImpl(this);
try {
msg.reset();
} catch (JMSException e) {
e.printStackTrace();
}
msg.setReadOnly(true);
msg.setUseThreadContextCL(useThreadContextCL);
if (reportDelivered)
reportDelivered(msg);
try {
messageListener.onMessage(msg);
} catch (RuntimeException e) {
System.err.println("ERROR! MessageListener throws RuntimeException, shutting down consumer!");
e.printStackTrace();
try {
close(e.toString());
} catch (JMSException e1) {
}
return;
}
if (!wasRecovered) {
if (request.isRequiresRestart())
fillCache();
if (doAck) {
try {
acknowledgeMessage(msgIndex, false);
} catch (JMSException e) {
}
}
} else
wasRecovered = false;
}
Aggregations