use of com.swiftmq.swiftlet.queue.QueuePullTransaction in project swiftmq-ce by iitsoftware.
the class NontransactedSession method visit.
public void visit(AcknowledgeMessageRequest req) {
if (closed)
return;
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitAcknowledgeMessageRequest");
AcknowledgeMessageReply reply = null;
if (req.isReplyRequired()) {
reply = (AcknowledgeMessageReply) req.createReply();
reply.setOk(true);
}
try {
MessageIndex ackIndex = req.getMessageIndex();
if (ctx.ackMode == javax.jms.Session.CLIENT_ACKNOWLEDGE) {
boolean found = false;
Iterator iter = deliveredList.iterator();
while (iter.hasNext()) {
MessageDeliveredRequest request = (MessageDeliveredRequest) iter.next();
Consumer consumer = (Consumer) consumerList.get(request.getQueueConsumerId());
MessageIndex actIndex = request.getMessageIndex();
QueuePullTransaction t = consumer.getTransaction();
try {
if (!t.isClosed())
t.acknowledgeMessage(actIndex);
} catch (Exception e) {
// temp queue might be deleted in the mean time
}
iter.remove();
}
} else {
Consumer consumer = (Consumer) consumerList.get(req.getQueueConsumerId());
QueuePullTransaction t = consumer.getReadTransaction();
try {
if (!t.isClosed())
t.acknowledgeMessage(ackIndex);
} catch (Exception e) {
// temp queue might be deleted in the mean time
}
}
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitAcknowledgeMessageRequest, exception: " + e);
if (reply != null) {
reply.setOk(false);
reply.setException(e);
}
}
if (reply != null)
reply.send();
}
use of com.swiftmq.swiftlet.queue.QueuePullTransaction in project swiftmq-ce by iitsoftware.
the class Session method visitMessageDeliveredRequest.
public void visitMessageDeliveredRequest(MessageDeliveredRequest req) {
if (closed || recoveryInProgress)
return;
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitMessageDeliveredRequest");
try {
Consumer consumer = (Consumer) consumerList.get(req.getQueueConsumerId());
QueuePullTransaction rt = (QueuePullTransaction) consumer.getReadTransaction();
QueuePullTransaction t = (QueuePullTransaction) consumer.getTransaction();
t.moveToTransaction(req.getMessageIndex(), rt);
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitMessageDeliveredRequest, exception=" + e);
e.printStackTrace();
}
}
use of com.swiftmq.swiftlet.queue.QueuePullTransaction in project swiftmq-ce by iitsoftware.
the class Exporter method execute.
public String[] execute(String[] context, Entity entity, String[] cmd) {
if (cmd.length < 3)
return new String[] { TreeCommands.ERROR, "Invalid command, please try '" + TreeCommands.EXPORT + " <queuename> <localdir> [-remove] [-xml] [-selector <selector>]" };
int nMsgs = 0;
try {
String queueName = cmd[1];
String localDir = cmd[2];
boolean delete = false;
boolean xml = false;
String selector = null;
if (cmd.length > 3) {
StringBuffer selBuffer = null;
for (int i = 3; i < cmd.length; i++) {
if (selBuffer != null) {
if (selBuffer.length() > 0)
selBuffer.append(' ');
selBuffer.append(cmd[i]);
} else if (cmd[i].equals("-delete"))
delete = true;
else if (cmd[i].equals("-xml"))
xml = true;
else if (cmd[i].equals("-selector"))
selBuffer = new StringBuffer();
else
throw new Exception("Invalid option: " + cmd[i]);
}
if (selBuffer != null)
selector = selBuffer.toString();
}
XStream xStream = null;
File outputDir = new File(localDir);
if (!outputDir.exists()) {
if (!outputDir.mkdir())
throw new Exception("Unable to create output directory: " + localDir);
}
if (xml) {
xStream = new XStream(new Dom4JDriver());
xStream.allowTypesByWildcard(new String[] { ".*" });
}
MessageSelector msel = null;
if (selector != null) {
msel = new MessageSelector(selector);
msel.compile();
}
QueueReceiver receiver = ctx.queueManager.createQueueReceiver(queueName, null, msel);
QueuePullTransaction pullTx = receiver.createTransaction(false);
try {
MessageEntry entry = null;
while ((entry = pullTx.getMessage(0, msel)) != null) {
MessageImpl msg = delete ? entry.getMessage() : copyMessage(entry.getMessage());
msg.clearSwiftMQAllProps();
store(queueName, xStream, outputDir, nMsgs++, msg);
if (delete) {
pullTx.commit();
pullTx = receiver.createTransaction(false);
}
}
} finally {
try {
pullTx.rollback();
} catch (Exception e) {
}
try {
receiver.close();
} catch (Exception e) {
}
}
} catch (Exception e) {
return new String[] { TreeCommands.ERROR, e.getMessage() };
}
return new String[] { TreeCommands.INFO, nMsgs + " messages exported." };
}
use of com.swiftmq.swiftlet.queue.QueuePullTransaction in project swiftmq-ce by iitsoftware.
the class Subscription method processMessage.
@Override
public void processMessage(MessageEntry messageEntry) {
try {
QueuePullTransaction tx = consumer.createTransaction();
tx.moveToTransaction(messageEntry.getMessageIndex(), readTx);
String jmsTopicName = ((TopicImpl) messageEntry.getMessage().getJMSDestination()).getTopicName();
MqttQoS mqos = MqttQoS.valueOf(qos.value());
if (messageEntry.getMessage().propertyExists(Producer.PROP_QOS)) {
int pqos = messageEntry.getMessage().getIntProperty(Producer.PROP_QOS);
int sqos = qos.value();
if (sqos > pqos)
mqos = MqttQoS.valueOf(pqos);
}
session.getMqttConnection().getConnectionQueue().enqueue(new POSendMessage(jmsTopicName, messageEntry.getMessage(), mqos, tx, this));
incMsgsReceived(1);
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.swiftmq.swiftlet.queue.QueuePullTransaction in project swiftmq-ce by iitsoftware.
the class Session method visit.
public void visit(MessageDeliveredRequest req) {
if (closed || recoveryInProgress)
return;
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitMessageDeliveredRequest");
try {
Consumer consumer = (Consumer) consumerList.get(req.getQueueConsumerId());
QueuePullTransaction rt = (QueuePullTransaction) consumer.getReadTransaction();
// Duplicates are immediately deleted
if (req.isDuplicate()) {
QueuePullTransaction t = (QueuePullTransaction) consumer.createDuplicateTransaction();
t.moveToTransaction(req.getMessageIndex(), rt);
t.commit();
} else {
QueuePullTransaction t = (QueuePullTransaction) consumer.getTransaction();
t.moveToTransaction(req.getMessageIndex(), rt);
}
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitMessageDeliveredRequest, exception=" + e);
}
}
Aggregations