@Override public void start() { logger.info("Starting {}...", this); try { Responder responder = new SpecificResponder(AvroSourceProtocol.class, this); socketChannelFactory = initSocketChannelFactory(); ChannelPipelineFactory pipelineFactory = initChannelPipelineFactory(); server = new NettyServer(responder, new InetSocketAddress(bindAddress, port), socketChannelFactory, pipelineFactory, null); } catch (org.jboss.netty.channel.ChannelException nce) { logger.error("Avro source {} startup failed. Cannot initialize Netty server", getName(), nce); stop(); throw new FlumeException("Failed to set up server socket", nce); } connectionCountUpdater = Executors.newSingleThreadScheduledExecutor(); server.start(); sourceCounter.start(); super.start(); final NettyServer srv = (NettyServer)server; connectionCountUpdater.scheduleWithFixedDelay( () -> sourceCounter.setOpenConnectionCount(Long.valueOf(srv.getNumActiveConnections())), 0, 60, TimeUnit.SECONDS); logger.info("Avro source {} started.", getName()); }
@Test public void testConnectionsCount() throws Exception { Transceiver transceiver2 = new NettyTransceiver(new InetSocketAddress( server.getPort()), CONNECT_TIMEOUT_MILLIS); Mail proxy2 = SpecificRequestor.getClient(Mail.class, transceiver2); proxy.fireandforget(createMessage()); proxy2.fireandforget(createMessage()); Assert.assertEquals(2, ((NettyServer) server).getNumActiveConnections()); transceiver2.close(); // Check the active connections with some retries as closing at the client // side might not take effect on the server side immediately int numActiveConnections = ((NettyServer) server).getNumActiveConnections(); for (int i = 0; i < 50 && numActiveConnections == 2; ++i) { System.out.println("Server still has 2 active connections; retrying..."); Thread.sleep(100); numActiveConnections = ((NettyServer) server).getNumActiveConnections(); } Assert.assertEquals(1, numActiveConnections); }
@Override public void start() { logger.info("Starting {}...", this); try { Responder responder = new SpecificResponder(AvroSourceProtocol.class, this); socketChannelFactory = initSocketChannelFactory(); ChannelPipelineFactory pipelineFactory = initChannelPipelineFactory(); server = new NettyServer(responder, new InetSocketAddress(bindAddress, port), socketChannelFactory, pipelineFactory, null); } catch (org.jboss.netty.channel.ChannelException nce) { logger.error("Avro source {} startup failed. Cannot initialize Netty server", getName(), nce); stop(); throw new FlumeException("Failed to set up server socket", nce); } connectionCountUpdater = Executors.newSingleThreadScheduledExecutor(); server.start(); sourceCounter.start(); super.start(); final NettyServer srv = (NettyServer)server; connectionCountUpdater.scheduleWithFixedDelay( () -> sourceCounter.setOpenConnectionCount(Long.valueOf(srv.getNumActiveConnections())), 0, 60, TimeUnit.SECONDS); logger.info("Avro source {} started.", getName()); }