Example usage for io.netty.channel ChannelFuture await

List of usage examples for io.netty.channel ChannelFuture await

Introduction

In this page you can find the example usage for io.netty.channel ChannelFuture await.

Prototype

@Override
    ChannelFuture await() throws InterruptedException;

Source Link

Usage

From source file:org.onesec.raven.rtp.RtpInboundHandlerTest.java

License:Apache License

@Test
public void test() throws Exception {
    NioEventLoopGroup group = new NioEventLoopGroup(4);
    Bootstrap serverBootstrap = createServerBootstrap(group);
    Bootstrap clientBootstrap = createClientBootstrap(group);

    ChannelFuture future = serverBootstrap.bind(Inet4Address.getLocalHost(), BIND_PORT);
    future.await();
    serverChannel = future.channel();/*from   www .  j  a  va 2  s .c  om*/
    RtpInboundHandler handler = serverChannel.pipeline().get(RtpInboundHandler.class);
    assertNotNull(handler);
    handler.getInStream().setTransferHandler(new Handler());

    //        ChannelFuture clientFuture = clientBootstrap.connect(Inet4Address.getLocalHost(), BIND_PORT);
    ChannelFuture clientFuture = clientBootstrap.bind(Inet4Address.getLocalHost(), BIND_PORT + 1);
    clientChannel = clientFuture.await().channel();
    assertNotNull(clientChannel);
    InetSocketAddress addr = new InetSocketAddress(localhost, BIND_PORT);
    ByteBuf writeBuf = clientChannel.alloc().buffer(5).writeBytes(TEST_BUFFER);
    clientChannel.writeAndFlush(new DatagramPacket(writeBuf, addr)).addListener(new GenericFutureListener() {
        public void operationComplete(Future future) throws Exception {
            clientChannel.close();
        }
    });

    serverChannel.closeFuture().await();
    assertNotNull(receivedBuffer.get());
    assertArrayEquals(TEST_BUFFER, receivedBuffer.get());

}

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  ww  w  .  j a  v  a 2 s. co  m*/
            .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.it.NetconfConfigPersisterITTest.java

License:Open Source License

@Before
public void setUp() throws Exception {
    super.initConfigTransactionManagerImpl(
            new HardcodedModuleFactoriesResolver(mockedContext, NetconfITTest.FACTORIES));

    NetconfMonitoringServiceImpl monitoringService = new NetconfMonitoringServiceImpl(
            getNetconfOperationProvider());

    NetconfOperationServiceFactoryListenerImpl factoriesListener = new NetconfOperationServiceFactoryListenerImpl();
    factoriesListener/* ww  w . j  a v  a  2  s.  com*/
            .onAddNetconfOperationServiceFactory(new NetconfOperationServiceFactoryImpl(getYangStore()));
    factoriesListener.onAddNetconfOperationServiceFactory(
            new NetconfMonitoringActivator.NetconfMonitoringOperationServiceFactory(
                    new NetconfMonitoringOperationService(monitoringService)));

    commitNotifier = new DefaultCommitNotificationProducer(platformMBeanServer);
    NetconfServerDispatcher dispatch = createDispatcher(factoriesListener, mockSessionMonitoringService(),
            commitNotifier);
    ChannelFuture s = dispatch.createServer(tcpAddress);
    s.await();

    clientDispatcher = new NetconfClientDispatcherImpl(getNettyThreadgroup(), getNettyThreadgroup(),
            getHashedWheelTimer());
}

From source file:org.opendaylight.controller.netconf.it.NetconfITTest.java

License:Open Source License

@Before
public void setUp() throws Exception {
    initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext, FACTORIES));

    loadMessages();//from  w  ww.  ja  va  2s.  c  o m

    NetconfOperationServiceFactoryListenerImpl factoriesListener = new NetconfOperationServiceFactoryListenerImpl();
    factoriesListener
            .onAddNetconfOperationServiceFactory(new NetconfOperationServiceFactoryImpl(getYangStore()));

    commitNotificationProducer = new DefaultCommitNotificationProducer(
            ManagementFactory.getPlatformMBeanServer());

    dispatch = createDispatcher(factoriesListener);
    ChannelFuture s = dispatch.createServer(tcpAddress);
    s.await();

    clientDispatcher = new NetconfClientDispatcherImpl(getNettyThreadgroup(), getNettyThreadgroup(),
            getHashedWheelTimer());
}

From source file:org.opendaylight.controller.netconf.it.NetconfMonitoringITTest.java

License:Open Source License

@Before
public void setUp() throws Exception {
    super.initConfigTransactionManagerImpl(
            new HardcodedModuleFactoriesResolver(mockedContext, NetconfITTest.FACTORIES));

    monitoringService = new NetconfMonitoringServiceImpl(getNetconfOperationProvider());

    NetconfOperationServiceFactoryListenerImpl factoriesListener = new NetconfOperationServiceFactoryListenerImpl();
    factoriesListener/*w w w  . j av a  2  s  . c om*/
            .onAddNetconfOperationServiceFactory(new NetconfOperationServiceFactoryImpl(getYangStore()));
    factoriesListener.onAddNetconfOperationServiceFactory(
            new NetconfMonitoringActivator.NetconfMonitoringOperationServiceFactory(
                    new NetconfMonitoringOperationService(monitoringService)));

    dispatch = createDispatcher(factoriesListener);
    ChannelFuture s = dispatch.createServer(tcpAddress);
    s.await();

    clientDispatcher = new NetconfClientDispatcherImpl(getNettyThreadgroup(), getNettyThreadgroup(),
            getHashedWheelTimer());
}

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  w  w.  j a  va2 s.com
            .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();
}

From source file:org.rzo.netty.ahessian.heartbeat.ClientHeartbeatHandlerOutbound.java

License:Apache License

@Override
public void timedOut(ChannelHandlerContext ctx) {
    Constants.ahessianLogger/*ww  w  .j  ava2 s .  co  m*/
            .info("no writes since " + new Date(_handler.getLastCalled()) + " -> send empty buffer heartbeat");
    ByteBuf b = ctx.alloc().buffer(1);
    b.writeByte(0);
    ChannelFuture f = ctx.writeAndFlush(b);
    try {
        f.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:org.rzo.yajsw.app.WrapperManagerImpl.java

License:Apache License

public void signalStopping(int timeoutHint) {
    try {/*w  w w.  j a va2  s.co m*/
        if (_session == null || !_session.isActive()) {
            final ChannelFuture future1 = connector.connect();
            future1.await();
            future1.isSuccess();
            _session = future1.channel();
        }
        ChannelFuture wFuture = _session
                .writeAndFlush(new Message(Constants.WRAPPER_MSG_STOP_PENDING, String.valueOf(timeoutHint)));
        wFuture.await();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        _session.close();
        _session = null;
    }

}

From source file:org.teiid.transport.SocketListener.java

License:Apache License

/**
 * Stops the {@link SocketListener}//from w w w. ja  va 2  s  . c  om
 * @return a Future if the transport was started successfully
 * that can notify of successfully killing all clients
 */
public Future<?> stop() {
    ChannelFuture future = this.serverChannel.closeFuture();
    Future<?> shutdown = null;
    if (this.bootstrap != null) {
        shutdown = bootstrap.config().group().shutdownGracefully(0, 0, TimeUnit.SECONDS);
        bootstrap = null;
    }
    try {
        future.await();
    } catch (InterruptedException e) {
        throw new TeiidRuntimeException(e);
    }
    return shutdown;
}

From source file:org.thingsplode.synapse.endpoint.Endpoint.java

License:Apache License

/**
 *
 * @throws InterruptedException/*from w  w  w  .j  av a  2 s.co  m*/
 */
private void startInternal() throws InterruptedException {
    for (SocketAddress addr : connections.getSocketAddresses()) {
        ChannelFuture channelFuture = bootstrap.bind(addr).sync();
        Channel channel = channelFuture.await().channel();
        channelRegistry.add(channel);
        //channelFuture.channel().closeFuture().sync();
    }
    lifecycle = ComponentLifecycle.INITIALIZED;
    logger.info("Endpoint [" + endpointId + "] started.");
}