Commit f63f81f9 authored by afreyssin's avatar afreyssin

Receive code from helper.

parent 1d11ab94
......@@ -26,6 +26,7 @@ import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import javax.jms.JMSConsumer;
import javax.jms.JMSContext;
import javax.jms.JMSException;
import javax.jms.Message;
......@@ -65,7 +66,7 @@ public class ConsumerContext extends SessionContext {
return -1;
}
public void put(long id, Message msg) {
private final void put(long id, Message msg) {
if (msg == null)
return;
if (id > getLastId())
......@@ -74,9 +75,39 @@ public class ConsumerContext extends SessionContext {
}
public Message getMessage(long id) {
getClientCtx().setLastActivity(System.currentTimeMillis());
return messages.get(id);
}
synchronized Message receive(long timeout, long msgId) throws JMSException {
Message message = null;
if (timeout > 0)
message = getConsumer().receive(timeout);
else if (timeout == 0)
message = getConsumer().receiveNoWait();
else {
message = getConsumer().receive();
if (message == null)
throw new JMSException("The consumer expire (timeout)");
}
//update activity
getClientCtx().setLastActivity(System.currentTimeMillis());
if (message != null) {
if (getJmsContext().getSessionMode() == JMSContext.CLIENT_ACKNOWLEDGE) {
long id = msgId;
if (id == -1)
id = incLastId();
put(id, message);
} else {
incLastId();
}
}
return message;
}
public Message removeMessage(long id) {
return messages.remove(id);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment