List of usage examples for io.netty.util.concurrent Future isSuccess
boolean isSuccess();
From source file:io.codis.nedis.PromiseConverter.java
License:Apache License
public static PromiseConverter<List<Boolean>> toBooleanList(EventExecutor executor) { return new PromiseConverter<List<Boolean>>(executor) { @Override/*from ww w. j a v a 2 s.c o m*/ public FutureListener<Object> newListener(final Promise<List<Boolean>> promise) { return new FutureListener<Object>() { @Override public void operationComplete(Future<Object> future) throws Exception { if (future.isSuccess()) { Object resp = future.getNow(); if (resp instanceof RedisResponseException) { promise.tryFailure((RedisResponseException) resp); } else if (resp == RedisResponseDecoder.NULL_REPLY) { promise.trySuccess(null); } else { @SuppressWarnings("unchecked") List<Long> rawValueList = (List<Long>) resp; List<Boolean> values = new ArrayList<>(rawValueList.size()); for (long l : rawValueList) { values.add(l != 0L); } promise.trySuccess(values); } } else { promise.tryFailure(future.cause()); } } }; } }; }
From source file:io.codis.nedis.PromiseConverter.java
License:Apache License
public static PromiseConverter<List<Object>> toObjectList(EventExecutor executor) { return new PromiseConverter<List<Object>>(executor) { @Override/*from w ww . j a v a 2 s . com*/ public FutureListener<Object> newListener(final Promise<List<Object>> promise) { return new FutureListener<Object>() { @SuppressWarnings("unchecked") @Override public void operationComplete(Future<Object> future) throws Exception { if (future.isSuccess()) { Object resp = future.getNow(); if (resp instanceof RedisResponseException) { promise.tryFailure((RedisResponseException) resp); } else if (resp == RedisResponseDecoder.NULL_REPLY) { promise.trySuccess(null); } else { promise.trySuccess((List<Object>) resp); } } else { promise.tryFailure(future.cause()); } } }; } }; }
From source file:io.codis.nedis.TestNedis.java
License:Apache License
@Test public void testTimeout() throws InterruptedException { pool = NedisClientPoolBuilder.create().remoteAddress(new InetSocketAddress("127.0.0.1", PORT)).database(1) .build();/*from www . j av a 2 s . c o m*/ NedisClient client = pool.acquire().sync().getNow(); Thread.sleep(1000); assertEquals(1, pool.numPooledConns()); assertEquals(1, pool.numConns()); assertEquals(0L, client.setTimeout(100).sync().getNow().longValue()); Future<?> future = client.blpop(1, toBytes("foo")).await(); assertFalse(future.isSuccess()); assertTrue(future.cause() instanceof ReadTimeoutException); Thread.sleep(1000); assertEquals(0, pool.numPooledConns()); assertEquals(0, pool.numConns()); }
From source file:io.flood.rpc.FloodServer.java
License:Apache License
@Override public void onBindCompleted(Future<? super Void> completefuture) { if (completefuture.isSuccess()) { bindCompleted = true;//from ww w .j av a 2 s.c om Map<String, Service> serviceMap = dispatcher.getServices(); for (Map.Entry<String, Service> entry : serviceMap.entrySet()) { try { registServiceToRemote(entry.getValue()); } catch (Exception e) { LOG.warn(format(getId(), "buid service instance faild({})", entry.getValue().getDescriptorForType().getFullName())); } } Map<String, BlockingService> blockingServiceMap = dispatcher.getBlockingServices(); for (Map.Entry<String, BlockingService> entry : blockingServiceMap.entrySet()) { try { registServiceToRemote(entry.getValue()); } catch (Exception e) { LOG.warn(format(getId(), "buid service instance faild({})", entry.getValue().getDescriptorForType().getFullName())); } } } else { LOG.error(format(getId(), "start rpc server faild({})", completefuture.cause().getMessage())); } }
From source file:io.flood.rpc.network.ConnectorImpl.java
License:Apache License
private ChannelFuture connect0(final SocketAddress address, final int retryTime) { id = SocketIdGenerator.nextId();/*from ww w . ja v a2s .c o m*/ final ChannelFuture future = boot.connect(address); future.addListener(new GenericFutureListener<Future<? super Void>>() { public void operationComplete(io.netty.util.concurrent.Future<? super Void> completeFuture) throws Exception { broadcastComplete(future); if (completeFuture.isSuccess()) { channel = future.channel(); LOG.info(LogHelper.format(id, "connected to server ({}=>{})"), channel.localAddress(), channel.remoteAddress()); ConnectionManager.put(id, Connection.Type.Client, channel); future.channel().closeFuture().addListener(new GenericFutureListener<Future<? super Void>>() { public void operationComplete(Future<? super Void> completeFuture) throws Exception { LOG.info( LogHelper.format(id, "connection closed ,after {} millisecond will be reconnect"), retryTime); if (!isInitiative.get()) { Thread.sleep(retryTime); connect0(address, retryTime); } } }); } else { LOG.info(LogHelper.format(id, "connet to server failed({})"), address); } } }); return future; }
From source file:io.gatling.http.client.impl.DefaultHttpClient.java
License:Apache License
private void sendTx(HttpTx tx, EventLoop eventLoop) { EventLoopResources resources = eventLoopResources(eventLoop); Request request = tx.request; HttpListener listener = tx.listener; RequestTimeout requestTimeout = tx.requestTimeout; // use a fresh channel for WebSocket Channel pooledChannel = request.getUri().isWebSocket() ? null : resources.channelPool.poll(tx.key); if (pooledChannel != null) { sendTxWithChannel(tx, pooledChannel); } else {// w w w . j a va2 s. co m resolveRemoteAddresses(request, eventLoop, listener, requestTimeout) .addListener((Future<List<InetSocketAddress>> whenRemoteAddresses) -> { if (requestTimeout.isDone()) { return; } if (whenRemoteAddresses.isSuccess()) { List<InetSocketAddress> addresses = whenRemoteAddresses.getNow(); if (request.isHttp2Enabled()) { String domain = tx.request.getUri().getHost(); Channel coalescedChannel = resources.channelPool .pollCoalescedChannel(tx.key.clientId, domain, addresses); if (coalescedChannel != null) { tx.listener.onProtocolAwareness(true); sendTxWithChannel(tx, coalescedChannel); } else { sendTxWithNewChannel(tx, resources, eventLoop, addresses); } } else { sendTxWithNewChannel(tx, resources, eventLoop, addresses); } } }); } }
From source file:io.gatling.http.client.impl.DefaultHttpClient.java
License:Apache License
private void sendHttp2Txs(List<HttpTx> txs, EventLoop eventLoop) { HttpTx tx = txs.get(0);/* ww w .j a v a2 s .c om*/ EventLoopResources resources = eventLoopResources(eventLoop); Request request = tx.request; HttpListener listener = tx.listener; RequestTimeout requestTimeout = tx.requestTimeout; resolveRemoteAddresses(request, eventLoop, listener, requestTimeout) .addListener((Future<List<InetSocketAddress>> whenRemoteAddresses) -> { if (requestTimeout.isDone()) { return; } if (whenRemoteAddresses.isSuccess()) { List<InetSocketAddress> addresses = whenRemoteAddresses.getNow(); String domain = tx.request.getUri().getHost(); Channel coalescedChannel = resources.channelPool.pollCoalescedChannel(tx.key.clientId, domain, addresses); if (coalescedChannel != null) { sendHttp2TxsWithChannel(txs, coalescedChannel); } else { sendHttp2TxsWithNewChannel(txs, resources, eventLoop, addresses); } } }); }
From source file:io.gatling.http.client.impl.DefaultHttpClient.java
License:Apache License
private Future<List<InetSocketAddress>> resolveRemoteAddresses(Request request, EventLoop eventLoop, HttpListener listener, RequestTimeout requestTimeout) { if (!request.getUri().isSecured() && request.getProxyServer() instanceof HttpProxyServer) { // directly connect to proxy over clear HTTP InetSocketAddress remoteAddress = ((HttpProxyServer) request.getProxyServer()).getAddress(); return ImmediateEventExecutor.INSTANCE.newSucceededFuture(singletonList(remoteAddress)); } else {/* w ww. j av a 2 s. c o m*/ Promise<List<InetSocketAddress>> p = eventLoop.newPromise(); request.getNameResolver().resolveAll(request.getUri().getHost(), eventLoop.newPromise()) .addListener((Future<List<InetAddress>> whenAddresses) -> { if (whenAddresses.isSuccess()) { List<InetSocketAddress> remoteInetSocketAddresses = whenAddresses.getNow().stream().map( address -> new InetSocketAddress(address, request.getUri().getExplicitPort())) .collect(Collectors.toList()); p.setSuccess(remoteInetSocketAddresses); } else { if (!requestTimeout.isDone()) { // only report if we haven't timed out listener.onThrowable(whenAddresses.cause()); } p.setFailure(whenAddresses.cause()); } }); return p; } }
From source file:io.gatling.http.client.impl.DefaultHttpClient.java
License:Apache License
private void sendTxWithNewChannel(HttpTx tx, EventLoopResources resources, EventLoop eventLoop, List<InetSocketAddress> addresses) { openNewChannel(tx.request, eventLoop, resources, addresses, tx.listener, tx.requestTimeout) .addListener((Future<Channel> whenNewChannel) -> { if (whenNewChannel.isSuccess()) { Channel channel = whenNewChannel.getNow(); if (tx.requestTimeout.isDone()) { channel.close(); return; }//from www .ja va 2 s . c o m channelGroup.add(channel); resources.channelPool.register(channel, tx.key); if (tx.request.getUri().isSecured()) { LOGGER.debug("Installing SslHandler for {}", tx.request.getUri()); installSslHandler(tx, channel).addListener(f -> { if (tx.requestTimeout.isDone() || !f.isSuccess()) { channel.close(); return; } if (tx.request.isAlpnRequired()) { LOGGER.debug("Installing Http2Handler for {}", tx.request.getUri()); installHttp2Handler(tx, channel, resources.channelPool).addListener(f2 -> { if (tx.requestTimeout.isDone() || !f2.isSuccess()) { channel.close(); return; } sendTxWithChannel(tx, channel); }); } else { sendTxWithChannel(tx, channel); } }); } else { sendTxWithChannel(tx, channel); } } }); }
From source file:io.gatling.http.client.impl.DefaultHttpClient.java
License:Apache License
private void sendHttp2TxsWithNewChannel(List<HttpTx> txs, EventLoopResources resources, EventLoop eventLoop, List<InetSocketAddress> addresses) { HttpTx tx = txs.get(0);/*from w w w. jav a 2s . com*/ openNewChannel(tx.request, eventLoop, resources, addresses, tx.listener, tx.requestTimeout) .addListener((Future<Channel> whenNewChannel) -> { if (whenNewChannel.isSuccess()) { Channel channel = whenNewChannel.getNow(); if (tx.requestTimeout.isDone()) { channel.close(); return; } channelGroup.add(channel); resources.channelPool.register(channel, tx.key); LOGGER.debug("Installing SslHandler for {}", tx.request.getUri()); installSslHandler(tx, channel).addListener(f -> { if (tx.requestTimeout.isDone() || !f.isSuccess()) { channel.close(); return; } LOGGER.debug("Installing Http2Handler for {}", tx.request.getUri()); installHttp2Handler(tx, channel, resources.channelPool).addListener(f2 -> { if (tx.requestTimeout.isDone() || !f2.isSuccess()) { channel.close(); return; } sendHttp2TxsWithChannel(txs, channel); }); }); } }); }