Modifed version of patch supplied by Claudio Parodi to handle incoming
ping frames correctly.
This commit is contained in:
Timothy Bish 2015-03-31 16:36:56 -04:00
parent b9ed01fa56
commit 516c9db43b
3 changed files with 66 additions and 6 deletions

View File

@ -20,6 +20,7 @@ import java.io.IOException;
import java.util.concurrent.CountDownLatch;
import org.apache.activemq.command.Command;
import org.apache.activemq.command.KeepAliveInfo;
import org.apache.activemq.transport.TransportSupport;
import org.apache.activemq.transport.stomp.ProtocolConverter;
import org.apache.activemq.transport.stomp.Stomp;
@ -44,7 +45,7 @@ class StompSocket extends TransportSupport implements WebSocket.OnTextMessage, S
ProtocolConverter protocolConverter = new ProtocolConverter(this, null);
StompWireFormat wireFormat = new StompWireFormat();
private final CountDownLatch socketTransportStarted = new CountDownLatch(1);
private StompInactivityMonitor stompInactivityMonitor = new StompInactivityMonitor(this, wireFormat);
private final StompInactivityMonitor stompInactivityMonitor = new StompInactivityMonitor(this, wireFormat);
@Override
public void onOpen(Connection connection) {
@ -74,7 +75,13 @@ class StompSocket extends TransportSupport implements WebSocket.OnTextMessage, S
try {
protocolConverter.onStompCommand((StompFrame)wireFormat.unmarshal(new ByteSequence(data.getBytes("UTF-8"))));
if (data != null) {
if (data.startsWith("\n")) {
sendToActiveMQ(new KeepAliveInfo());
}
protocolConverter.onStompCommand((StompFrame)wireFormat.unmarshal(new ByteSequence(data.getBytes("UTF-8"))));
}
} catch (Exception e) {
onException(IOExceptionSupport.create(e));
}
@ -87,6 +94,7 @@ class StompSocket extends TransportSupport implements WebSocket.OnTextMessage, S
@Override
protected void doStart() throws Exception {
socketTransportStarted.countDown();
stompInactivityMonitor.setTransportListener(getTransportListener());
}
@Override

View File

@ -20,6 +20,7 @@ import java.io.IOException;
import java.util.concurrent.CountDownLatch;
import org.apache.activemq.command.Command;
import org.apache.activemq.command.KeepAliveInfo;
import org.apache.activemq.transport.TransportSupport;
import org.apache.activemq.transport.stomp.ProtocolConverter;
import org.apache.activemq.transport.stomp.Stomp;
@ -45,7 +46,7 @@ class StompSocket extends TransportSupport implements WebSocketListener, StompTr
ProtocolConverter protocolConverter = new ProtocolConverter(this, null);
StompWireFormat wireFormat = new StompWireFormat();
private final CountDownLatch socketTransportStarted = new CountDownLatch(1);
private StompInactivityMonitor stompInactivityMonitor = new StompInactivityMonitor(this, wireFormat);
private final StompInactivityMonitor stompInactivityMonitor = new StompInactivityMonitor(this, wireFormat);
private boolean transportStartedAtLeastOnce() {
return socketTransportStarted.getCount() == 0;
@ -54,6 +55,7 @@ class StompSocket extends TransportSupport implements WebSocketListener, StompTr
@Override
protected void doStart() throws Exception {
socketTransportStarted.countDown();
stompInactivityMonitor.setTransportListener(getTransportListener());
}
@Override
@ -118,7 +120,7 @@ class StompSocket extends TransportSupport implements WebSocketListener, StompTr
}
@Override
public void onWebSocketError(Throwable arg0) {
public void onWebSocketError(Throwable arg0) {
}
@Override
@ -133,10 +135,15 @@ class StompSocket extends TransportSupport implements WebSocketListener, StompTr
}
try {
protocolConverter.onStompCommand((StompFrame)wireFormat.unmarshal(new ByteSequence(data.getBytes("UTF-8"))));
if (data != null) {
if (data.startsWith("\n")) {
sendToActiveMQ(new KeepAliveInfo());
}
protocolConverter.onStompCommand((StompFrame)wireFormat.unmarshal(new ByteSequence(data.getBytes("UTF-8"))));
}
} catch (Exception e) {
onException(IOExceptionSupport.create(e));
}
}
}

View File

@ -0,0 +1,45 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq;
import java.io.File;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.store.kahadb.KahaDBStore;
public class IDERunner {
private static final boolean TRANSPORT_TRACE = true;
public static void main(String[]args) throws Exception {
BrokerService brokerService = new BrokerService();
brokerService.addConnector(
"ws://0.0.0.0:61614?trace=" + TRANSPORT_TRACE);
KahaDBStore store = new KahaDBStore();
store.setDirectory(new File("target/activemq-data/kahadb"));
brokerService.setStoreOpenWireVersion(10);
brokerService.setPersistenceAdapter(store);
brokerService.setUseJmx(false);
brokerService.deleteAllMessages();
brokerService.start();
brokerService.waitUntilStopped();
}
}