use of com.swiftmq.jms.MessageImpl 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");
}
boolean wasDuplicate = false;
boolean wasInvalidConnectionId = false;
MessageImpl msg = null;
String id = null;
long to = timeout;
do {
wasDuplicate = false;
wasInvalidConnectionId = false;
if (!consumerStarted)
fillCache();
do {
if (messageCache.getSize() == 0) {
if (block) {
receiverWaiting = true;
if (timeout == 0) {
UninterruptableWaiter.doWait(this);
if (cancelled)
return null;
} else {
long startWait = System.currentTimeMillis();
UninterruptableWaiter.doWait(this, to);
to -= System.currentTimeMillis() - startWait;
if (to <= 0)
return null;
}
} else {
if (fillCachePending && receiveNoWaitFirstCall) {
UninterruptableWaiter.doWait(this, 1000);
}
}
}
} while (mySession.resetInProgress);
receiverWaiting = false;
if (messageCache.getSize() == 0 || isClosed())
return null;
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() }, "receiveMessage, invalid connectionId (" + request.getConnectionId() + " vs " + mySession.myConnection.getConnectionId() + ")");
}
wasInvalidConnectionId = true;
} else {
MessageEntry messageEntry = request.getMessageEntry();
msg = messageEntry.getMessage();
messageEntry.moveMessageAttributes();
msg.setMessageConsumerImpl(this);
msg.reset();
msg.setReadOnly(true);
msg.setUseThreadContextCL(useThreadContextCL);
if (request.isRequiresRestart())
fillCache();
if (recordLog) {
id = SessionImpl.buildId(uniqueConsumerId, msg);
wasDuplicate = mySession.myConnection.isDuplicateMessageDetection() && mySession.isDuplicate(id);
}
if (MessageTracker.enabled) {
MessageTracker.getInstance().track(msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "receivedMessage, duplicate=" + wasDuplicate);
}
if (reportDelivered)
reportDelivered(msg, false);
if (doAck) {
try {
if (MessageTracker.enabled) {
MessageTracker.getInstance().track(msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "receivedMessage, ack...");
}
boolean cancelled = acknowledgeMessage(msg.getMessageIndex(), false);
if (MessageTracker.enabled) {
MessageTracker.getInstance().track(msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "receivedMessage, ack, cancelled=" + cancelled);
}
} catch (JMSException e) {
}
}
if (wasDuplicate) {
msg = null;
}
}
} while (wasDuplicate || wasInvalidConnectionId);
if (recordLog && mySession.myConnection.isDuplicateMessageDetection())
mySession.addCurrentTxLog(id);
return msg;
}
use of com.swiftmq.jms.MessageImpl 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.jms.MessageImpl in project swiftmq-ce by iitsoftware.
the class StreamLibDeployer method sendReply.
private void sendReply(QueueImpl replyTo, boolean rc) throws JMSException {
QueueSender sender = ctx.queueManager.createQueueSender(replyTo.getQueueName(), (ActiveLogin) null);
QueuePushTransaction pushTx = sender.createTransaction();
MessageImpl reply = new MessageImpl();
reply.setBooleanProperty("success", rc);
reply.setJMSDestination(replyTo);
pushTx.putMessage(reply);
pushTx.commit();
sender.close();
}
use of com.swiftmq.jms.MessageImpl in project swiftmq-ce by iitsoftware.
the class QueueWireTapInput method start.
@Override
public void start() throws Exception {
if (selector != null) {
messageSelector = new MessageSelector(selector);
messageSelector.compile();
}
queue = new ArrayBlockingQueue<MessageImpl>(bufferSize);
AbstractQueue queue = ctx.ctx.queueManager.getQueueForInternalUse(destinationName);
if (queue == null)
throw new Exception("Queue '" + destinationName + "' is undefined!");
queue.addWireTapSubscriber(name, this);
started = true;
}
use of com.swiftmq.jms.MessageImpl in project swiftmq-ce by iitsoftware.
the class QueueMemory method reload.
@Override
public void reload() throws Exception {
List content = getContent();
for (int i = 0; i < content.size(); i++) {
MessageIndex messageIndex = (MessageIndex) content.get(i);
MessageImpl message = abstractQueue.getMessageByIndex(messageIndex).getMessage();
if (!shared || message.propertyExists(KEY) && message.getStringProperty(KEY).equals(name)) {
String key = message.getJMSMessageID();
long storeTime = message.getJMSTimestamp();
messageStore.add(key, new KeyEntry(key, messageIndex, storeTime));
addToIndexes(key, ctx.messageBuilder.wrap(message));
}
}
}
Aggregations