io.netty.util.concurrent.FailedFuture Java Examples

The following examples show how to use io.netty.util.concurrent.FailedFuture. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NettyClient2.java    From wind-im with Apache License 2.0 5 votes vote down vote up
public Future<IRedisCommandResponse> sendRedisCommand(final RedisCommand redisCommand) {
	final Future<IRedisCommandResponse> responseFuture;
	// logger.info("send push message {} {} {}", channelPromise,
	// channelPromise.isSuccess(),
	// channelPromise.channel().isActive());
	if (channelPromise != null) {
		final ChannelPromise readyPromise = this.channelPromise;

		final DefaultPromise<IRedisCommandResponse> responsePromise = new DefaultPromise<IRedisCommandResponse>(
				readyPromise.channel().eventLoop());
		// 提交一个事件
		readyPromise.channel().eventLoop().submit(new Runnable() {
			@Override
			public void run() {
				// 将这个结果赋值给responsePromise
				NettyClient2.this.responsePromise = responsePromise;
			}
		});

		readyPromise.channel().writeAndFlush(redisCommand).addListener(new GenericFutureListener<ChannelFuture>() {
			@Override
			public void operationComplete(final ChannelFuture future) throws Exception {
				if (!future.isSuccess()) {
					// 如果失败了,直接将promise返回
					responsePromise.tryFailure(future.cause());
					logger.error("send push message error: {},cause={}", redisCommand, future.cause());
				} else {
					// logger.info("write data to platform success");
				}
			}
		});
		responseFuture = responsePromise;
	} else {
		logger.error("send push error because client is not connected: {}", redisCommand.toString());
		responseFuture = new FailedFuture<IRedisCommandResponse>(GlobalEventExecutor.INSTANCE, CONNECT_EXCEPTION);
	}
	return responseFuture;
}
 
Example #2
Source File: PlatformSSLClient.java    From wind-im with Apache License 2.0 5 votes vote down vote up
public Future<IRedisCommandResponse> sendRedisCommand(final RedisCommand redisCommand) {
	final Future<IRedisCommandResponse> responseFuture;
	if (channelPromise != null) {
		final ChannelPromise readyPromise = this.channelPromise;

		final DefaultPromise<IRedisCommandResponse> responsePromise = new DefaultPromise<IRedisCommandResponse>(
				readyPromise.channel().eventLoop());
		// 提交一个事件
		readyPromise.channel().eventLoop().submit(new Runnable() {
			@Override
			public void run() {
				// 将这个结果赋值给responsePromise
				PlatformSSLClient.this.responsePromise = responsePromise;
			}
		});

		readyPromise.channel().writeAndFlush(redisCommand).addListener(new GenericFutureListener<ChannelFuture>() {
			@Override
			public void operationComplete(final ChannelFuture future) throws Exception {
				if (!future.isSuccess()) {
					// 如果失败了,直接将promise返回
					responsePromise.tryFailure(future.cause());
					logger.error("send push message error: {},cause={}", redisCommand, future.cause());
				} else {
					// logger.info("write data to platform success");
				}
			}
		});
		responseFuture = responsePromise;
	} else {
		logger.error("send push error because client is not connected: {}", redisCommand.toString());
		responseFuture = new FailedFuture<IRedisCommandResponse>(GlobalEventExecutor.INSTANCE, CONNECT_EXCEPTION);
	}
	return responseFuture;
}
 
Example #3
Source File: NettyClient2.java    From openzaly with Apache License 2.0 5 votes vote down vote up
public Future<IRedisCommandResponse> sendRedisCommand(final RedisCommand redisCommand) {
	final Future<IRedisCommandResponse> responseFuture;
	// logger.info("send push message {} {} {}", channelPromise,
	// channelPromise.isSuccess(),
	// channelPromise.channel().isActive());
	if (channelPromise != null) {
		final ChannelPromise readyPromise = this.channelPromise;

		final DefaultPromise<IRedisCommandResponse> responsePromise = new DefaultPromise<IRedisCommandResponse>(
				readyPromise.channel().eventLoop());
		// 提交一个事件
		readyPromise.channel().eventLoop().submit(new Runnable() {
			@Override
			public void run() {
				// 将这个结果赋值给responsePromise
				NettyClient2.this.responsePromise = responsePromise;
			}
		});

		readyPromise.channel().writeAndFlush(redisCommand).addListener(new GenericFutureListener<ChannelFuture>() {
			@Override
			public void operationComplete(final ChannelFuture future) throws Exception {
				if (!future.isSuccess()) {
					// 如果失败了,直接将promise返回
					responsePromise.tryFailure(future.cause());
					logger.error("send push message error: {},cause={}", redisCommand, future.cause());
				} else {
					// logger.info("write data to platform success");
				}
			}
		});
		responseFuture = responsePromise;
	} else {
		logger.error("send push error because client is not connected: {}", redisCommand.toString());
		responseFuture = new FailedFuture<IRedisCommandResponse>(GlobalEventExecutor.INSTANCE, CONNECT_EXCEPTION);
	}
	return responseFuture;
}
 
