List of usage examples for io.netty.util HashedWheelTimer HashedWheelTimer
public HashedWheelTimer()
From source file:org.opendaylight.controller.netconf.impl.ConcurrentClientsTest.java
License:Open Source License
@Before public void setUp() throws Exception { hashedWheelTimer = new HashedWheelTimer(); nettyGroup = new NioEventLoopGroup(nettyThreads); netconfClientDispatcher = new NetconfClientDispatcherImpl(nettyGroup, nettyGroup, hashedWheelTimer); AggregatedNetconfOperationServiceFactory factoriesListener = new AggregatedNetconfOperationServiceFactory(); testingNetconfOperation = new TestingNetconfOperation(); factoriesListener/*from w ww. j a v a2 s . c om*/ .onAddNetconfOperationServiceFactory(new TestingOperationServiceFactory(testingNetconfOperation)); SessionIdProvider idProvider = new SessionIdProvider(); NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory( hashedWheelTimer, factoriesListener, idProvider, 5000, commitNot, createMockedMonitoringService(), serverCaps); commitNot = new DefaultCommitNotificationProducer(ManagementFactory.getPlatformMBeanServer()); NetconfServerDispatcherImpl.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcherImpl.ServerChannelInitializer( serverNegotiatorFactory); final NetconfServerDispatcherImpl dispatch = new NetconfServerDispatcherImpl(serverChannelInitializer, nettyGroup, nettyGroup); ChannelFuture s = dispatch.createServer(netconfAddress); s.await(); }
From source file:org.opendaylight.controller.netconf.impl.NetconfDispatcherImplTest.java
License:Open Source License
@Before public void setUp() throws Exception { nettyGroup = new NioEventLoopGroup(); commitNot = new DefaultCommitNotificationProducer(ManagementFactory.getPlatformMBeanServer()); AggregatedNetconfOperationServiceFactory factoriesListener = new AggregatedNetconfOperationServiceFactory(); SessionIdProvider idProvider = new SessionIdProvider(); hashedWheelTimer = new HashedWheelTimer(); NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory( hashedWheelTimer, factoriesListener, idProvider, 5000, commitNot, ConcurrentClientsTest.createMockedMonitoringService()); NetconfServerDispatcherImpl.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcherImpl.ServerChannelInitializer( serverNegotiatorFactory);/*w w w . j a v a 2 s. c o m*/ dispatch = new NetconfServerDispatcherImpl(serverChannelInitializer, nettyGroup, nettyGroup); }
From source file:org.opendaylight.controller.netconf.impl.osgi.NetconfImplActivator.java
License:Open Source License
@Override public void start(final BundleContext context) { AggregatedNetconfOperationServiceFactory factoriesListener = new AggregatedNetconfOperationServiceFactory(); startOperationServiceFactoryTracker(context, factoriesListener); SessionIdProvider idProvider = new SessionIdProvider(); timer = new HashedWheelTimer(); long connectionTimeoutMillis = NetconfConfigUtil.extractTimeoutMillis(context); commitNot = new DefaultCommitNotificationProducer(ManagementFactory.getPlatformMBeanServer()); NetconfMonitoringService monitoringService = startMonitoringService(context, factoriesListener); NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory( timer, factoriesListener, idProvider, connectionTimeoutMillis, commitNot, monitoringService); eventLoopGroup = new NioEventLoopGroup(); NetconfServerDispatcherImpl.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcherImpl.ServerChannelInitializer( serverNegotiatorFactory);/*from w ww . ja va2s . co m*/ NetconfServerDispatcherImpl dispatch = new NetconfServerDispatcherImpl(serverChannelInitializer, eventLoopGroup, eventLoopGroup); LocalAddress address = NetconfConfigUtil.getNetconfLocalAddress(); LOG.trace("Starting local netconf server at {}", address); dispatch.createLocalServer(address); }
From source file:org.opendaylight.controller.netconf.it.AbstractNetconfConfigTest.java
License:Open Source License
/** * @Before in subclasses is called after this method. *//* w w w . j a v a 2 s .c o m*/ @Before public void setUpAbstractNetconfConfigTest() throws Exception { super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext, FACTORIES)); nettyThreadgroup = new NioEventLoopGroup(); hashedWheelTimer = new HashedWheelTimer(); loadMessages(); setUpTestInitial(); final AggregatedNetconfOperationServiceFactory factoriesListener = new AggregatedNetconfOperationServiceFactory(); final NetconfMonitoringService netconfMonitoringService = getNetconfMonitoringService(factoriesListener); factoriesListener .onAddNetconfOperationServiceFactory(new NetconfOperationServiceFactoryImpl(getYangStore())); factoriesListener.onAddNetconfOperationServiceFactory( new NetconfMonitoringActivator.NetconfMonitoringOperationServiceFactory( new NetconfMonitoringOperationService(netconfMonitoringService))); for (final NetconfOperationServiceFactory netconfOperationServiceFactory : getAdditionalServiceFactories( factoriesListener)) { factoriesListener.onAddNetconfOperationServiceFactory(netconfOperationServiceFactory); } serverTcpChannel = startNetconfTcpServer(factoriesListener, netconfMonitoringService); clientDispatcher = new NetconfClientDispatcherImpl(getNettyThreadgroup(), getNettyThreadgroup(), getHashedWheelTimer()); }
From source file:org.opendaylight.controller.netconf.it.NetconfITSecureTestTool.java
License:Open Source License
/** * Test all requests are handled properly and no mismatch occurs in listener *///from w w w . jav a 2 s .c o m @Test(timeout = 6 * 60 * 1000) public void testSecureStress() throws Exception { final int requests = 4000; List<Future<?>> tasks = new ArrayList<>(); final NetconfClientDispatcher dispatch = new NetconfClientDispatcherImpl(new NioEventLoopGroup(), new NioEventLoopGroup(), new HashedWheelTimer()); final NetconfDeviceCommunicator sessionListener = getSessionListener(); try (TestingNetconfClient netconfClient = new TestingNetconfClient("testing-ssh-client", dispatch, NetconfITSecureTest.getClientConfiguration(sessionListener, TLS_ADDRESS));) { final AtomicInteger responseCounter = new AtomicInteger(0); final List<ListenableFuture<RpcResult<NetconfMessage>>> futures = Lists.newArrayList(); for (int i = 0; i < requests; i++) { NetconfMessage getConfig = XmlFileLoader.xmlFileToNetconfMessage(xmlFile); getConfig = NetconfITSecureTest.changeMessageId(getConfig, i); Runnable worker = new NetconfITSecureTestToolRunnable(getConfig, i, sessionListener, futures, responseCounter); tasks.add(msgExec.submit(worker)); } msgExec.shutdown(); // Wait for every future for (final Future<?> task : tasks) { try { task.get(3, TimeUnit.MINUTES); } catch (final TimeoutException e) { fail(String.format("Request %d is not responding", tasks.indexOf(task))); } } for (final ListenableFuture<RpcResult<NetconfMessage>> future : futures) { try { future.get(3, TimeUnit.MINUTES); } catch (final TimeoutException e) { fail(String.format("Reply %d is not responding", futures.indexOf(future))); } } sleep(5000); assertEquals(requests, responseCounter.get()); } }
From source file:org.opendaylight.controller.netconf.netty.SSHTest.java
License:Open Source License
@BeforeClass public static void setUp() throws Exception { hashedWheelTimer = new HashedWheelTimer(); nettyGroup = new NioEventLoopGroup(); nioExec = Executors.newFixedThreadPool(1); minaTimerEx = Executors.newScheduledThreadPool(1); }
From source file:org.opendaylight.controller.netconf.test.tool.client.stress.StressClient.java
License:Open Source License
public static void main(final String[] args) { final Parameters params = parseArgs(args, Parameters.getParser()); params.validate();/*from w ww. ja v a 2 s . c o m*/ final ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory .getLogger(Logger.ROOT_LOGGER_NAME); root.setLevel(params.debug ? Level.DEBUG : Level.INFO); final int threadAmount = params.threadAmount; LOG.info("thread amount: " + threadAmount); final int requestsPerThread = params.editCount / params.threadAmount; LOG.info("requestsPerThread: " + requestsPerThread); final int leftoverRequests = params.editCount % params.threadAmount; LOG.info("leftoverRequests: " + leftoverRequests); LOG.info("Preparing messages"); // Prepare all msgs up front final List<List<NetconfMessage>> allPreparedMessages = new ArrayList<>(threadAmount); for (int i = 0; i < threadAmount; i++) { if (i != threadAmount - 1) { allPreparedMessages.add(new ArrayList<NetconfMessage>(requestsPerThread)); } else { allPreparedMessages.add(new ArrayList<NetconfMessage>(requestsPerThread + leftoverRequests)); } } final String editContentString; try { editContentString = Files.toString(params.editContent, Charsets.UTF_8); } catch (final IOException e) { throw new IllegalArgumentException("Cannot read content of " + params.editContent); } for (int i = 0; i < threadAmount; i++) { final List<NetconfMessage> preparedMessages = allPreparedMessages.get(i); int padding = 0; if (i == threadAmount - 1) { padding = leftoverRequests; } for (int j = 0; j < requestsPerThread + padding; j++) { LOG.debug("id: " + (i * requestsPerThread + j)); preparedMessages.add(prepareMessage(i * requestsPerThread + j, editContentString)); } } final NioEventLoopGroup nioGroup = new NioEventLoopGroup(); final Timer timer = new HashedWheelTimer(); final NetconfClientDispatcherImpl netconfClientDispatcher = configureClientDispatcher(params, nioGroup, timer); final List<StressClientCallable> callables = new ArrayList<>(threadAmount); for (final List<NetconfMessage> messages : allPreparedMessages) { callables.add(new StressClientCallable(params, netconfClientDispatcher, messages)); } final ExecutorService executorService = Executors.newFixedThreadPool(threadAmount); LOG.info("Starting stress test"); final Stopwatch started = Stopwatch.createStarted(); try { final List<Future<Boolean>> futures = executorService.invokeAll(callables); for (final Future<Boolean> future : futures) { try { future.get(4L, TimeUnit.MINUTES); } catch (ExecutionException | TimeoutException e) { throw new RuntimeException(e); } } executorService.shutdownNow(); } catch (final InterruptedException e) { throw new RuntimeException("Unable to execute requests", e); } started.stop(); LOG.info("FINISHED. Execution time: {}", started); LOG.info("Requests per second: {}", (params.editCount * 1000.0 / started.elapsed(TimeUnit.MILLISECONDS))); // Cleanup timer.stop(); try { nioGroup.shutdownGracefully().get(20L, TimeUnit.SECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { LOG.warn("Unable to close executor properly", e); } //stop the underlying ssh thread that gets spawned if we use ssh if (params.ssh) { AsyncSshHandler.DEFAULT_CLIENT.stop(); } }
From source file:org.opendaylight.controller.netconf.test.tool.NetconfDeviceSimulator.java
License:Open Source License
public NetconfDeviceSimulator() { // TODO make pool size configurable this(new NioEventLoopGroup(), new HashedWheelTimer(), Executors.newScheduledThreadPool(8, new ThreadFactoryBuilder().setNameFormat("netconf-ssh-server-mina-timers-%d").build()), ThreadUtils.newFixedThreadPool("netconf-ssh-server-nio-group", 8)); }
From source file:org.opendaylight.controller.sal.connect.netconf.listener.NetconfDeviceCommunicatorTest.java
License:Open Source License
/** * Test whether reconnect is scheduled properly */// w ww. j ava2 s . co m @Test public void testNetconfDeviceReconnectInCommunicator() throws Exception { final RemoteDevice<NetconfSessionPreferences, NetconfMessage, NetconfDeviceCommunicator> device = mock( RemoteDevice.class); final TimedReconnectStrategy timedReconnectStrategy = new TimedReconnectStrategy( GlobalEventExecutor.INSTANCE, 10000, 0, 1.0, null, 100L, null); final ReconnectStrategy reconnectStrategy = spy(new ReconnectStrategy() { @Override public int getConnectTimeout() throws Exception { return timedReconnectStrategy.getConnectTimeout(); } @Override public Future<Void> scheduleReconnect(final Throwable cause) { return timedReconnectStrategy.scheduleReconnect(cause); } @Override public void reconnectSuccessful() { timedReconnectStrategy.reconnectSuccessful(); } }); final EventLoopGroup group = new NioEventLoopGroup(); final Timer time = new HashedWheelTimer(); try { final NetconfDeviceCommunicator listener = new NetconfDeviceCommunicator(new RemoteDeviceId("test"), device); final NetconfReconnectingClientConfiguration cfg = NetconfReconnectingClientConfigurationBuilder .create().withAddress(new InetSocketAddress("localhost", 65000)) .withReconnectStrategy(reconnectStrategy) .withConnectStrategyFactory(new ReconnectStrategyFactory() { @Override public ReconnectStrategy createReconnectStrategy() { return reconnectStrategy; } }).withAuthHandler(new LoginPassword("admin", "admin")).withConnectionTimeoutMillis(10000) .withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH) .withSessionListener(listener).build(); listener.initializeRemoteConnection(new NetconfClientDispatcherImpl(group, group, time), cfg); verify(reconnectStrategy, timeout((int) TimeUnit.MINUTES.toMillis(3)).times(101)) .scheduleReconnect(any(Throwable.class)); } finally { time.stop(); group.shutdownGracefully(); } }
From source file:org.opendaylight.netconf.impl.ConcurrentClientsTest.java
License:Open Source License
@Before public void setUp() throws Exception { hashedWheelTimer = new HashedWheelTimer(); nettyGroup = new NioEventLoopGroup(nettyThreads); netconfClientDispatcher = new NetconfClientDispatcherImpl(nettyGroup, nettyGroup, hashedWheelTimer); AggregatedNetconfOperationServiceFactory factoriesListener = new AggregatedNetconfOperationServiceFactory(); testingNetconfOperation = new TestingNetconfOperation(); factoriesListener// w ww.j av a 2s. c o m .onAddNetconfOperationServiceFactory(new TestingOperationServiceFactory(testingNetconfOperation)); SessionIdProvider idProvider = new SessionIdProvider(); NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactoryBuilder() .setTimer(hashedWheelTimer).setAggregatedOpService(factoriesListener).setIdProvider(idProvider) .setConnectionTimeoutMillis(5000).setMonitoringService(createMockedMonitoringService()) .setBaseCapabilities(serverCaps).build(); NetconfServerDispatcherImpl.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcherImpl.ServerChannelInitializer( serverNegotiatorFactory); final NetconfServerDispatcherImpl dispatch = new NetconfServerDispatcherImpl(serverChannelInitializer, nettyGroup, nettyGroup); ChannelFuture s = dispatch.createServer(netconfAddress); s.await(); }