use of com.swiftmq.swiftlet.queue.MessageEntry in project swiftmq-ce by iitsoftware.
the class BrowserManager method fetchBrowserMessage.
public void fetchBrowserMessage(FetchBrowserMessageRequest request) {
FetchBrowserMessageReply reply = (FetchBrowserMessageReply) request.createReply();
int browserId = request.getQueueBrowserId();
try {
com.swiftmq.swiftlet.queue.QueueBrowser browser = (com.swiftmq.swiftlet.queue.QueueBrowser) queueBrowsers.get(browserId);
if (request.isResetRequired())
browser.resetBrowser();
browser.setLastMessageIndex(request.getLastMessageIndex());
MessageEntry me = (MessageEntry) browser.getNextMessage();
reply.setOk(true);
reply.setMessageEntry(me);
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + ": get next message failed: " + e.getMessage());
reply.setOk(false);
reply.setException(e);
}
reply.send();
}
use of com.swiftmq.swiftlet.queue.MessageEntry in project swiftmq-client by iitsoftware.
the class AsyncMessageDeliveryRequest method readContent.
public void readContent(DataInput in) throws IOException {
super.readContent(in);
listenerId = in.readInt();
sessionDispatchId = in.readInt();
recoveryEpoche = in.readInt();
requiresRestart = in.readBoolean();
byte set = in.readByte();
if (set == 0) {
messageEntry = null;
} else {
messageEntry = new MessageEntry();
messageEntry.readContent(in);
}
set = in.readByte();
if (set == 0) {
bulk = null;
} else {
bulk = new MessageEntry[in.readInt()];
for (int i = 0; i < bulk.length; i++) {
MessageEntry entry = new MessageEntry();
entry.readContent(in);
bulk[i] = entry;
}
}
}
use of com.swiftmq.swiftlet.queue.MessageEntry 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;
}
use of com.swiftmq.swiftlet.queue.MessageEntry in project swiftmq-client by iitsoftware.
the class MessageConsumerImpl method receiveMessage.
synchronized Message receiveMessage(boolean block, long timeout) throws JMSException {
verifyState();
if (messageListener != null) {
throw new JMSException("receive not allowed while a message listener has been set");
}
try {
if (!consumerStarted)
fillCache();
if (messageCache.getSize() == 0) {
if (block) {
receiverWaiting = true;
if (timeout == 0)
wait();
else
wait(timeout);
} else {
if (fillCachePending && receiveNoWaitFirstCall) {
wait(1000);
}
}
}
} catch (InterruptedException e) {
}
receiverWaiting = false;
if (messageCache.getSize() == 0 || isClosed())
return null;
AsyncMessageDeliveryRequest request = (AsyncMessageDeliveryRequest) messageCache.remove();
MessageEntry messageEntry = request.getMessageEntry();
MessageImpl msg = messageEntry.getMessage();
messageEntry.moveMessageAttributes();
msg.setMessageConsumerImpl(this);
msg.reset();
msg.setReadOnly(true);
msg.setUseThreadContextCL(useThreadContextCL);
if (request.isRequiresRestart())
fillCache();
if (reportDelivered)
reportDelivered(msg);
if (doAck) {
try {
acknowledgeMessage(msg.getMessageIndex(), false);
} catch (JMSException e) {
}
}
return msg;
}
use of com.swiftmq.swiftlet.queue.MessageEntry 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