Example #4
Source File: PlatformSSLClient.java    From openzaly with Apache License 2.0 5 votes vote down vote up
public Future<IRedisCommandResponse> sendRedisCommand(final RedisCommand redisCommand) {
	final Future<IRedisCommandResponse> responseFuture;
	if (channelPromise != null) {
		final ChannelPromise readyPromise = this.channelPromise;

		final DefaultPromise<IRedisCommandResponse> responsePromise = new DefaultPromise<IRedisCommandResponse>(
				readyPromise.channel().eventLoop());
		// 提交一个事件
		readyPromise.channel().eventLoop().submit(new Runnable() {
			@Override
			public void run() {
				// 将这个结果赋值给responsePromise
				PlatformSSLClient.this.responsePromise = responsePromise;
			}
		});

		readyPromise.channel().writeAndFlush(redisCommand).addListener(new GenericFutureListener<ChannelFuture>() {
			@Override
			public void operationComplete(final ChannelFuture future) throws Exception {
				if (!future.isSuccess()) {
					// 如果失败了,直接将promise返回
					responsePromise.tryFailure(future.cause());
					logger.error("send push message error: {},cause={}", redisCommand, future.cause());
				} else {
					// logger.info("write data to platform success");
				}
			}
		});
		responseFuture = responsePromise;
	} else {
		logger.error("send push error because client is not connected: {}", redisCommand.toString());
		responseFuture = new FailedFuture<IRedisCommandResponse>(GlobalEventExecutor.INSTANCE, CONNECT_EXCEPTION);
	}
	return responseFuture;
}
 
Example #5
Source File: NettyClient2.java    From openzaly with Apache License 2.0 5 votes vote down vote up
public Future<IRedisCommandResponse> sendRedisCommand(final RedisCommand redisCommand) {
	final Future<IRedisCommandResponse> responseFuture;
	// logger.info("send push message {} {} {}", channelPromise,
	// channelPromise.isSuccess(),
	// channelPromise.channel().isActive());
	if (channelPromise != null) {
		final ChannelPromise readyPromise = this.channelPromise;

		final DefaultPromise<IRedisCommandResponse> responsePromise = new DefaultPromise<IRedisCommandResponse>(
				readyPromise.channel().eventLoop());
		// 提交一个事件
		readyPromise.channel().eventLoop().submit(new Runnable() {
			@Override
			public void run() {
				// 将这个结果赋值给responsePromise
				NettyClient2.this.responsePromise = responsePromise;
			}
		});

		readyPromise.channel().writeAndFlush(redisCommand).addListener(new GenericFutureListener<ChannelFuture>() {
			@Override
			public void operationComplete(final ChannelFuture future) throws Exception {
				if (!future.isSuccess()) {
					// 如果失败了,直接将promise返回
					responsePromise.tryFailure(future.cause());
					logger.error("send push message error: {},cause={}", redisCommand, future.cause());
				} else {
					// logger.info("write data to platform success");
				}
			}
		});
		responseFuture = responsePromise;
	} else {
		logger.error("send push error because client is not connected: {}", redisCommand.toString());
		responseFuture = new FailedFuture<IRedisCommandResponse>(GlobalEventExecutor.INSTANCE, CONNECT_EXCEPTION);
	}
	return responseFuture;
}
 
Example #6
Source File: PlatformSSLClient.java    From openzaly with Apache License 2.0 5 votes vote down vote up
public Future<IRedisCommandResponse> sendRedisCommand(final RedisCommand redisCommand) {
	final Future<IRedisCommandResponse> responseFuture;
	if (channelPromise != null) {
		final ChannelPromise readyPromise = this.channelPromise;

		final DefaultPromise<IRedisCommandResponse> responsePromise = new DefaultPromise<IRedisCommandResponse>(
				readyPromise.channel().eventLoop());
		// 提交一个事件
		readyPromise.channel().eventLoop().submit(new Runnable() {
			@Override
			public void run() {
				// 将这个结果赋值给responsePromise
				PlatformSSLClient.this.responsePromise = responsePromise;
			}
		});

		readyPromise.channel().writeAndFlush(redisCommand).addListener(new GenericFutureListener<ChannelFuture>() {
			@Override
			public void operationComplete(final ChannelFuture future) throws Exception {
				if (!future.isSuccess()) {
					// 如果失败了,直接将promise返回
					responsePromise.tryFailure(future.cause());
					logger.error("send push message error: {},cause={}", redisCommand, future.cause());
				} else {
					// logger.info("write data to platform success");
				}
			}
		});
		responseFuture = responsePromise;
	} else {
		logger.error("send push error because client is not connected: {}", redisCommand.toString());
		responseFuture = new FailedFuture<IRedisCommandResponse>(GlobalEventExecutor.INSTANCE, CONNECT_EXCEPTION);
	}
	return responseFuture;
}
 
Example #7
Source File: Http2MultiplexedChannelPoolTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void failedConnectionAcquireNotifiesPromise() throws InterruptedException {
    IOException exception = new IOException();
    ChannelPool connectionPool = mock(ChannelPool.class);
    when(connectionPool.acquire()).thenReturn(new FailedFuture<>(loopGroup.next(), exception));

    ChannelPool pool = new Http2MultiplexedChannelPool(connectionPool, loopGroup.next(), null);

    Future<Channel> acquirePromise = pool.acquire().await();
    assertThat(acquirePromise.isSuccess()).isFalse();
    assertThat(acquirePromise.cause()).isEqualTo(exception);
}
 
Example #8
Source File: Http2MultiplexedChannelPoolTest.java    From ambry with Apache License 2.0 5 votes vote down vote up
/**
 * Channel acquire should fail if parent channel pool acquire fails.
 */
@Test
public void failedConnectionAcquireNotifiesPromise() throws InterruptedException {
  IOException exception = new IOException();
  ChannelPool connectionPool = mock(ChannelPool.class);
  when(connectionPool.acquire()).thenReturn(new FailedFuture<>(loopGroup.next(), exception));

  ChannelPool pool = new Http2MultiplexedChannelPool(connectionPool, loopGroup.next(), new HashSet<>(), null,
      http2ClientConfigForOneConnection, new Http2ClientMetrics(new MetricRegistry()), streamChannelInitializer);

  Future<Channel> acquirePromise = pool.acquire().await();
  assertFalse(acquirePromise.isSuccess());
  assertEquals(acquirePromise.cause(), exception);
}