Java Code Examples for io.netty.util.concurrent.Future#sync()
The following examples show how to use
io.netty.util.concurrent.Future#sync() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataCompressionHttp2Test.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
@After public void teardown() throws InterruptedException { if (clientChannel != null) { clientChannel.close().sync(); clientChannel = null; } if (serverChannel != null) { serverChannel.close().sync(); serverChannel = null; } final Channel serverConnectedChannel = this.serverConnectedChannel; if (serverConnectedChannel != null) { serverConnectedChannel.close().sync(); this.serverConnectedChannel = null; } Future<?> serverGroup = sb.config().group().shutdownGracefully(0, 0, MILLISECONDS); Future<?> serverChildGroup = sb.config().childGroup().shutdownGracefully(0, 0, MILLISECONDS); Future<?> clientGroup = cb.config().group().shutdownGracefully(0, 0, MILLISECONDS); serverGroup.sync(); serverChildGroup.sync(); clientGroup.sync(); }
Example 2
Source File: JdkSslEngineTest.java From netty4.0.27Learn with Apache License 2.0 | 6 votes |
@After public void tearDown() throws InterruptedException { if (serverChannel != null) { serverChannel.close().sync(); Future<?> serverGroup = sb.group().shutdownGracefully(0, 0, TimeUnit.MILLISECONDS); Future<?> serverChildGroup = sb.childGroup().shutdownGracefully(0, 0, TimeUnit.MILLISECONDS); Future<?> clientGroup = cb.group().shutdownGracefully(0, 0, TimeUnit.MILLISECONDS); serverGroup.sync(); serverChildGroup.sync(); clientGroup.sync(); } clientChannel = null; serverChannel = null; serverConnectedChannel = null; serverException = null; }
Example 3
Source File: EchoServer.java From netty.book.kor with MIT License | 6 votes |
public static void main(String[] args) throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) { ChannelPipeline p = ch.pipeline(); p.addLast(new EchoServerHandler()); } }); ChannelFuture f = b.bind(8888).sync(); f.channel().closeFuture().sync(); } finally { Future f1 = workerGroup.shutdownGracefully(); f1.sync(); Future f2 = bossGroup.shutdownGracefully(); f2.sync(); } }
Example 4
Source File: PCEPDispatcherImplTest.java From bgpcep with Eclipse Public License 1.0 | 6 votes |
@Test(timeout = 20000) public void testCreateDuplicateClient() throws InterruptedException { final int port = InetSocketAddressUtil.getRandomPort(); final InetSocketAddress serverAddr = new InetSocketAddress("0.0.0.0", port); final InetSocketAddress clientAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(port); doReturn(serverAddr).when(this.dispatcherDependencies).getAddress(); doReturn(this.listenerFactory).when(this.dispatcherDependencies).getListenerFactory(); doReturn(new SimpleSessionListener()).when(this.listenerFactory).getSessionListener(); this.dispatcher.createServer(this.dispatcherDependencies).sync(); final Future<PCEPSessionImpl> futureClient = this.pccMock.createClient(clientAddr, RETRY_TIMER, CONNECT_TIMEOUT, SimpleSessionListener::new); futureClient.sync(); try (PCEPSessionImpl ignored = futureClient.get()) { this.pccMock.createClient(clientAddr, RETRY_TIMER, CONNECT_TIMEOUT, SimpleSessionListener::new).get(); Assert.fail(); } catch (final ExecutionException e) { Assert.assertTrue(e.getMessage().contains("A conflicting session for address")); } }
Example 5
Source File: BGPDispatcherImplTest.java From bgpcep with Eclipse Public License 1.0 | 6 votes |
@Test(timeout = 20000) public void testCreateClient() throws InterruptedException, ExecutionException { final InetSocketAddress serverAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(); final Channel serverChannel = createServer(serverAddress); final Future<BGPSessionImpl> futureClient = this.clientDispatcher.createClient(this.clientAddress, serverAddress, 2, true); futureClient.sync(); final BGPSessionImpl session = futureClient.get(); Assert.assertEquals(State.UP, this.clientListener.getState()); Assert.assertEquals(State.UP, this.serverListener.getState()); Assert.assertEquals(AS_NUMBER, session.getAsNumber()); Assert.assertEquals(Sets.newHashSet(IPV_4_TT), session.getAdvertisedTableTypes()); Assert.assertTrue(serverChannel.isWritable()); session.close(); this.serverListener.releaseConnection(); checkIdleState(this.clientListener); checkIdleState(this.serverListener); }
Example 6
Source File: BootstrapTest.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Test(timeout = 10000) public void testBindDeadLock() throws Exception { final Bootstrap bootstrapA = new Bootstrap(); bootstrapA.group(groupA); bootstrapA.channel(LocalChannel.class); bootstrapA.handler(dummyHandler); final Bootstrap bootstrapB = new Bootstrap(); bootstrapB.group(groupB); bootstrapB.channel(LocalChannel.class); bootstrapB.handler(dummyHandler); List<Future<?>> bindFutures = new ArrayList<Future<?>>(); // Try to bind from each other. for (int i = 0; i < 1024; i ++) { bindFutures.add(groupA.next().submit(new Runnable() { @Override public void run() { bootstrapB.bind(LocalAddress.ANY); } })); bindFutures.add(groupB.next().submit(new Runnable() { @Override public void run() { bootstrapA.bind(LocalAddress.ANY); } })); } for (Future<?> f: bindFutures) { f.sync(); } }
Example 7
Source File: BootstrapTest.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Test(timeout = 10000) public void testConnectDeadLock() throws Exception { final Bootstrap bootstrapA = new Bootstrap(); bootstrapA.group(groupA); bootstrapA.channel(LocalChannel.class); bootstrapA.handler(dummyHandler); final Bootstrap bootstrapB = new Bootstrap(); bootstrapB.group(groupB); bootstrapB.channel(LocalChannel.class); bootstrapB.handler(dummyHandler); List<Future<?>> bindFutures = new ArrayList<Future<?>>(); // Try to connect from each other. for (int i = 0; i < 1024; i ++) { bindFutures.add(groupA.next().submit(new Runnable() { @Override public void run() { bootstrapB.connect(LocalAddress.ANY); } })); bindFutures.add(groupB.next().submit(new Runnable() { @Override public void run() { bootstrapA.connect(LocalAddress.ANY); } })); } for (Future<?> f: bindFutures) { f.sync(); } }
Example 8
Source File: NettyConnectionManager.java From stratosphere with Apache License 2.0 | 5 votes |
public void shutdown() { Future<?> inShutdownFuture = this.in.group().shutdownGracefully(); Future<?> outShutdownFuture = this.out.group().shutdownGracefully(); try { inShutdownFuture.sync(); outShutdownFuture.sync(); } catch (InterruptedException e) { throw new RuntimeException("Could not properly shutdown connections."); } }
Example 9
Source File: SSLEngineTest.java From netty-4.1.22 with Apache License 2.0 | 4 votes |
@After public void tearDown() throws InterruptedException { ChannelFuture clientCloseFuture = null; ChannelFuture serverConnectedCloseFuture = null; ChannelFuture serverCloseFuture = null; if (clientChannel != null) { clientCloseFuture = clientChannel.close(); clientChannel = null; } if (serverConnectedChannel != null) { serverConnectedCloseFuture = serverConnectedChannel.close(); serverConnectedChannel = null; } if (serverChannel != null) { serverCloseFuture = serverChannel.close(); serverChannel = null; } // We must wait for the Channel cleanup to finish. In the case if the ReferenceCountedOpenSslEngineTest // the ReferenceCountedOpenSslEngine depends upon the SslContext and so we must wait the cleanup the // SslContext to avoid JVM core dumps! // // See https://github.com/netty/netty/issues/5692 if (clientCloseFuture != null) { clientCloseFuture.sync(); } if (serverConnectedCloseFuture != null) { serverConnectedCloseFuture.sync(); } if (serverCloseFuture != null) { serverCloseFuture.sync(); } if (serverSslCtx != null) { cleanupServerSslContext(serverSslCtx); serverSslCtx = null; } if (clientSslCtx != null) { cleanupClientSslContext(clientSslCtx); clientSslCtx = null; } Future<?> serverGroupShutdownFuture = null; Future<?> serverChildGroupShutdownFuture = null; Future<?> clientGroupShutdownFuture = null; if (sb != null) { serverGroupShutdownFuture = sb.config().group().shutdownGracefully(0, 0, TimeUnit.MILLISECONDS); serverChildGroupShutdownFuture = sb.config().childGroup().shutdownGracefully(0, 0, TimeUnit.MILLISECONDS); } if (cb != null) { clientGroupShutdownFuture = cb.config().group().shutdownGracefully(0, 0, TimeUnit.MILLISECONDS); } if (serverGroupShutdownFuture != null) { serverGroupShutdownFuture.sync(); serverChildGroupShutdownFuture.sync(); } if (clientGroupShutdownFuture != null) { clientGroupShutdownFuture.sync(); } serverException = null; }
Example 10
Source File: BootstrapTest.java From netty4.0.27Learn with Apache License 2.0 | 4 votes |
@Test(timeout = 10000) public void testBindDeadLock() throws Exception { EventLoopGroup groupA = new LocalEventLoopGroup(1); EventLoopGroup groupB = new LocalEventLoopGroup(1); try { ChannelInboundHandler dummyHandler = new DummyHandler(); final Bootstrap bootstrapA = new Bootstrap(); bootstrapA.group(groupA); bootstrapA.channel(LocalChannel.class); bootstrapA.handler(dummyHandler); final Bootstrap bootstrapB = new Bootstrap(); bootstrapB.group(groupB); bootstrapB.channel(LocalChannel.class); bootstrapB.handler(dummyHandler); List<Future<?>> bindFutures = new ArrayList<Future<?>>(); // Try to bind from each other. for (int i = 0; i < 1024; i ++) { bindFutures.add(groupA.next().submit(new Runnable() { @Override public void run() { bootstrapB.bind(LocalAddress.ANY); } })); bindFutures.add(groupB.next().submit(new Runnable() { @Override public void run() { bootstrapA.bind(LocalAddress.ANY); } })); } for (Future<?> f: bindFutures) { f.sync(); } } finally { groupA.shutdownGracefully(); groupB.shutdownGracefully(); groupA.terminationFuture().sync(); groupB.terminationFuture().sync(); } }
Example 11
Source File: BootstrapTest.java From netty4.0.27Learn with Apache License 2.0 | 4 votes |
@Test(timeout = 10000) public void testConnectDeadLock() throws Exception { EventLoopGroup groupA = new LocalEventLoopGroup(1); EventLoopGroup groupB = new LocalEventLoopGroup(1); try { ChannelInboundHandler dummyHandler = new DummyHandler(); final Bootstrap bootstrapA = new Bootstrap(); bootstrapA.group(groupA); bootstrapA.channel(LocalChannel.class); bootstrapA.handler(dummyHandler); final Bootstrap bootstrapB = new Bootstrap(); bootstrapB.group(groupB); bootstrapB.channel(LocalChannel.class); bootstrapB.handler(dummyHandler); List<Future<?>> bindFutures = new ArrayList<Future<?>>(); // Try to connect from each other. for (int i = 0; i < 1024; i ++) { bindFutures.add(groupA.next().submit(new Runnable() { @Override public void run() { bootstrapB.connect(LocalAddress.ANY); } })); bindFutures.add(groupB.next().submit(new Runnable() { @Override public void run() { bootstrapA.connect(LocalAddress.ANY); } })); } for (Future<?> f: bindFutures) { f.sync(); } } finally { groupA.shutdownGracefully(); groupB.shutdownGracefully(); groupA.terminationFuture().sync(); groupB.terminationFuture().sync(); } }