Search in sources :

Example 1 with Ping

use of org.apache.activemq.artemis.core.protocol.core.impl.wireformat.Ping in project activemq-artemis by apache.

the class PingTest method testNoPingingOnInVMConnection.

/*
    * Test that pinging is disabled for in-vm connection when using the default settings
    */
@Test
public void testNoPingingOnInVMConnection() throws Exception {
    // server should receive one and only one ping from the client so that
    // the server connection TTL is configured with the client value
    final CountDownLatch requiredPings = new CountDownLatch(1);
    final CountDownLatch unwantedPings = new CountDownLatch(2);
    server.getRemotingService().addIncomingInterceptor(new Interceptor() {

        @Override
        public boolean intercept(final Packet packet, final RemotingConnection connection) throws ActiveMQException {
            if (packet.getType() == PacketImpl.PING) {
                Assert.assertEquals(ActiveMQClient.DEFAULT_CONNECTION_TTL_INVM, ((Ping) packet).getConnectionTTL());
                unwantedPings.countDown();
                requiredPings.countDown();
            }
            return true;
        }
    });
    TransportConfiguration transportConfig = new TransportConfiguration("org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory");
    ServerLocator locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(transportConfig));
    ClientSessionFactory csf = createSessionFactory(locator);
    ClientSession session = csf.createSession(false, true, true);
    Assert.assertEquals(1, ((ClientSessionFactoryInternal) csf).numConnections());
    Assert.assertTrue("server didn't received an expected ping from the client", requiredPings.await(5000, TimeUnit.MILLISECONDS));
    Assert.assertFalse("server received an unexpected ping from the client", unwantedPings.await(ActiveMQClient.DEFAULT_CONNECTION_TTL * 2, TimeUnit.MILLISECONDS));
    session.close();
    csf.close();
    locator.close();
}
Also used : Packet(org.apache.activemq.artemis.core.protocol.core.Packet) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) Ping(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.Ping) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) CoreRemotingConnection(org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) CountDownLatch(java.util.concurrent.CountDownLatch) Interceptor(org.apache.activemq.artemis.api.core.Interceptor) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 2 with Ping

use of org.apache.activemq.artemis.core.protocol.core.impl.wireformat.Ping in project activemq-artemis by apache.

the class ActiveMQClientProtocolManager method ping.

@Override
public void ping(long connectionTTL) {
    Channel channel = connection.getChannel(ChannelImpl.CHANNEL_ID.PING.id, -1);
    Ping ping = new Ping(connectionTTL);
    channel.send(ping);
    connection.flush();
}
Also used : Channel(org.apache.activemq.artemis.core.protocol.core.Channel) Ping(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.Ping)

Aggregations

Ping (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.Ping)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 Interceptor (org.apache.activemq.artemis.api.core.Interceptor)1 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)1 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)1 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)1 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)1 Channel (org.apache.activemq.artemis.core.protocol.core.Channel)1 CoreRemotingConnection (org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection)1 Packet (org.apache.activemq.artemis.core.protocol.core.Packet)1 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)1 Test (org.junit.Test)1