ARTEMIS-934 Stomp Heart beat not being stopped in some cases
(cherry picked from commit f79b21e866
)
This commit is contained in:
parent
0e7fde72fb
commit
a8a0c186d1
|
@ -107,6 +107,10 @@ public final class StompConnection implements RemotingConnection {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public VersionedStompFrameHandler getStompVersionHandler() {
|
||||||
|
return frameHandler;
|
||||||
|
}
|
||||||
|
|
||||||
public StompFrame decode(ActiveMQBuffer buffer) throws ActiveMQStompException {
|
public StompFrame decode(ActiveMQBuffer buffer) throws ActiveMQStompException {
|
||||||
StompFrame frame = null;
|
StompFrame frame = null;
|
||||||
try {
|
try {
|
||||||
|
@ -315,6 +319,11 @@ public final class StompConnection implements RemotingConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
ActiveMQServerLogger.LOGGER.connectionFailureDetected(me.getMessage(), me.getType());
|
ActiveMQServerLogger.LOGGER.connectionFailureDetected(me.getMessage(), me.getType());
|
||||||
|
|
||||||
|
if (frameHandler != null) {
|
||||||
|
frameHandler.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
// Then call the listeners
|
// Then call the listeners
|
||||||
callFailureListeners(me);
|
callFailureListeners(me);
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,9 @@ public abstract class VersionedStompFrameHandler {
|
||||||
protected final ScheduledExecutorService scheduledExecutorService;
|
protected final ScheduledExecutorService scheduledExecutorService;
|
||||||
protected final ExecutorFactory executorFactory;
|
protected final ExecutorFactory executorFactory;
|
||||||
|
|
||||||
|
protected void disconnect() {
|
||||||
|
}
|
||||||
|
|
||||||
public static VersionedStompFrameHandler getHandler(StompConnection connection,
|
public static VersionedStompFrameHandler getHandler(StompConnection connection,
|
||||||
StompVersions version,
|
StompVersions version,
|
||||||
ScheduledExecutorService scheduledExecutorService,
|
ScheduledExecutorService scheduledExecutorService,
|
||||||
|
|
|
@ -57,6 +57,10 @@ public class StompFrameHandlerV11 extends VersionedStompFrameHandler implements
|
||||||
decoder.init();
|
decoder.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ActiveMQScheduledComponent getHeartBeater() {
|
||||||
|
return heartBeater;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StompFrame onConnect(StompFrame frame) {
|
public StompFrame onConnect(StompFrame frame) {
|
||||||
StompFrame response = null;
|
StompFrame response = null;
|
||||||
|
@ -131,15 +135,22 @@ public class StompFrameHandlerV11 extends VersionedStompFrameHandler implements
|
||||||
//client receive ping
|
//client receive ping
|
||||||
long minAcceptInterval = Long.valueOf(params[1]);
|
long minAcceptInterval = Long.valueOf(params[1]);
|
||||||
|
|
||||||
heartBeater = new HeartBeater(scheduledExecutorService, executorFactory.getExecutor(), minPingInterval, minAcceptInterval);
|
if (heartBeater == null) {
|
||||||
|
heartBeater = new HeartBeater(scheduledExecutorService, executorFactory.getExecutor(), minPingInterval, minAcceptInterval);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StompFrame onDisconnect(StompFrame frame) {
|
public StompFrame onDisconnect(StompFrame frame) {
|
||||||
|
disconnect();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void disconnect() {
|
||||||
if (this.heartBeater != null) {
|
if (this.heartBeater != null) {
|
||||||
heartBeater.shutdown();
|
heartBeater.shutdown();
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -62,7 +62,8 @@ public abstract class AbstractStompClientConnection implements StompClientConnec
|
||||||
protected BlockingQueue<ClientStompFrame> frameQueue = new LinkedBlockingQueue<>();
|
protected BlockingQueue<ClientStompFrame> frameQueue = new LinkedBlockingQueue<>();
|
||||||
|
|
||||||
protected boolean connected = false;
|
protected boolean connected = false;
|
||||||
private int serverPingCounter;
|
protected int serverPingCounter;
|
||||||
|
protected ReaderThread readerThread;
|
||||||
|
|
||||||
public AbstractStompClientConnection(String version, String host, int port) throws IOException {
|
public AbstractStompClientConnection(String version, String host, int port) throws IOException {
|
||||||
this.version = version;
|
this.version = version;
|
||||||
|
@ -85,7 +86,13 @@ public abstract class AbstractStompClientConnection implements StompClientConnec
|
||||||
readBuffer = ByteBuffer.allocateDirect(10240);
|
readBuffer = ByteBuffer.allocateDirect(10240);
|
||||||
receiveList = new ArrayList<>(10240);
|
receiveList = new ArrayList<>(10240);
|
||||||
|
|
||||||
new ReaderThread().start();
|
readerThread = new ReaderThread();
|
||||||
|
readerThread.start();
|
||||||
|
//new ReaderThread().start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void killReaderThread() {
|
||||||
|
readerThread.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -32,12 +32,16 @@ import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.activemq.artemis.api.core.SimpleString;
|
import org.apache.activemq.artemis.api.core.SimpleString;
|
||||||
import org.apache.activemq.artemis.core.protocol.stomp.Stomp;
|
import org.apache.activemq.artemis.core.protocol.stomp.Stomp;
|
||||||
|
import org.apache.activemq.artemis.core.protocol.stomp.StompConnection;
|
||||||
|
import org.apache.activemq.artemis.core.protocol.stomp.v11.StompFrameHandlerV11;
|
||||||
import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
|
import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
|
||||||
import org.apache.activemq.artemis.tests.integration.IntegrationTestLogger;
|
import org.apache.activemq.artemis.tests.integration.IntegrationTestLogger;
|
||||||
|
import org.apache.activemq.artemis.tests.integration.stomp.util.AbstractStompClientConnection;
|
||||||
import org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame;
|
import org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame;
|
||||||
import org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection;
|
import org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection;
|
||||||
import org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnectionFactory;
|
import org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnectionFactory;
|
||||||
import org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnectionV11;
|
import org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnectionV11;
|
||||||
|
import org.apache.activemq.artemis.tests.util.Wait;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -2468,6 +2472,48 @@ public class StompV11Test extends StompV11TestBase {
|
||||||
unsubscribe(conn, subId, receipt, false);
|
unsubscribe(conn, subId, receipt, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHeartBeat3() throws Exception {
|
||||||
|
|
||||||
|
connection.close();
|
||||||
|
ClientStompFrame frame = connV11.createFrame("CONNECT");
|
||||||
|
frame.addHeader("host", "127.0.0.1");
|
||||||
|
frame.addHeader("login", this.defUser);
|
||||||
|
frame.addHeader("passcode", this.defPass);
|
||||||
|
frame.addHeader("heart-beat", "500,500");
|
||||||
|
frame.addHeader("accept-version", "1.0,1.1");
|
||||||
|
|
||||||
|
ClientStompFrame reply = connV11.sendFrame(frame);
|
||||||
|
|
||||||
|
assertEquals("CONNECTED", reply.getCommand());
|
||||||
|
|
||||||
|
assertEquals("500,500", reply.getHeader("heart-beat"));
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("========== start pinger!");
|
||||||
|
|
||||||
|
connV11.startPinger(100);
|
||||||
|
|
||||||
|
|
||||||
|
Assert.assertEquals(1, server.getActiveMQServer().getRemotingService().getConnections().size());
|
||||||
|
StompConnection stompConnection = (StompConnection)server.getActiveMQServer().getRemotingService().getConnections().iterator().next();
|
||||||
|
StompFrameHandlerV11 stompFrameHandler = (StompFrameHandlerV11) stompConnection.getStompVersionHandler();
|
||||||
|
|
||||||
|
Thread.sleep(1000);
|
||||||
|
|
||||||
|
//now check the frame size
|
||||||
|
int size = connV11.getServerPingNumber();
|
||||||
|
|
||||||
|
connV11.stopPinger();
|
||||||
|
((AbstractStompClientConnection)connV11).killReaderThread();
|
||||||
|
Wait.waitFor(() -> {
|
||||||
|
return server.getActiveMQServer().getRemotingService().getConnections().size() == 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
Assert.assertFalse(stompFrameHandler.getHeartBeater().isStarted());
|
||||||
|
}
|
||||||
|
|
||||||
protected void assertSubscribeWithClientAckThenConsumeWithAutoAck(boolean sendDisconnect) throws Exception {
|
protected void assertSubscribeWithClientAckThenConsumeWithAutoAck(boolean sendDisconnect) throws Exception {
|
||||||
connV11.connect(defUser, defPass);
|
connV11.connect(defUser, defPass);
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ public abstract class StompV11TestBase extends ActiveMQTestBase {
|
||||||
|
|
||||||
private ConnectionFactory connectionFactory;
|
private ConnectionFactory connectionFactory;
|
||||||
|
|
||||||
private Connection connection;
|
protected Connection connection;
|
||||||
|
|
||||||
protected Session session;
|
protected Session session;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue