mirror of https://github.com/apache/activemq.git
Apply patch to work around known race condition. git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1494681 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5415f3a6aa
commit
166ab43c90
|
@ -16,30 +16,27 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.web;
|
package org.apache.activemq.web;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
import javax.jms.Message;
|
import javax.jms.Message;
|
||||||
import javax.jms.MessageConsumer;
|
import javax.jms.MessageConsumer;
|
||||||
|
|
||||||
|
import org.apache.activemq.MessageAvailableListener;
|
||||||
import org.eclipse.jetty.continuation.Continuation;
|
import org.eclipse.jetty.continuation.Continuation;
|
||||||
import org.eclipse.jetty.continuation.ContinuationSupport;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import org.apache.activemq.MessageAvailableListener;
|
|
||||||
|
|
||||||
import java.util.LinkedList;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Listen for available messages and wakeup any continuations.
|
* Listen for available messages and wakeup any continuations.
|
||||||
*/
|
*/
|
||||||
public class AjaxListener implements MessageAvailableListener {
|
public class AjaxListener implements MessageAvailableListener {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(AjaxListener.class);
|
private static final Logger LOG = LoggerFactory.getLogger(AjaxListener.class);
|
||||||
|
|
||||||
private long maximumReadTimeout;
|
private final long maximumReadTimeout;
|
||||||
private AjaxWebClient client;
|
private final AjaxWebClient client;
|
||||||
private long lastAccess;
|
private long lastAccess;
|
||||||
private Continuation continuation;
|
private Continuation continuation;
|
||||||
private LinkedList<UndeliveredAjaxMessage> undeliveredMessages = new LinkedList<UndeliveredAjaxMessage>();
|
private final LinkedList<UndeliveredAjaxMessage> undeliveredMessages = new LinkedList<UndeliveredAjaxMessage>();
|
||||||
|
|
||||||
AjaxListener(AjaxWebClient client, long maximumReadTimeout) {
|
AjaxListener(AjaxWebClient client, long maximumReadTimeout) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
@ -59,6 +56,7 @@ public class AjaxListener implements MessageAvailableListener {
|
||||||
return undeliveredMessages;
|
return undeliveredMessages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public synchronized void onMessageAvailable(MessageConsumer consumer) {
|
public synchronized void onMessageAvailable(MessageConsumer consumer) {
|
||||||
if (LOG.isDebugEnabled()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
LOG.debug("message for " + consumer + " continuation=" + continuation);
|
LOG.debug("message for " + consumer + " continuation=" + continuation);
|
||||||
|
@ -66,15 +64,15 @@ public class AjaxListener implements MessageAvailableListener {
|
||||||
if (continuation != null) {
|
if (continuation != null) {
|
||||||
try {
|
try {
|
||||||
Message message = consumer.receive(10);
|
Message message = consumer.receive(10);
|
||||||
LOG.debug( "message is " + message );
|
LOG.debug("message is " + message);
|
||||||
if( message != null ) {
|
if (message != null) {
|
||||||
if( continuation.isSuspended() ) {
|
if (!continuation.isResumed()) {
|
||||||
LOG.debug( "Resuming suspended continuation " + continuation );
|
LOG.debug("Resuming suspended continuation " + continuation);
|
||||||
continuation.setAttribute("undelivered_message", new UndeliveredAjaxMessage( message, consumer ) );
|
continuation.setAttribute("undelivered_message", new UndeliveredAjaxMessage(message, consumer));
|
||||||
continuation.resume();
|
continuation.resume();
|
||||||
} else {
|
} else {
|
||||||
LOG.debug( "Message available, but continuation is already resumed. Buffer for next time." );
|
LOG.debug("Message available, but continuation is already resumed. Buffer for next time.");
|
||||||
bufferMessageForDelivery( message, consumer );
|
bufferMessageForDelivery(message, consumer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -83,6 +81,7 @@ public class AjaxListener implements MessageAvailableListener {
|
||||||
|
|
||||||
} else if (System.currentTimeMillis() - lastAccess > 2 * this.maximumReadTimeout) {
|
} else if (System.currentTimeMillis() - lastAccess > 2 * this.maximumReadTimeout) {
|
||||||
new Thread() {
|
new Thread() {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
client.closeConsumers();
|
client.closeConsumers();
|
||||||
};
|
};
|
||||||
|
@ -90,17 +89,17 @@ public class AjaxListener implements MessageAvailableListener {
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
Message message = consumer.receive(10);
|
Message message = consumer.receive(10);
|
||||||
bufferMessageForDelivery( message, consumer );
|
bufferMessageForDelivery(message, consumer);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("Error receiving message " + e, e);
|
LOG.error("Error receiving message " + e, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bufferMessageForDelivery( Message message, MessageConsumer consumer ) {
|
public void bufferMessageForDelivery(Message message, MessageConsumer consumer) {
|
||||||
if( message != null ) {
|
if (message != null) {
|
||||||
synchronized( undeliveredMessages ) {
|
synchronized (undeliveredMessages) {
|
||||||
undeliveredMessages.addLast( new UndeliveredAjaxMessage( message, consumer ) );
|
undeliveredMessages.addLast(new UndeliveredAjaxMessage(message, consumer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -381,7 +381,7 @@ public class MessageListenerServlet extends MessageServletSupport {
|
||||||
LinkedList<UndeliveredAjaxMessage> undeliveredMessages = ((AjaxListener)consumer.getAvailableListener()).getUndeliveredMessages();
|
LinkedList<UndeliveredAjaxMessage> undeliveredMessages = ((AjaxListener)consumer.getAvailableListener()).getUndeliveredMessages();
|
||||||
LOG.debug("Send " + undeliveredMessages.size() + " unconsumed messages");
|
LOG.debug("Send " + undeliveredMessages.size() + " unconsumed messages");
|
||||||
synchronized( undeliveredMessages ) {
|
synchronized( undeliveredMessages ) {
|
||||||
for (Iterator<UndeliveredAjaxMessage> it = undeliveredMessages.iterator(); it.hasNext(); ) {
|
for (Iterator<UndeliveredAjaxMessage> it = undeliveredMessages.iterator(); it.hasNext();) {
|
||||||
messages++;
|
messages++;
|
||||||
UndeliveredAjaxMessage undelivered = it.next();
|
UndeliveredAjaxMessage undelivered = it.next();
|
||||||
Message msg = undelivered.getMessage();
|
Message msg = undelivered.getMessage();
|
||||||
|
@ -425,7 +425,6 @@ public class MessageListenerServlet extends MessageServletSupport {
|
||||||
String m = swriter.toString();
|
String m = swriter.toString();
|
||||||
response.getWriter().println(m);
|
response.getWriter().println(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void writeMessageResponse(PrintWriter writer, Message message, String id, String destinationName) throws JMSException, IOException {
|
protected void writeMessageResponse(PrintWriter writer, Message message, String id, String destinationName) throws JMSException, IOException {
|
||||||
|
|
Loading…
Reference in New Issue