use of org.apache.activemq.transport.TransportListener in project activemq-artemis by apache.
the class WireformatNegociationTest method startClient.
/**
* @throws Exception
* @throws URISyntaxException
*/
private void startClient(String uri) throws Exception, URISyntaxException {
clientTransport = TransportFactory.connect(new URI(uri));
clientTransport.setTransportListener(new TransportListener() {
@Override
public void onCommand(Object command) {
if (command instanceof WireFormatInfo) {
clientWF.set((WireFormatInfo) command);
negotiationCounter.countDown();
}
}
@Override
public void onException(IOException error) {
if (!ignoreAsycError.get()) {
LOG.info("Client transport error: ", error);
asyncError.set(error);
negotiationCounter.countDown();
}
}
@Override
public void transportInterupted() {
}
@Override
public void transportResumed() {
}
});
clientTransport.start();
}
use of org.apache.activemq.transport.TransportListener in project activemq-artemis by apache.
the class InactivityMonitorTest method startClient.
/**
* @throws Exception
* @throws URISyntaxException
*/
private void startClient() throws Exception, URISyntaxException {
clientTransport = TransportFactory.connect(new URI("tcp://localhost:" + serverPort + "?trace=true&wireFormat.maxInactivityDuration=1000"));
clientTransport.setTransportListener(new TransportListener() {
@Override
public void onCommand(Object command) {
clientReceiveCount.incrementAndGet();
if (clientRunOnCommand != null) {
clientRunOnCommand.run();
}
}
@Override
public void onException(IOException error) {
if (!ignoreClientError.get()) {
LOG.info("Client transport error:");
error.printStackTrace();
clientErrorCount.incrementAndGet();
}
}
@Override
public void transportInterupted() {
}
@Override
public void transportResumed() {
}
});
clientTransport.start();
}
use of org.apache.activemq.transport.TransportListener in project activemq-artemis by apache.
the class InactivityMonitorTest method onAccept.
@Override
public void onAccept(Transport transport) {
try {
LOG.info("[" + getName() + "] Server Accepted a Connection");
serverTransport = transport;
serverTransport.setTransportListener(new TransportListener() {
@Override
public void onCommand(Object command) {
serverReceiveCount.incrementAndGet();
if (serverRunOnCommand != null) {
serverRunOnCommand.run();
}
}
@Override
public void onException(IOException error) {
if (!ignoreClientError.get()) {
LOG.info("Server transport error:", error);
serverErrorCount.incrementAndGet();
}
}
@Override
public void transportInterupted() {
}
@Override
public void transportResumed() {
}
});
serverTransport.start();
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.apache.activemq.transport.TransportListener in project activemq-artemis by apache.
the class InactivityMonitorTest method testClientHang.
public void testClientHang() throws Exception {
// Manually create a client transport so that it does not send KeepAlive
// packets. this should simulate a client hang.
clientTransport = new TcpTransport(new OpenWireFormat(), SocketFactory.getDefault(), new URI("tcp://localhost:" + serverPort), null);
clientTransport.setTransportListener(new TransportListener() {
@Override
public void onCommand(Object command) {
clientReceiveCount.incrementAndGet();
if (clientRunOnCommand != null) {
clientRunOnCommand.run();
}
}
@Override
public void onException(IOException error) {
if (!ignoreClientError.get()) {
LOG.info("Client transport error:");
error.printStackTrace();
clientErrorCount.incrementAndGet();
}
}
@Override
public void transportInterupted() {
}
@Override
public void transportResumed() {
}
});
clientTransport.start();
WireFormatInfo info = new WireFormatInfo();
info.setVersion(OpenWireFormat.DEFAULT_LEGACY_VERSION);
info.setMaxInactivityDuration(1000);
clientTransport.oneway(info);
assertEquals(0, serverErrorCount.get());
assertEquals(0, clientErrorCount.get());
// Server should consider the client timed out right away since the
// client is not hart beating fast enough.
Thread.sleep(6000);
assertEquals(0, clientErrorCount.get());
assertTrue(serverErrorCount.get() > 0);
}
use of org.apache.activemq.transport.TransportListener in project activemq-artemis by apache.
the class FailoverTransportBackupsTest method createTransport.
protected Transport createTransport(int backups) throws Exception {
String connectionUri = "failover://(" + newURI(0) + "," + newURI(1) + "," + newURI(2) + ")";
if (backups > 0) {
connectionUri += "?randomize=false&backup=true&backupPoolSize=" + backups;
}
Transport transport = TransportFactory.connect(new URI(connectionUri));
transport.setTransportListener(new TransportListener() {
@Override
public void onCommand(Object command) {
LOG.debug("Test Transport Listener received Command: " + command);
}
@Override
public void onException(IOException error) {
LOG.debug("Test Transport Listener received Exception: " + error);
}
@Override
public void transportInterupted() {
transportInterruptions++;
LOG.debug("Test Transport Listener records transport Interrupted: " + transportInterruptions);
}
@Override
public void transportResumed() {
transportResumptions++;
LOG.debug("Test Transport Listener records transport Resumed: " + transportResumptions);
}
});
transport.start();
this.failoverTransport = transport.narrow(FailoverTransport.class);
return transport;
}
Aggregations