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();
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.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 = SessionImpl.buildId(uniqueConsumerId, msg);
boolean duplicate = false;
if (recordLog)
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-client by iitsoftware.
the class MessageConsumerImpl method reportDelivered.
private void reportDelivered(Message message) {
try {
MessageIndex messageIndex = ((MessageImpl) message).getMessageIndex();
requestRegistry.request(new MessageDeliveredRequest(dispatchId, serverQueueConsumerId, messageIndex));
} catch (Exception e) {
}
}
use of com.swiftmq.swiftlet.queue.MessageIndex in project swiftmq-ce by iitsoftware.
the class Remover method execute.
public String[] execute(String[] context, Entity entity, String[] cmd) {
if (cmd.length < 3 || cmd.length > 5)
return new String[] { TreeCommands.ERROR, "Invalid command, please try '" + PATTERN + "'" };
String[] result = null;
try {
if (!ctx.queueManager.isQueueDefined(cmd[1]))
throw new Exception("Unknown queue: " + cmd[1]);
AbstractQueue aq = (AbstractQueue) ctx.queueManager.getQueueForInternalUse(cmd[1]);
if (!(aq instanceof MessageQueue))
throw new Exception("Operation not supported on this type of queue!");
MessageQueue mq = (MessageQueue) aq;
SortedSet content = mq.getQueueIndex();
if (cmd[2].equals("-index")) {
if (cmd.length != 5)
return new String[] { TreeCommands.ERROR, "Invalid command, please try 'remove <queue> -index <start> <stop>'" };
int start = Integer.parseInt(cmd[3]);
int stop = Integer.parseInt(cmd[4]);
if (stop < start)
throw new Exception("Stop index is less than start index.");
int i = 0, cnt = 0;
for (Iterator iter = content.iterator(); iter.hasNext(); ) {
MessageIndex mi = (MessageIndex) iter.next();
if (i >= start && i <= stop) {
try {
mq.removeMessageByIndex(mi);
cnt++;
} catch (MessageLockedException ignored) {
}
}
if (i > stop)
break;
i++;
}
return new String[] { TreeCommands.INFO, cnt + " messages removed." };
} else {
String key = cmd[2];
int id = -1;
if (!key.equals("*"))
id = Integer.parseInt(key);
boolean found = false;
for (Iterator iter = content.iterator(); iter.hasNext(); ) {
MessageIndex mi = (MessageIndex) iter.next();
if (id == -1 || mi.getId() == id) {
found = true;
mq.removeMessageByIndex(mi);
if (id != -1)
break;
}
}
if (!found && id != -1)
throw new Exception("Message key '" + id + "' not found!");
}
} catch (Exception e) {
result = new String[] { TreeCommands.ERROR, e.getMessage() };
}
return result;
}
use of com.swiftmq.swiftlet.queue.MessageIndex in project swiftmq-ce by iitsoftware.
the class SessionHandler method createDeliveryTag.
private DeliveryTag createDeliveryTag(Delivery delivery) throws IOException {
// Need to create a copy of the MessageIndex without the delivery count; otherwise it won't match on redeliveries
MessageIndex messageIndex = delivery.getMessageIndex();
MessageIndex deliveryTag = new MessageIndex(messageIndex.getId(), messageIndex.getPriority(), 0);
deliveryTag.setTxId(0);
dtagStream.rewind();
deliveryTag.writeContent(dtagStream);
byte[] b = new byte[dtagStream.getCount()];
System.arraycopy(dtagStream.getBuffer(), 0, b, 0, b.length);
return new DeliveryTag(b);
}
Aggregations