List of usage examples for io.netty.util HashedWheelTimer HashedWheelTimer
public HashedWheelTimer()
From source file:org.apache.camel.component.netty4.NettyProducer.java
License:Apache License
@Override protected void doStart() throws Exception { super.doStart(); if (configuration.isProducerPoolEnabled()) { // setup pool where we want an unbounded pool, which allows the pool to shrink on no demand GenericObjectPool.Config config = new GenericObjectPool.Config(); config.maxActive = configuration.getProducerPoolMaxActive(); config.minIdle = configuration.getProducerPoolMinIdle(); config.maxIdle = configuration.getProducerPoolMaxIdle(); // we should test on borrow to ensure the channel is still valid config.testOnBorrow = true;/* w w w .ja va 2s . c o m*/ // only evict channels which are no longer valid config.testWhileIdle = true; // run eviction every 30th second config.timeBetweenEvictionRunsMillis = 30 * 1000L; config.minEvictableIdleTimeMillis = configuration.getProducerPoolMinEvictableIdle(); config.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL; pool = new GenericObjectPool<Channel>(new NettyProducerPoolableObjectFactory(), config); if (LOG.isDebugEnabled()) { LOG.debug( "Created NettyProducer pool[maxActive={}, minIdle={}, maxIdle={}, minEvictableIdleTimeMillis={}] -> {}", new Object[] { config.maxActive, config.minIdle, config.maxIdle, config.minEvictableIdleTimeMillis, pool }); } } else { pool = new SharedSingletonObjectPool<Channel>(new NettyProducerPoolableObjectFactory()); if (LOG.isDebugEnabled()) { LOG.info("Created NettyProducer shared singleton pool -> {}", pool); } } timer = new HashedWheelTimer(); // setup pipeline factory ClientPipelineFactory factory = configuration.getClientPipelineFactory(); if (factory != null) { pipelineFactory = factory.createPipelineFactory(this); } else { pipelineFactory = new DefaultClientPipelineFactory(this); } if (!configuration.isLazyChannelCreation()) { // ensure the connection can be established when we start up Channel channel = pool.borrowObject(); pool.returnObject(channel); } }
From source file:org.apache.pulsar.zookeeper.ZkIsolatedBookieEnsemblePlacementPolicyTest.java
License:Apache License
@BeforeMethod public void setUp() throws Exception { timer = new HashedWheelTimer(); localZkS = new ZookeeperServerTest(LOCAL_ZOOKEEPER_PORT); localZkS.start();/*from www . ja v a 2s . c o m*/ localZkc = ZooKeeperClient.newBuilder().connectString("127.0.0.1" + ":" + LOCAL_ZOOKEEPER_PORT).build(); writableBookies.add(new BookieSocketAddress(BOOKIE1)); writableBookies.add(new BookieSocketAddress(BOOKIE2)); writableBookies.add(new BookieSocketAddress(BOOKIE3)); writableBookies.add(new BookieSocketAddress(BOOKIE4)); isolationGroups.add("group1"); }
From source file:org.asynchttpclient.DefaultAsyncHttpClient.java
License:Apache License
private Timer newNettyTimer() { HashedWheelTimer timer = new HashedWheelTimer(); timer.start(); return timer; }
From source file:org.asynchttpclient.providers.netty.channel.Channels.java
License:Apache License
private Timer newNettyTimer() { HashedWheelTimer nettyTimer = new HashedWheelTimer(); nettyTimer.start(); return nettyTimer; }
From source file:org.opendaylight.controller.netconf.cli.NetconfDeviceConnectionManager.java
License:Open Source License
public NetconfDeviceConnectionManager(final CommandDispatcher commandDispatcher, final CommandArgHandlerRegistry argumentHandlerRegistry, final SchemaContextRegistry schemaContextRegistry, final ConsoleIO consoleIO) { this.commandDispatcher = commandDispatcher; this.schemaContextRegistry = schemaContextRegistry; this.console = consoleIO; executor = Executors.newSingleThreadExecutor(); nettyThreadGroup = new NioEventLoopGroup(); netconfClientDispatcher = new NetconfClientDispatcherImpl(nettyThreadGroup, nettyThreadGroup, new HashedWheelTimer()); }
From source file:org.opendaylight.controller.netconf.client.NetconfClientDispatcherImplTest.java
License:Open Source License
@Test public void testNetconfClientDispatcherImpl() throws Exception { EventLoopGroup bossGroup = Mockito.mock(EventLoopGroup.class); EventLoopGroup workerGroup = Mockito.mock(EventLoopGroup.class); Timer timer = new HashedWheelTimer(); ChannelFuture chf = Mockito.mock(ChannelFuture.class); Channel ch = Mockito.mock(Channel.class); doReturn(ch).when(chf).channel();// w w w .j ava2 s .c o m Throwable thr = Mockito.mock(Throwable.class); doReturn(chf).when(workerGroup).register(any(Channel.class)); ChannelPromise promise = Mockito.mock(ChannelPromise.class); doReturn(promise).when(chf).addListener(any(GenericFutureListener.class)); doReturn(thr).when(chf).cause(); Long timeout = 200L; NetconfHelloMessageAdditionalHeader header = new NetconfHelloMessageAdditionalHeader("a", "host", "port", "trans", "id"); NetconfClientSessionListener listener = new SimpleNetconfClientSessionListener(); InetSocketAddress address = InetSocketAddress.createUnresolved("host", 830); ReconnectStrategyFactory reconnectStrategyFactory = Mockito.mock(ReconnectStrategyFactory.class); AuthenticationHandler handler = Mockito.mock(AuthenticationHandler.class); ReconnectStrategy reconnect = Mockito.mock(ReconnectStrategy.class); doReturn(5).when(reconnect).getConnectTimeout(); doReturn("").when(reconnect).toString(); doReturn("").when(handler).toString(); doReturn("").when(reconnectStrategyFactory).toString(); doReturn(reconnect).when(reconnectStrategyFactory).createReconnectStrategy(); NetconfReconnectingClientConfiguration cfg = NetconfReconnectingClientConfigurationBuilder.create() .withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH).withAddress(address) .withConnectionTimeoutMillis(timeout).withReconnectStrategy(reconnect).withAdditionalHeader(header) .withSessionListener(listener).withConnectStrategyFactory(reconnectStrategyFactory) .withAuthHandler(handler).build(); NetconfReconnectingClientConfiguration cfg2 = NetconfReconnectingClientConfigurationBuilder.create() .withProtocol(NetconfClientConfiguration.NetconfClientProtocol.TCP).withAddress(address) .withConnectionTimeoutMillis(timeout).withReconnectStrategy(reconnect).withAdditionalHeader(header) .withSessionListener(listener).withConnectStrategyFactory(reconnectStrategyFactory) .withAuthHandler(handler).build(); NetconfClientDispatcherImpl dispatcher = new NetconfClientDispatcherImpl(bossGroup, workerGroup, timer); Future<NetconfClientSession> sshSession = dispatcher.createClient(cfg); Future<NetconfClientSession> tcpSession = dispatcher.createClient(cfg2); Future<Void> sshReconn = dispatcher.createReconnectingClient(cfg); Future<Void> tcpReconn = dispatcher.createReconnectingClient(cfg2); assertNotNull(sshSession); assertNotNull(tcpSession); assertNotNull(sshReconn); assertNotNull(tcpReconn); }
From source file:org.opendaylight.controller.netconf.client.NetconfClientSessionNegotiatorFactoryTest.java
License:Open Source License
@Test public void testGetSessionNegotiator() throws Exception { NetconfClientSessionListener sessionListener = mock(NetconfClientSessionListener.class); Timer timer = new HashedWheelTimer(); SessionListenerFactory<NetconfClientSessionListener> listenerFactory = mock(SessionListenerFactory.class); doReturn(sessionListener).when(listenerFactory).getSessionListener(); Channel channel = mock(Channel.class); Promise<NetconfClientSession> promise = mock(Promise.class); NetconfClientSessionNegotiatorFactory negotiatorFactory = new NetconfClientSessionNegotiatorFactory(timer, Optional.<NetconfHelloMessageAdditionalHeader>absent(), 200L); SessionNegotiator<?> sessionNegotiator = negotiatorFactory.getSessionNegotiator(listenerFactory, channel, promise);/*from w ww. j a va 2 s . c om*/ assertNotNull(sessionNegotiator); }
From source file:org.opendaylight.controller.netconf.client.NetconfClientSessionNegotiatorTest.java
License:Open Source License
private NetconfClientSessionNegotiator createNetconfClientSessionNegotiator( final Promise<NetconfClientSession> promise, final NetconfMessage startExi) { ChannelProgressivePromise progressivePromise = mock(ChannelProgressivePromise.class); NetconfClientSessionPreferences preferences = new NetconfClientSessionPreferences(helloMessage, startExi); doReturn(progressivePromise).when(promise).setFailure(any(Throwable.class)); long timeout = 10L; NetconfClientSessionListener sessionListener = mock(NetconfClientSessionListener.class); Timer timer = new HashedWheelTimer(); return new NetconfClientSessionNegotiator(preferences, promise, channel, timer, sessionListener, timeout); }
From source file:org.opendaylight.controller.netconf.client.test.TestingNetconfClient.java
License:Open Source License
public static void main(String[] args) throws Exception { HashedWheelTimer hashedWheelTimer = new HashedWheelTimer(); NioEventLoopGroup nettyGroup = new NioEventLoopGroup(); NetconfClientDispatcherImpl netconfClientDispatcher = new NetconfClientDispatcherImpl(nettyGroup, nettyGroup, hashedWheelTimer); LoginPassword authHandler = new LoginPassword("admin", "admin"); TestingNetconfClient client = new TestingNetconfClient("client", netconfClientDispatcher, getClientConfig("127.0.0.1", 1830, true, Optional.of(authHandler))); System.out.println(client.getCapabilities()); }
From source file:org.opendaylight.controller.netconf.client.TestingNetconfClient.java
License:Open Source License
public static void main(String[] args) throws Exception { HashedWheelTimer hashedWheelTimer = new HashedWheelTimer(); NioEventLoopGroup nettyGroup = new NioEventLoopGroup(); NetconfClientDispatcherImpl netconfClientDispatcher = new NetconfClientDispatcherImpl(nettyGroup, nettyGroup, hashedWheelTimer); LoginPassword authHandler = new LoginPassword("admin", "admin"); TestingNetconfClient client = new TestingNetconfClient("client", netconfClientDispatcher, getClientConfig("127.0.0.1", 1830, true, Optional.of(authHandler))); System.console().writer().println(client.getCapabilities()); }