List of usage examples for io.netty.util.concurrent Future cause
Throwable cause();
From source file:blazingcache.network.netty.NettyChannel.java
License:Apache License
@Override public void sendOneWayMessage(Message message, SendResultCallback callback) { if (message.getMessageId() == null) { message.setMessageId(UUID.randomUUID().toString()); }//from w ww. j a va 2 s. c om SocketChannel _socket = this.socket; if (_socket == null || !_socket.isOpen()) { callback.messageSent(message, new Exception(this + " connection is closed")); return; } _socket.writeAndFlush(message).addListener(new GenericFutureListener() { @Override public void operationComplete(Future future) throws Exception { if (future.isSuccess()) { callback.messageSent(message, null); } else { LOGGER.log(Level.SEVERE, this + ": error " + future.cause(), future.cause()); callback.messageSent(message, future.cause()); close(); } } }); }
From source file:com.addthis.hydra.query.tracker.DetailedStatusHandler.java
License:Apache License
@Override public void operationComplete(Future<TaskSourceInfo[]> future) throws Exception { if (future.isSuccess()) { try {//from w w w.j a va 2s . c o m TaskSourceInfo[] taskSourceInfos = future.get(); QueryEntryInfo queryEntryInfo = queryEntry.getStat(); long exactLines = 0; for (TaskSourceInfo taskSourceInfo : taskSourceInfos) { exactLines += taskSourceInfo.lines; } queryEntryInfo.lines = exactLines; queryEntryInfo.tasks = taskSourceInfos; onSuccess(queryEntryInfo); } catch (Throwable t) { onFailure(t); } } else { onFailure(future.cause()); } }
From source file:com.addthis.hydra.query.web.DetailedStatusHandler.java
License:Apache License
@Override public void operationComplete(Future<QueryEntryInfo> future) throws Exception { if (future.isSuccess()) { onSuccess(future.get());/*ww w . j a va 2s . c o m*/ } else { onFailure(future.cause()); } }
From source file:com.addthis.meshy.MeshyServer.java
License:Apache License
public MeshyServer(final int port, final File rootDir, @Nullable String[] netif, final MeshyServerGroup group) throws IOException { super();//from ww w . j a v a 2s . co m this.group = group; this.rootDir = rootDir; this.filesystems = loadFileSystems(rootDir); this.serverPeers = new AtomicInteger(0); bossGroup = new NioEventLoopGroup(1); ServerBootstrap bootstrap = new ServerBootstrap() .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .option(ChannelOption.SO_BACKLOG, 1024).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 30000) .option(ChannelOption.SO_REUSEADDR, true) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childOption(ChannelOption.TCP_NODELAY, true).childOption(ChannelOption.SO_KEEPALIVE, true) .childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, HIGH_WATERMARK) .childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, LOW_WATERMARK) .channel(NioServerSocketChannel.class).group(bossGroup, workerGroup) .childHandler(new ChannelInitializer<NioSocketChannel>() { @Override protected void initChannel(final NioSocketChannel ch) throws Exception { ch.pipeline().addLast(new ChannelState(MeshyServer.this, ch)); } }); /* bind to one or more interfaces, if supplied, otherwise all */ if ((netif == null) || (netif.length == 0)) { ServerSocketChannel serverChannel = (ServerSocketChannel) bootstrap.bind(new InetSocketAddress(port)) .syncUninterruptibly().channel(); serverLocal = serverChannel.localAddress(); } else { InetSocketAddress primaryServerLocal = null; for (String net : netif) { NetworkInterface nicif = NetworkInterface.getByName(net); if (nicif == null) { log.warn("missing speficied NIC: {}", net); continue; } for (InterfaceAddress addr : nicif.getInterfaceAddresses()) { InetAddress inAddr = addr.getAddress(); if (inAddr.getAddress().length != 4) { log.trace("skip non-ipV4 address: {}", inAddr); continue; } ServerSocketChannel serverChannel = (ServerSocketChannel) bootstrap .bind(new InetSocketAddress(inAddr, port)).syncUninterruptibly().channel(); if (primaryServerLocal != null) { log.info("server [{}-*] binding to extra address: {}", super.getUUID(), primaryServerLocal); } primaryServerLocal = serverChannel.localAddress(); } } if (primaryServerLocal == null) { throw new IllegalArgumentException("no valid interface / port specified"); } serverLocal = primaryServerLocal; } this.serverNetIf = NetworkInterface.getByInetAddress(serverLocal.getAddress()); this.serverPort = serverLocal.getPort(); if (serverNetIf != null) { serverUuid = super.getUUID() + "-" + serverPort + "-" + serverNetIf.getName(); } else { serverUuid = super.getUUID() + "-" + serverPort; } log.info("server [{}] on {} @ {}", getUUID(), serverLocal, rootDir); closeFuture = new DefaultPromise<>(GlobalEventExecutor.INSTANCE); workerGroup.terminationFuture().addListener((Future<Object> workerFuture) -> { bossGroup.terminationFuture().addListener((Future<Object> bossFuture) -> { if (!workerFuture.isSuccess()) { closeFuture.tryFailure(workerFuture.cause()); } else if (!bossFuture.isSuccess()) { closeFuture.tryFailure(bossFuture.cause()); } else { closeFuture.trySuccess(null); } }); }); addMessageFileSystemPaths(); group.join(this); if (autoMesh) { startAutoMesh(serverPort, autoMeshTimeout); } }
From source file:com.cloudera.livy.rsc.Utils.java
License:Apache License
public static <T> void addListener(Future<T> future, final FutureListener<T> lsnr) { future.addListener(new GenericFutureListener<Future<T>>() { @Override/*w w w .ja va2 s . com*/ public void operationComplete(Future<T> f) throws Exception { if (f.isSuccess()) { lsnr.onSuccess(f.get()); } else { lsnr.onFailure(f.cause()); } } }); }
From source file:com.codnos.dbgp.internal.impl.DBGpIdeImpl.java
License:Apache License
private void bindPort(ServerBootstrap b) { b.bind(port).addListener(new GenericFutureListener<Future<? super Void>>() { @Override// w w w . j a va2 s. com public void operationComplete(Future<? super Void> channelFuture) throws Exception { if (channelFuture.isDone() && channelFuture.isSuccess()) { LOGGER.fine("Successfully opened port to wait for clients"); isConnected.set(true); } else if (channelFuture.isCancelled()) { LOGGER.fine("Connection cancelled"); } else if (!channelFuture.isSuccess()) { LOGGER.fine("Failed to connect"); channelFuture.cause().printStackTrace(); } } }); }
From source file:com.couchbase.client.core.endpoint.binary.BinaryAuthHandler.java
License:Open Source License
@Override public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception { originalPromise = promise;// w ww .java2 s . co m ChannelPromise downPromise = ctx.newPromise(); downPromise.addListener(new GenericFutureListener<Future<Void>>() { @Override public void operationComplete(Future<Void> future) throws Exception { if (!future.isSuccess() && !originalPromise.isDone()) { originalPromise.setFailure(future.cause()); } } }); ctx.connect(remoteAddress, localAddress, downPromise); }
From source file:com.couchbase.client.core.env.resources.IoPoolShutdownHook.java
License:Apache License
public Observable<Boolean> shutdown() { return Observable.create(new Observable.OnSubscribe<Boolean>() { @Override/*from w w w . ja va2s . c o m*/ public void call(final Subscriber<? super Boolean> subscriber) { ioPool.shutdownGracefully(0, 10, TimeUnit.MILLISECONDS).addListener(new GenericFutureListener() { @Override public void operationComplete(final Future future) throws Exception { if (!subscriber.isUnsubscribed()) { try { if (future.isSuccess()) { subscriber.onNext(true); shutdown = true; subscriber.onCompleted(); } else { subscriber.onError(future.cause()); } } catch (Exception ex) { subscriber.onError(ex); } } } }); } }); }
From source file:com.eucalyptus.util.async.AsyncRequestHandler.java
License:Open Source License
/** * *//*from ww w . j a va 2 s. c o m*/ @Override public boolean fire(final ServiceConfiguration config, final Q request) { if (!this.request.compareAndSet(null, request)) { LOG.warn("Duplicate write attempt for request: " + this.request.get().getClass().getSimpleName()); return false; } else { try { final InetSocketAddress serviceSocketAddress = config.getSocketAddress(); final Bootstrap clientBootstrap = config.getComponentId().getClientBootstrap(); final ChannelInitializer<?> initializer = config.getComponentId().getClientChannelInitializer(); final int poolSizeLimit = initializer instanceof AsyncRequestPoolable ? ((AsyncRequestPoolable) initializer).fixedSize() : -1; final IoMessage<FullHttpRequest> ioMessage = IoMessage.httpRequest(ServiceUris.internal(config), this.request.get()); final ChannelPoolKey poolKey = new ChannelPoolKey(clientBootstrap, initializer, serviceSocketAddress, poolSizeLimit); final long before = System.currentTimeMillis(); this.channelPool = POOL_MAP.get(poolKey); this.acquireFuture = channelPool.acquire(); this.acquireFuture.addListener(new GenericFutureListener<Future<Channel>>() { @Override public void operationComplete(final Future<Channel> future) throws Exception { try { if (future.isSuccess()) { final Channel channel = future.get(); logAcquired(channel, before); channel.pipeline().addLast("request-handler", AsyncRequestHandler.this); if (!initializer.getClass().getSimpleName().startsWith("GatherLog")) { Topology.populateServices(config, AsyncRequestHandler.this.request.get()); } logMessage(ioMessage); channel.writeAndFlush(ioMessage).addListener(new ChannelFutureListener() { @Override public void operationComplete(final ChannelFuture future) throws Exception { AsyncRequestHandler.this.writeComplete.set(true); Logs.extreme() .debug(EventRecord.here(request.getClass(), EventClass.SYSTEM_REQUEST, EventType.CHANNEL_WRITE, request.getClass().getSimpleName(), request.getCorrelationId(), serviceSocketAddress.toString(), "" + future.channel().localAddress(), "" + future.channel().remoteAddress())); } }); } else { AsyncRequestHandler.this.teardown(future.cause()); } } catch (final Exception ex) { LOG.error(ex, ex); AsyncRequestHandler.this.teardown(ex); } } }); return true; } catch (final Exception t) { LOG.error(t, t); this.teardown(t); return false; } } }
From source file:com.flowpowered.networking.NetworkClient.java
License:MIT License
public ChannelFuture connect(final SocketAddress remoteAdress) { return bootstrap.connect(remoteAdress).addListener(new GenericFutureListener<Future<? super Void>>() { @Override// ww w. j ava 2 s. c o m public void operationComplete(Future<? super Void> f) throws Exception { Throwable cause = f.cause(); if (cause != null || f.isCancelled()) { onConnectFailure(); } } }); }