Here are the examples of the java api class org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection taken from open source projects.
1. PingTest#testClientFailureNoServerPing()
Project: activemq-artemis
File: PingTest.java
File: PingTest.java
/* * Test the client triggering failure due to no ping from server received in time */ @Test public void testClientFailureNoServerPing() throws Exception { // server must received at least one ping from the client to pass // so that the server connection TTL is configured with the client value final CountDownLatch pingOnServerLatch = 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) { pingOnServerLatch.countDown(); } return true; } }); TransportConfiguration transportConfig = new TransportConfiguration(INVM_CONNECTOR_FACTORY); ServerLocator locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(transportConfig)); locator.setClientFailureCheckPeriod(PingTest.CLIENT_FAILURE_CHECK_PERIOD); locator.setConnectionTTL(PingTest.CLIENT_FAILURE_CHECK_PERIOD * 2); ClientSessionFactory csf = createSessionFactory(locator); ClientSession session = csf.createSession(false, true, true); Assert.assertEquals(1, ((ClientSessionFactoryInternal) csf).numConnections()); final CountDownLatch clientLatch = new CountDownLatch(1); SessionFailureListener clientListener = new SessionFailureListener() { @Override public void connectionFailed(final ActiveMQException me, boolean failedOver) { clientLatch.countDown(); } @Override public void connectionFailed(final ActiveMQException me, boolean failedOver, String scaleDownTargetNodeID) { connectionFailed(me, failedOver); } @Override public void beforeReconnect(final ActiveMQException exception) { } }; final CountDownLatch serverLatch = new CountDownLatch(1); CloseListener serverListener = new CloseListener() { @Override public void connectionClosed() { serverLatch.countDown(); } }; session.addFailureListener(clientListener); CoreRemotingConnection serverConn = null; while (serverConn == null) { Set<RemotingConnection> conns = server.getRemotingService().getConnections(); if (!conns.isEmpty()) { serverConn = (CoreRemotingConnection) server.getRemotingService().getConnections().iterator().next(); } else { // It's async so need to wait a while Thread.sleep(10); } } serverConn.addCloseListener(serverListener); Assert.assertTrue("server has not received any ping from the client", pingOnServerLatch.await(4000, TimeUnit.MILLISECONDS)); // we let the server receives at least 1 ping (so that it uses the client ConnectionTTL value) // Setting the handler to null will prevent server sending pings back to client serverConn.getChannel(0, -1).setHandler(null); Assert.assertTrue(clientLatch.await(8 * PingTest.CLIENT_FAILURE_CHECK_PERIOD, TimeUnit.MILLISECONDS)); // Server connection will be closed too, when client closes client side connection after failure is detected Assert.assertTrue(serverLatch.await(2 * RemotingServiceImpl.CONNECTION_TTL_CHECK_INTERVAL, TimeUnit.MILLISECONDS)); long start = System.currentTimeMillis(); while (true) { if (!server.getRemotingService().getConnections().isEmpty() && System.currentTimeMillis() - start < 10000) { Thread.sleep(500); } else { break; } } Assert.assertTrue(server.getRemotingService().getConnections().isEmpty()); session.close(); csf.close(); locator.close(); }
2. ClusterControl#createReplicationChannel()
Project: activemq-artemis
File: ClusterControl.java
File: ClusterControl.java
/** * create a replication channel * * @return the replication channel */ public Channel createReplicationChannel() { CoreRemotingConnection connection = (CoreRemotingConnection) sessionFactory.getConnection(); return connection.getChannel(ChannelImpl.CHANNEL_ID.REPLICATION.id, -1); }
3. ClusterControl#authorize()
Project: activemq-artemis
File: ClusterControl.java
File: ClusterControl.java
/** * authorise this cluster control so it can communicate with the cluster, it will set the cluster channel on a successful * authentication. * * @throws ActiveMQException if authorisation wasn't successful. */ public void authorize() throws ActiveMQException { CoreRemotingConnection connection = (CoreRemotingConnection) sessionFactory.getConnection(); clusterChannel = connection.getChannel(ChannelImpl.CHANNEL_ID.CLUSTER.id, -1); ClusterConnectReplyMessage packet = (ClusterConnectReplyMessage) clusterChannel.sendBlocking(new ClusterConnectMessage(clusterUser, clusterPassword), PacketImpl.CLUSTER_CONNECT_REPLY); if (!packet.isAuthorized()) { throw ActiveMQMessageBundle.BUNDLE.unableToValidateClusterUser(clusterUser); } }
4. CoreProtocolManager#createConnectionEntry()
Project: activemq-artemis
File: CoreProtocolManager.java
File: CoreProtocolManager.java
@Override public ConnectionEntry createConnectionEntry(final Acceptor acceptorUsed, final Connection connection) { final Configuration config = server.getConfiguration(); Executor connectionExecutor = server.getExecutorFactory().getExecutor(); final CoreRemotingConnection rc = new RemotingConnectionImpl(ServerPacketDecoder.INSTANCE, connection, incomingInterceptors, outgoingInterceptors, config.isAsyncConnectionExecutionEnabled() ? connectionExecutor : null, server.getNodeID()); Channel channel1 = rc.getChannel(CHANNEL_ID.SESSION.id, -1); ChannelHandler handler = new ActiveMQPacketHandler(this, server, channel1, rc); channel1.setHandler(handler); long ttl = ActiveMQClient.DEFAULT_CONNECTION_TTL; if (config.getConnectionTTLOverride() != -1) { ttl = config.getConnectionTTLOverride(); } final ConnectionEntry entry = new ConnectionEntry(rc, connectionExecutor, System.currentTimeMillis(), ttl); final Channel channel0 = rc.getChannel(ChannelImpl.CHANNEL_ID.PING.id, -1); channel0.setHandler(new LocalChannelHandler(config, entry, channel0, acceptorUsed, rc)); server.getClusterManager().addClusterChannelHandler(rc.getChannel(CHANNEL_ID.CLUSTER.id, -1), acceptorUsed, rc, server.getActivation()); return entry; }