List of usage examples for io.netty.util.concurrent Future sync
Future<V> sync() throws InterruptedException;
From source file:com.linecorp.armeria.client.ClientInvocationHandler.java
License:Apache License
private Object invokeClientMethod(Method method, Object[] args) throws Throwable { if (args == null) { args = NO_ARGS;// w ww . j a va 2 s . com } try { Future<Object> resultFuture = invoker().invoke(eventLoop(), uri, options, codec(), method, args); if (codec().isAsyncClient()) { return method.getReturnType().isInstance(resultFuture) ? resultFuture : null; } else { return resultFuture.sync().getNow(); } } catch (ClosedChannelException ignored) { throw ClosedSessionException.INSTANCE; } }
From source file:com.linecorp.armeria.server.AbstractServerTest.java
License:Apache License
protected static void stopServer(boolean await) throws Exception { synchronized (lock) { if (server == null) { return; }// w ww.ja va 2 s . c o m Future<Void> future = server.stop(); server = null; if (await) { future.sync(); } } }
From source file:com.whizzosoftware.hobson.api.plugin.channel.AbstractChannelObjectPlugin.java
License:Open Source License
private void closeEventLoopGroup() { // shutdown the event loop group if there is one if (connectionEventLoopGroup != null) { logger.debug("Closing event loop group"); Future f = connectionEventLoopGroup.shutdownGracefully(); try {//from w w w . j a va 2 s . c o m f.sync(); } catch (InterruptedException ignored) { } logger.debug("Event loop group closed"); } }
From source file:eu.stratosphere.runtime.io.network.netty.NettyConnectionManager.java
License:Apache License
public void shutdown() { Future<?> inShutdownFuture = this.in.group().shutdownGracefully(); Future<?> outShutdownFuture = this.out.group().shutdownGracefully(); try {//from w w w . j a v a 2 s .co m inShutdownFuture.sync(); outShutdownFuture.sync(); } catch (InterruptedException e) { throw new RuntimeException("Could not properly shutdown connections."); } }
From source file:io.atomix.cluster.messaging.impl.NettyMessagingService.java
License:Apache License
@Override public CompletableFuture<Void> stop() { if (started.compareAndSet(true, false)) { return CompletableFuture.supplyAsync(() -> { boolean interrupted = false; try { try { serverChannel.close().sync(); } catch (InterruptedException e) { interrupted = true;// w w w .ja va 2 s . co m } Future<?> serverShutdownFuture = serverGroup.shutdownGracefully(); Future<?> clientShutdownFuture = clientGroup.shutdownGracefully(); try { serverShutdownFuture.sync(); } catch (InterruptedException e) { interrupted = true; } try { clientShutdownFuture.sync(); } catch (InterruptedException e) { interrupted = true; } timeoutFuture.cancel(false); timeoutExecutor.shutdown(); } finally { log.info("Stopped"); if (interrupted) { Thread.currentThread().interrupt(); } } return null; }); } return CompletableFuture.completedFuture(null); }
From source file:io.codis.nedis.TestNedis.java
License:Apache License
@Test public void test() throws InterruptedException, ExecutionException { pool = NedisClientPoolBuilder.create().remoteAddress(new InetSocketAddress("127.0.0.1", PORT)) .clientName("test").build(); NedisClient client = NedisUtils.newPooledClient(pool); System.out.println(client.toString()); Future<String> pingFuture = client.ping(); for (int i = 0; i < 1000; i++) { Future<Boolean> setFuture = client.set(toBytes("foo"), toBytes("bar" + i)); assertTrue(setFuture.sync().getNow()); assertEquals("bar" + i, bytesToString(client.get(toBytes("foo")).sync().getNow())); }//from w ww. ja va 2 s . co m assertEquals("PONG", pingFuture.sync().getNow()); assertEquals(null, client.get(toBytes("bar")).sync().getNow()); NedisClient pipelineClient = pool.acquire().sync().getNow(); Future<Long> incrFuture = pipelineClient.incr(toBytes("num")); Future<Long> incrByFuture = pipelineClient.incrby(toBytes("num"), 2L); Future<Long> decrFuture = pipelineClient.decr(toBytes("num")); Future<Long> decrByFuture = pipelineClient.decrby(toBytes("num"), 2L); assertEquals(1L, incrFuture.sync().getNow().longValue()); assertEquals(3L, incrByFuture.sync().getNow().longValue()); assertEquals(2L, decrFuture.sync().getNow().longValue()); assertEquals(0L, decrByFuture.sync().getNow().longValue()); pipelineClient.release(); client.mset(toBytes("a1"), toBytes("b1"), toBytes("a2"), toBytes("b2")).sync(); List<byte[]> resp = client.mget(toBytes("a1"), toBytes("a2"), toBytes("a3")).sync().getNow(); assertEquals(3, resp.size()); assertEquals("b1", bytesToString(resp.get(0))); assertEquals("b2", bytesToString(resp.get(1))); assertEquals(null, resp.get(2)); assertEquals(pool.numConns(), pool.numPooledConns()); int numConns = pool.numConns(); Throwable error = client.execCmd(GET.raw).await().cause(); error.printStackTrace(); assertTrue(error instanceof RedisResponseException); // this error does not cause a connection closing. assertEquals(numConns, pool.numConns()); assertEquals(numConns, pool.numPooledConns()); client.close().sync(); assertEquals(0, pool.numPooledConns()); assertEquals(0, pool.numConns()); }
From source file:io.codis.nedis.TestNedis.java
License:Apache License
@Test public void testBlockingCommands() throws InterruptedException { pool = NedisClientPoolBuilder.create().remoteAddress(new InetSocketAddress("127.0.0.1", PORT)) .timeoutMs(100).exclusive(true).build(); NedisClient client = NedisUtils.newPooledClient(pool); Future<List<byte[]>> brpopFuture = client.brpop(100, toBytes("foo")); Thread.sleep(1000);/*from w w w . ja va2 s .co m*/ assertFalse(brpopFuture.isDone()); client.lpush(toBytes("foo"), toBytes("bar")); List<byte[]> brpopResp = brpopFuture.sync().getNow(); assertEquals(2, brpopResp.size()); assertEquals("foo", bytesToString(brpopResp.get(0))); assertEquals("bar", bytesToString(brpopResp.get(1))); Future<List<byte[]>> blpopFuture = client.blpop(100, toBytes("a1")); Future<byte[]> brpoplpushFuture = client.brpoplpush(toBytes("a2"), toBytes("a1"), 100); Thread.sleep(1000); assertFalse(blpopFuture.isDone()); assertFalse(brpoplpushFuture.isDone()); client.lpush(toBytes("a2"), toBytes("b")); List<byte[]> blpopResp = blpopFuture.sync().getNow(); assertEquals(2, blpopResp.size()); assertEquals("a1", bytesToString(blpopResp.get(0))); assertEquals("b", bytesToString(blpopResp.get(1))); assertTrue(brpoplpushFuture.isDone()); assertEquals("b", bytesToString(brpoplpushFuture.getNow())); }
From source file:io.liveoak.container.server.AbstractServer.java
License:Open Source License
/** * Synchronously stop the network listener. * * @throws InterruptedException If interrupted before completely stopping. *//*from w w w . j ava2s.co m*/ public void stop() throws InterruptedException { Future<?> future = eventLoopGroup().shutdownGracefully(); future.sync(); }
From source file:io.liveoak.stomp.server.SimpleStompServer.java
License:Open Source License
public void stop() throws InterruptedException { Future<?> future = this.group.shutdownGracefully(); future.sync(); }
From source file:me.ferrybig.javacoding.teamspeakconnector.TeamspeakConnectionIT.java
@Test public void testSomeMethod() throws InterruptedException, ExecutionException { Logger.getGlobal().getParent().setLevel(Level.ALL); Logger.getLogger(TeamspeakConnection.class.getName()).setLevel(Level.ALL); NioEventLoopGroup group = new NioEventLoopGroup(); try {//from w ww.j a v a 2 s . c o m System.out.println("Creating!"); TeamspeakApi api = new TeamspeakApi(group); Future<TeamspeakConnection> connect = api.connect(new InetSocketAddress("127.0.0.1", 10011), "serveradmin", "test1234"); System.out.println("Connected!"); TeamspeakConnection con = connect.sync().get(); System.out.println("Selecting server!"); con.getUnresolvedServerById(1).select().sync().get(); System.out.println("Creating!"); con.getServer(); con.getServer(); // con.getServer(); // con.getServer(); // con.getServer(); // con.getServer(); // con.getServer(); // con.getServer(); // con.getServer(); // con.getServer(); // con.getServer(); // con.getServer(); // con.getServer(); // con.getServer(); System.out.println("Queue make!"); System.out.println(con.getServer().sync().get()); System.out.println("Username seting...."); con.setOwnName("TestingBot").sync().get(); System.out.println("User list!"); List<User> users = con.getUsersList().sync().get(); for (User user : users) { if (user.getType() == ClientType.QUERY) { continue; } user.poke("Hello: " + user.getNickname() + ", Your ip address: " + user.getIp()); user.sendMessage("Hello: " + user.getNickname() + ", Your ip address: " + user.getIp()); } System.out.println("Waiting for messages!"); con.getPrivateMessageHandler().addHandler(evt -> { System.out.println("Message received! " + evt); evt.getInvoker().sendMessage("You said: " + evt.getMessage()); }); System.out.println("Waiting for eserver events!"); con.getServerHandler().addHandler(new ServerListener() { @Override public void onClientEnterView(ClientEnterViewEvent event) { LOG.log(Level.INFO, "ClientEnterViewEvent: {0}", event); event.getClient().sendMessage("Hello " + event.getClient().getNickname() + "!"); event.getClient().getChannel().resolv().addListener((Future<Channel> channel) -> { event.getClient().sendMessage("Welcome to channel " + channel.get().getName() + "!"); }); } @Override public void onClientLeaveView(ClientLeftViewEvent event) { LOG.log(Level.INFO, "ClientLeftViewEvent: {0}", event); } @Override public void onEditServer(ServerEditEvent event) { LOG.log(Level.INFO, "ServerEditEvent: {0}", event); } }); Thread.sleep(100000); System.out.println("Closing...!"); con.quit().sync().get(); } finally { group.shutdownGracefully(); } }