List of usage examples for io.netty.util.concurrent GenericFutureListener GenericFutureListener
GenericFutureListener
From source file:com.github.mrstampy.kitchensync.netty.channel.AbstractKiSyChannel.java
License:Open Source License
/** * Close channel.// w w w. j a v a2s . c o m */ protected void closeChannel() { ChannelFuture cf = close(); final CountDownLatch latch = new CountDownLatch(1); cf.addListener(new GenericFutureListener<ChannelFuture>() { @Override public void operationComplete(ChannelFuture future) throws Exception { latch.countDown(); } }); await(latch, "Channel close timed out"); }
From source file:com.github.mrstampy.kitchensync.netty.channel.AbstractKiSyMulticastChannel.java
License:Open Source License
/** * Sets the channel.//from w w w. java 2s . c om * * @param channel * the channel */ protected void setChannel(DC channel) { super.setChannel(channel); channel.closeFuture().addListener(new GenericFutureListener<Future<Void>>() { @Override public void operationComplete(Future<Void> future) throws Exception { registry.removeMulticastChannel(AbstractKiSyMulticastChannel.this); } }); }
From source file:com.github.mrstampy.kitchensync.netty.channel.AbstractKiSyMulticastChannel.java
License:Open Source License
private GenericFutureListener<ChannelFuture> getJoinGroupListener(final InetSocketAddress multicast, final CountDownLatch latch) { return new GenericFutureListener<ChannelFuture>() { @Override//w ww . java 2s. c o m public void operationComplete(ChannelFuture future) throws Exception { try { if (future.isSuccess()) { log.debug("Multicast channel joined group {}", multicast); } else { Throwable cause = future.cause(); if (cause == null) { log.error("Could not join multicast group for {}", multicast); } else { log.error("Could not join multicast group for {}", multicast, cause); } } } finally { latch.countDown(); } } }; }
From source file:com.github.mrstampy.kitchensync.netty.channel.AbstractKiSyMulticastChannel.java
License:Open Source License
private GenericFutureListener<ChannelFuture> getLeaveGroupListener(final InetSocketAddress multicast, final CountDownLatch latch) { return new GenericFutureListener<ChannelFuture>() { @Override/*from w w w .j a v a 2 s.co m*/ public void operationComplete(ChannelFuture future) throws Exception { try { if (future.isSuccess()) { log.debug("Multicast channel left group {}", multicast); } else { Throwable cause = future.cause(); if (cause == null) { log.error("Could not leave multicast group for {}", multicast); } else { log.error("Could not leave multicast group for {}", multicast, cause); } } } finally { latch.countDown(); } } }; }
From source file:com.github.mrstampy.kitchensync.netty.channel.AbstractKiSyMulticastChannel.java
License:Open Source License
private GenericFutureListener<ChannelFuture> getBlockListener(final InetSocketAddress multicast, final CountDownLatch latch, final InetAddress sourceToBlock) { return new GenericFutureListener<ChannelFuture>() { @Override/*w w w . j av a 2 s.c o m*/ public void operationComplete(ChannelFuture future) throws Exception { try { if (future.isSuccess()) { log.debug("Multicast channel {} now blocking {}", multicast, sourceToBlock); } else { Throwable cause = future.cause(); if (cause == null) { log.error("Could not block {} from {}", sourceToBlock, multicast); } else { log.error("Could not block {} from {}", sourceToBlock, multicast, cause); } } } finally { latch.countDown(); } } }; }
From source file:com.github.mrstampy.kitchensync.test.AbstractTester.java
License:Open Source License
/** * Adds the latch listener./*w ww . j a va2 s. c o m*/ * * @param cf * the cf * @param cdl * the cdl */ protected void addLatchListener(ChannelFuture cf, final CountDownLatch cdl) { cf.addListener(new GenericFutureListener<ChannelFuture>() { @Override public void operationComplete(ChannelFuture future) throws Exception { cdl.countDown(); } }); }
From source file:com.github.mrstampy.kitchensync.test.BroadcastTester.java
License:Open Source License
/** * Execute.//w ww . j a v a 2 s . c o m */ public void execute() { michael.leaveGroup(); ChannelFuture cf = michael.broadcast("A good day to you all!"); cf.addListener(new GenericFutureListener<ChannelFuture>() { @Override public void operationComplete(ChannelFuture future) throws Exception { michael.joinGroup(); } }); }
From source file:com.github.mrstampy.pprspray.core.streamer.AbstractMediaStreamer.java
License:Open Source License
private void addChannelCloseListener() { getChannel().getChannel().closeFuture().addListener(new GenericFutureListener<ChannelFuture>() { @Override// ww w. j a v a 2 s . com public void operationComplete(ChannelFuture future) throws Exception { destroyImpl(); } }); }
From source file:com.github.sinsinpub.pero.backend.ConnectBackendHandler.java
License:Apache License
/** * Create new promised callback on outbound channel operation complete. * /*ww w . ja va 2 s. c o m*/ * @param ctx * @param request * @return Promise */ protected Promise<Channel> newOutboundPromise(final ChannelHandlerContext ctx, final SocksCmdRequest request) { final Promise<Channel> promise = ctx.executor().newPromise(); promise.addListener(new GenericFutureListener<Future<Channel>>() { @Override public void operationComplete(final Future<Channel> future) throws Exception { final Channel outboundChannel = future.getNow(); if (future.isSuccess()) { ctx.channel().writeAndFlush(new SocksCmdResponse(SocksCmdStatus.SUCCESS, request.addressType())) .addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture channelFuture) { ctx.pipeline().remove(ConnectBackendHandler.this); outboundChannel.pipeline().addLast(new RelayTrafficHandler(ctx.channel())); ctx.pipeline().addLast(new RelayTrafficHandler(outboundChannel)); } }); } else { ctx.channel() .writeAndFlush(new SocksCmdResponse(SocksCmdStatus.FAILURE, request.addressType())); NettyChannelUtils.closeOnFlush(ctx.channel()); } } }); return promise; }
From source file:com.github.spapageo.jannel.client.ClientSession.java
License:Open Source License
/** * Asynchronously sends an sms/*ww w . ja v a2s. co m*/ * @param sms the sms to send * @param timeoutMillis the timeout for an open window slot to appear * @return the future on the operation * @throws InterruptedException when the operation was interrupted */ @SuppressWarnings("unchecked") @Nonnull public WindowFuture<Sms, Ack> sendSms(final Sms sms, final long timeoutMillis) throws InterruptedException { // Generate UUID if null if (sms.getId() == null) { sms.setId(UUID.randomUUID()); } // Apply the current client id if null if (sms.getBoxId() == null) sms.setBoxId(configuration.getClientId()); WindowFuture future = sendWindow.offer(sms.getId(), sms, timeoutMillis, configuration.getRequestExpiryTimeout()); sendMessage(sms).addListener(new GenericFutureListener<Future<? super Void>>() { @Override public void operationComplete(Future<? super Void> channelFuture) throws Exception { if (!channelFuture.isSuccess() && !channelFuture.isCancelled()) { sendWindow.fail(sms.getId(), channelFuture.cause()); } else if (channelFuture.isCancelled()) { sendWindow.cancel(sms.getId(), true); } } }); return future; }