use of com.swiftmq.swiftlet.queue.MessageIndex in project swiftmq-client by iitsoftware.
the class MessageDeliveredRequest method readContent.
public void readContent(DataInput in) throws IOException {
super.readContent(in);
queueConsumerId = in.readInt();
byte set = in.readByte();
if (set == 0) {
messageIndex = null;
} else {
messageIndex = new MessageIndex();
messageIndex.readContent(in);
}
}
use of com.swiftmq.swiftlet.queue.MessageIndex in project swiftmq-client by iitsoftware.
the class MessageConsumerImpl method reportDelivered.
private void reportDelivered(Message message, boolean duplicate) {
try {
MessageIndex messageIndex = ((MessageImpl) message).getMessageIndex();
requestRegistry.request(new MessageDeliveredRequest(this, mySession.dispatchId, serverQueueConsumerId, messageIndex, duplicate));
} catch (Exception e) {
}
}
use of com.swiftmq.swiftlet.queue.MessageIndex in project swiftmq-client by iitsoftware.
the class MessageConsumerImpl method invokeMessageListener.
private void invokeMessageListener() {
if (isClosed())
return;
AsyncMessageDeliveryRequest request = (AsyncMessageDeliveryRequest) messageCache.remove();
if (request.getConnectionId() != mySession.myConnection.getConnectionId()) {
if (MessageTracker.enabled) {
MessageTracker.getInstance().track(request.getMessageEntry().getMessage(), new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "invokeMessageListener, invalid connectionId (" + request.getConnectionId() + " vs " + mySession.myConnection.getConnectionId() + ")");
}
return;
}
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);
String id = null;
boolean duplicate = false;
if (recordLog) {
id = SessionImpl.buildId(uniqueConsumerId, msg);
duplicate = mySession.myConnection.isDuplicateMessageDetection() && mySession.isDuplicate(id);
}
if (MessageTracker.enabled) {
MessageTracker.getInstance().track(msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "invokeMessageListener, duplicate=" + duplicate);
}
if (reportDelivered)
reportDelivered(msg, false);
try {
if (!duplicate) {
if (recordLog && mySession.myConnection.isDuplicateMessageDetection())
mySession.addCurrentTxLog(id);
if (MessageTracker.enabled) {
MessageTracker.getInstance().track(msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "invokeMessageListener, onMessage...");
}
mySession.withinOnMessage = true;
mySession.setTxCancelled(false);
messageListener.onMessage(msg);
mySession.withinOnMessage = false;
if (MessageTracker.enabled) {
MessageTracker.getInstance().track(msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "invokeMessageListener, onMessage ok");
}
if (mySession.isTxCancelled() || mySession.acknowledgeMode == Session.CLIENT_ACKNOWLEDGE && msg.isCancelled()) {
if (MessageTracker.enabled) {
MessageTracker.getInstance().track(msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "tx was cancelled, return!");
}
wasRecovered = false;
return;
}
}
} catch (RuntimeException e) {
if (MessageTracker.enabled) {
MessageTracker.getInstance().track(msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "invokeMessageListener, exception=" + 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 {
if (MessageTracker.enabled) {
MessageTracker.getInstance().track(msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "invokeMessageListener, ack");
}
boolean cancelled = acknowledgeMessage(msgIndex, false);
if (MessageTracker.enabled) {
MessageTracker.getInstance().track(msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "invokeMessageListener, ack, cancelled=" + cancelled);
}
} catch (JMSException e) {
}
}
} else
wasRecovered = false;
}
use of com.swiftmq.swiftlet.queue.MessageIndex 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.MessageIndex in project swiftmq-client by iitsoftware.
the class AcknowledgeMessageRequest method readContent.
public void readContent(DataInput in) throws IOException {
super.readContent(in);
queueConsumerId = in.readInt();
byte set = in.readByte();
if (set == 0) {
messageIndex = null;
} else {
messageIndex = new MessageIndex();
messageIndex.readContent(in);
}
}
Aggregations