List of usage examples for io.netty.util HashedWheelTimer HashedWheelTimer
public HashedWheelTimer()
From source file:org.opendaylight.netconf.impl.NetconfDispatcherImplTest.java
License:Open Source License
@Before public void setUp() throws Exception { nettyGroup = new NioEventLoopGroup(); AggregatedNetconfOperationServiceFactory factoriesListener = new AggregatedNetconfOperationServiceFactory(); SessionIdProvider idProvider = new SessionIdProvider(); hashedWheelTimer = new HashedWheelTimer(); NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactoryBuilder() .setAggregatedOpService(factoriesListener).setTimer(hashedWheelTimer).setIdProvider(idProvider) .setMonitoringService(ConcurrentClientsTest.createMockedMonitoringService()) .setConnectionTimeoutMillis(5000).build(); NetconfServerDispatcherImpl.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcherImpl.ServerChannelInitializer( serverNegotiatorFactory);//from www . j a v a 2s . c om dispatch = new NetconfServerDispatcherImpl(serverChannelInitializer, nettyGroup, nettyGroup); }
From source file:org.opendaylight.netconf.impl.osgi.NetconfImplActivator.java
License:Open Source License
@Override public void start(final BundleContext context) { try {/*from ww w.j av a 2s.c om*/ AggregatedNetconfOperationServiceFactory factoriesListener = new AggregatedNetconfOperationServiceFactory(); startOperationServiceFactoryTracker(context, factoriesListener); SessionIdProvider idProvider = new SessionIdProvider(); timer = new HashedWheelTimer(); long connectionTimeoutMillis = NetconfConfigUtil.extractTimeoutMillis(context); final NetconfMonitoringServiceImpl monitoringService = startMonitoringService(context, factoriesListener); NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactoryBuilder() .setAggregatedOpService(factoriesListener).setTimer(timer).setIdProvider(idProvider) .setMonitoringService(monitoringService).setConnectionTimeoutMillis(connectionTimeoutMillis) .build(); eventLoopGroup = new NioEventLoopGroup(); ServerChannelInitializer serverChannelInitializer = new ServerChannelInitializer( serverNegotiatorFactory); NetconfServerDispatcherImpl dispatch = new NetconfServerDispatcherImpl(serverChannelInitializer, eventLoopGroup, eventLoopGroup); LocalAddress address = NetconfConfigUtil.getNetconfLocalAddress(); LOG.trace("Starting local netconf server at {}", address); dispatch.createLocalServer(address); final ServiceTracker<NetconfNotificationCollector, NetconfNotificationCollector> notificationServiceTracker = new ServiceTracker<>( context, NetconfNotificationCollector.class, new ServiceTrackerCustomizer<NetconfNotificationCollector, NetconfNotificationCollector>() { @Override public NetconfNotificationCollector addingService( ServiceReference<NetconfNotificationCollector> reference) { Preconditions.checkState(listenerReg == null, "Notification collector service was already added"); listenerReg = context.getService(reference).registerBaseNotificationPublisher(); monitoringService.setNotificationPublisher(listenerReg); return null; } @Override public void modifiedService(ServiceReference<NetconfNotificationCollector> reference, NetconfNotificationCollector service) { } @Override public void removedService(ServiceReference<NetconfNotificationCollector> reference, NetconfNotificationCollector service) { listenerReg.close(); listenerReg = null; monitoringService.setNotificationPublisher(listenerReg); } }); notificationServiceTracker.open(); } catch (Exception e) { LOG.warn("Unable to start NetconfImplActivator", e); } }
From source file:org.opendaylight.netconf.it.AbstractNetconfConfigTest.java
License:Open Source License
/** * @Before in subclasses is called after this method. *//*from www.ja v a 2s. co 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); configSubsystemFacadeFactory = new ConfigSubsystemFacadeFactory(configRegistryClient, configRegistryClient, getYangStore()); factoriesListener.onAddNetconfOperationServiceFactory( new NetconfOperationServiceFactoryImpl(configSubsystemFacadeFactory)); 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.netconf.nettyutil.AbstractNetconfSessionNegotiatorTest.java
License:Open Source License
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); channel = new EmbeddedChannel(); xmlToHello = new NetconfXMLToHelloMessageDecoder(); channel.pipeline().addLast(AbstractChannelInitializer.NETCONF_MESSAGE_ENCODER, new ChannelInboundHandlerAdapter()); channel.pipeline().addLast(AbstractChannelInitializer.NETCONF_MESSAGE_DECODER, xmlToHello); channel.pipeline().addLast(NETCONF_MESSAGE_FRAME_ENCODER, FramingMechanismHandlerFactory.createHandler(FramingMechanism.EOM)); channel.pipeline().addLast(NETCONF_MESSAGE_AGGREGATOR, new NetconfEOMAggregator()); hello = NetconfHelloMessage.createClientHello(Collections.emptySet(), Optional.absent()); helloBase11 = NetconfHelloMessage.createClientHello( Collections.singleton(XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_1), Optional.absent()); prefs = new NetconfSessionPreferences(helloBase11); doReturn(promise).when(promise).setFailure(any()); doReturn(promise).when(promise).setSuccess(any()); negotiator = new TestSessionNegotiator(prefs, promise, channel, new HashedWheelTimer(), listener, 100L); }
From source file:org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicatorTest.java
License:Open Source License
/** * Test whether reconnect is scheduled properly *///from ww w.j a v a 2s . c o 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", InetSocketAddress.createUnresolved("localhost", 22)), device, 10); 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.test.tool.client.stress.StressClient.java
License:Open Source License
public static void main(final String[] args) { params = parseArgs(args, Parameters.getParser()); params.validate();// w ww .j a v a2 s . co 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.netconf.test.tool.NetconfDeviceSimulator.java
License:Open Source License
public NetconfDeviceSimulator(final int ThreadPoolSize) { this(new NioEventLoopGroup(), new HashedWheelTimer(), Executors.newScheduledThreadPool(ThreadPoolSize, new ThreadFactoryBuilder().setNameFormat("netconf-ssh-server-mina-timers-%d").build()), ThreadUtils.newFixedThreadPool("netconf-ssh-server-nio-group", ThreadPoolSize)); }
From source file:org.opendaylight.netvirt.ipv6service.utils.Ipv6TimerWheel.java
License:Open Source License
private Ipv6TimerWheel() { ipv6PeriodicRATimerWheel = new HashedWheelTimer(); }
From source file:org.opendaylight.openflowplugin.impl.device.DeviceManagerImplTest.java
License:Open Source License
private DeviceManagerImpl prepareDeviceManager() { final DataBroker mockedDataBroker = mock(DataBroker.class); final WriteTransaction mockedWriteTransaction = mock(WriteTransaction.class); final BindingTransactionChain mockedTxChain = mock(BindingTransactionChain.class); final WriteTransaction mockedWTx = mock(WriteTransaction.class); when(mockedTxChain.newWriteOnlyTransaction()).thenReturn(mockedWTx); when(mockedDataBroker.createTransactionChain(any(TransactionChainListener.class))) .thenReturn(mockedTxChain);/* w w w. ja v a2 s. c om*/ when(mockedDataBroker.newWriteOnlyTransaction()).thenReturn(mockedWriteTransaction); when(mockedWriteTransaction.submit()).thenReturn(mockedFuture); final DeviceManagerImpl deviceManager = new DeviceManagerImpl(mockedDataBroker, TEST_VALUE_GLOBAL_NOTIFICATION_QUOTA, false, barrierIntervalNanos, barrierCountLimit, messageIntelligenceAgency, true, clusterSingletonServiceProvider, null, new HashedWheelTimer(), convertorExecutor, false); deviceManager.setDeviceInitializationPhaseHandler(deviceInitPhaseHandler); deviceManager.setDeviceTerminationPhaseHandler(deviceTerminationPhaseHandler); return deviceManager; }
From source file:org.opendaylight.openflowplugin.impl.role.RoleManagerImplTest.java
License:Open Source License
@Before public void setUp() throws Exception { CheckedFuture<Void, TransactionCommitFailedException> future = Futures.immediateCheckedFuture(null); Mockito.when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext); Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState); Mockito.when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo); Mockito.when(deviceContext.getMessageSpy()).thenReturn(messageSpy); Mockito.when(deviceContext.getPrimaryConnectionContext().getOutboundQueueProvider()) .thenReturn(outboundQueue);// ww w . j a v a 2 s . com Mockito.when(connectionContext.getFeatures()).thenReturn(featuresReply); Mockito.when(connectionContext.getNodeId()).thenReturn(nodeId); Mockito.when(connectionContext.getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.WORKING); Mockito.when(deviceInfo.getDatapathId()).thenReturn(new BigInteger("1")); Mockito.when(deviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3); Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeId); Mockito.doNothing().when(deviceInitializationPhaseHandler).onDeviceContextLevelUp(Mockito.<DeviceInfo>any(), Mockito.<LifecycleService>any()); Mockito.doNothing().when(deviceTerminationPhaseHandler).onDeviceContextLevelDown(Mockito.<DeviceInfo>any()); Mockito.when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction); Mockito.when(writeTransaction.submit()).thenReturn(future); Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeId); Mockito.when(deviceInfo2.getNodeId()).thenReturn(nodeId2); Mockito.when(deviceInfo.getDatapathId()).thenReturn(BigInteger.TEN); Mockito.when(deviceInfo.getNodeInstanceIdentifier()) .thenReturn(DeviceStateUtil.createNodeInstanceIdentifier(nodeId)); Mockito.when(lifecycleService.getDeviceContext()).thenReturn(deviceContext); roleManager = new RoleManagerImpl(dataBroker, new HashedWheelTimer()); roleManager.setDeviceInitializationPhaseHandler(deviceInitializationPhaseHandler); roleManager.setDeviceTerminationPhaseHandler(deviceTerminationPhaseHandler); roleManagerSpy = Mockito.spy(roleManager); roleManagerSpy.onDeviceContextLevelUp(deviceInfo, lifecycleService); roleContextSpy = Mockito.spy(roleManager.getRoleContext(deviceInfo)); Mockito.when(roleContextSpy.getDeviceInfo()).thenReturn(deviceInfo); Mockito.when(roleContextSpy.getDeviceInfo().getNodeId()).thenReturn(nodeId); inOrder = Mockito.inOrder(roleManagerSpy, roleContextSpy); }