List of usage examples for io.netty.util.concurrent Future isSuccess
boolean isSuccess();
From source file:com.twitter.http2.PipeTest.java
License:Apache License
@Test public void testRSSR() { Future<Object> recvFuture1 = pipe.receive(); assertFalse(recvFuture1.isDone());/*from w w w . jav a 2 s .com*/ Future<Void> sendFuture1 = pipe.send(MESSAGE1); assertTrue(sendFuture1.isSuccess()); assertSame(MESSAGE1, recvFuture1.getNow()); Future<Void> sendFuture2 = pipe.send(MESSAGE2); assertFalse(sendFuture2.isDone()); assertTrue(sendFuture1.isSuccess()); assertTrue(recvFuture1.isSuccess()); Future<Object> recvFuture2 = pipe.receive(); assertSame(MESSAGE2, recvFuture2.getNow()); assertTrue(sendFuture2.isSuccess()); assertTrue(sendFuture1.isSuccess()); assertTrue(recvFuture1.isSuccess()); }
From source file:com.twitter.http2.PipeTest.java
License:Apache License
@Test public void testSRRS() { Future<Void> sendFuture1 = pipe.send(MESSAGE1); assertFalse(sendFuture1.isDone());//ww w.j av a2 s.c o m Future<Object> recvFuture1 = pipe.receive(); assertSame(MESSAGE1, recvFuture1.getNow()); assertTrue(sendFuture1.isSuccess()); Future<Object> recvFuture2 = pipe.receive(); assertFalse(recvFuture2.isDone()); assertTrue(recvFuture1.isSuccess()); assertTrue(sendFuture1.isSuccess()); Future<Void> sendFuture2 = pipe.send(MESSAGE2); assertTrue(sendFuture2.isSuccess()); assertSame(MESSAGE2, recvFuture2.getNow()); assertTrue(recvFuture1.isSuccess()); assertTrue(sendFuture1.isSuccess()); }
From source file:com.twitter.http2.PipeTest.java
License:Apache License
@Test public void testSSRRR() { Future<Void> sendFuture1 = pipe.send(MESSAGE1); assertFalse(sendFuture1.isDone());/* w w w. j a v a 2 s .c o m*/ Future<Void> sendFuture2 = pipe.send(MESSAGE2); assertFalse(sendFuture2.isDone()); assertFalse(sendFuture1.isDone()); Future<Object> recvFuture1 = pipe.receive(); assertTrue(recvFuture1.isSuccess()); assertSame(MESSAGE1, recvFuture1.getNow()); assertFalse(sendFuture2.isDone()); assertTrue(sendFuture1.isSuccess()); Future<Object> recvFuture2 = pipe.receive(); assertTrue(recvFuture2.isSuccess()); assertSame(MESSAGE2, recvFuture2.getNow()); assertTrue(sendFuture2.isSuccess()); assertTrue(recvFuture1.isSuccess()); assertTrue(sendFuture2.isSuccess()); assertTrue(sendFuture1.isSuccess()); Future<Object> recvFuture3 = pipe.receive(); assertFalse(recvFuture3.isDone()); }
From source file:com.twitter.http2.PipeTest.java
License:Apache License
@Test public void testSCR() { Future<Void> sendFuture = pipe.send(MESSAGE); assertFalse(sendFuture.isDone());//from w ww .ja v a2 s . c om pipe.close(); assertFalse(sendFuture.isDone()); Future<Object> recvFuture = pipe.receive(); assertSame(MESSAGE, recvFuture.getNow()); assertTrue(sendFuture.isSuccess()); }
From source file:com.twitter.http2.PipeTest.java
License:Apache License
@Test public void testSRCS() { Future<Void> sendFuture1 = pipe.send(MESSAGE1); assertFalse(sendFuture1.isDone());//from w w w. j a va 2s . c om Future<Object> recvFuture = pipe.receive(); assertSame(MESSAGE1, recvFuture.getNow()); assertTrue(sendFuture1.isSuccess()); pipe.close(); Future<Void> sendFuture2 = pipe.send(MESSAGE2); assertNotNull(sendFuture2.cause()); }
From source file:com.twitter.http2.PipeTest.java
License:Apache License
@Test public void testSRCR() { Future<Void> sendFuture = pipe.send(MESSAGE); assertFalse(sendFuture.isDone());//from w ww .ja v a 2 s .co m Future<Object> recvFuture1 = pipe.receive(); assertSame(MESSAGE, recvFuture1.getNow()); assertTrue(sendFuture.isSuccess()); pipe.close(); Future<Object> recvFuture2 = pipe.receive(); assertNotNull(recvFuture2.cause()); assertTrue(sendFuture.isSuccess()); }
From source file:com.twitter.http2.PipeTest.java
License:Apache License
@Test public void testRSCR() { Future<Object> recvFuture1 = pipe.receive(); assertFalse(recvFuture1.isDone());/*from ww w. j av a2 s . com*/ Future<Void> sendFuture1 = pipe.send(MESSAGE); assertTrue(sendFuture1.isSuccess()); assertSame(MESSAGE, recvFuture1.getNow()); pipe.close(); Future<Object> recvFuture2 = pipe.receive(); assertNotNull(recvFuture2.cause()); assertTrue(sendFuture1.isSuccess()); assertTrue(recvFuture1.isSuccess()); }
From source file:com.twitter.http2.PipeTest.java
License:Apache License
@Test public void testRSCS() { Future<Object> recvFuture = pipe.receive(); assertFalse(recvFuture.isDone());/*from w w w . ja va 2 s . c om*/ Future<Void> sendFuture1 = pipe.send(MESSAGE1); assertTrue(sendFuture1.isSuccess()); assertSame(MESSAGE1, recvFuture.getNow()); pipe.close(); Future<Void> sendFuture2 = pipe.send(MESSAGE2); assertNotNull(sendFuture2.cause()); assertTrue(sendFuture1.isSuccess()); assertTrue(recvFuture.isSuccess()); }
From source file:com.xx_dev.apn.socks.remote.SocksServerConnectHandler.java
License:Apache License
@Override public void channelRead0(final ChannelHandlerContext ctx, final SocksCmdRequest request) throws Exception { Promise<Channel> promise = ctx.executor().newPromise(); promise.addListener(new GenericFutureListener<Future<Channel>>() { @Override/*from w ww .j a v a 2s.co m*/ public void operationComplete(final Future<Channel> future) throws Exception { final Channel outboundChannel = future.getNow(); if (future.isSuccess()) { restLogger.info(request.host() + ":" + request.port() + "," + "T"); ctx.channel().writeAndFlush(new SocksCmdResponse(SocksCmdStatus.SUCCESS, request.addressType())) .addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture channelFuture) { ctx.pipeline().remove(SocksServerConnectHandler.this); outboundChannel.pipeline().addLast(new RelayHandler(ctx.channel())); ctx.pipeline().addLast(new RelayHandler(outboundChannel)); } }); } else { restLogger.info(request.host() + ":" + request.port() + "," + "F"); ctx.channel() .writeAndFlush(new SocksCmdResponse(SocksCmdStatus.FAILURE, request.addressType())); SocksServerUtils.closeOnFlush(ctx.channel()); } } }); final Channel inboundChannel = ctx.channel(); b.group(inboundChannel.eventLoop()).channel(NioSocketChannel.class) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000).option(ChannelOption.SO_KEEPALIVE, true) .handler(new DirectClientHandler(promise)); b.connect(request.host(), request.port()).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { // Connection established use handler provided results } else { // Close the connection if the connection attempt has failed. restLogger.info(request.host() + ":" + request.port() + "," + "F"); ctx.channel() .writeAndFlush(new SocksCmdResponse(SocksCmdStatus.FAILURE, request.addressType())); SocksServerUtils.closeOnFlush(ctx.channel()); } } }); }
From source file:com.yahoo.pulsar.client.impl.ConsumerImpl.java
License:Apache License
private CompletableFuture<Void> sendAcknowledge(MessageId messageId, AckType ackType) { MessageIdImpl msgId = (MessageIdImpl) messageId; final ByteBuf cmd = Commands.newAck(consumerId, msgId.getLedgerId(), msgId.getEntryId(), ackType, null); // There's no actual response from ack messages final CompletableFuture<Void> ackFuture = new CompletableFuture<Void>(); if (isConnected()) { cnx().ctx().writeAndFlush(cmd).addListener(new GenericFutureListener<Future<Void>>() { @Override//www . j ava2 s. co m public void operationComplete(Future<Void> future) throws Exception { if (future.isSuccess()) { if (ackType == AckType.Individual) { unAckedMessageTracker.remove(msgId); // increment counter by 1 for non-batch msg if (!(messageId instanceof BatchMessageIdImpl)) { stats.incrementNumAcksSent(1); } } else if (ackType == AckType.Cumulative) { stats.incrementNumAcksSent(unAckedMessageTracker.removeMessagesTill(msgId)); } if (log.isDebugEnabled()) { log.debug("[{}] [{}] [{}] Successfully acknowledged message - {}, acktype {}", subscription, topic, consumerName, messageId, ackType); } ackFuture.complete(null); } else { stats.incrementNumAcksFailed(); ackFuture.completeExceptionally(new PulsarClientException(future.cause())); } } }); } else { stats.incrementNumAcksFailed(); ackFuture.completeExceptionally( new PulsarClientException("Not connected to broker. State: " + state.get())); } return ackFuture; }