当前位置: 首页>>代码示例>>Java>>正文


Java ChannelPool类代码示例

本文整理汇总了Java中io.netty.channel.pool.ChannelPool的典型用法代码示例。如果您正苦于以下问题:Java ChannelPool类的具体用法?Java ChannelPool怎么用?Java ChannelPool使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ChannelPool类属于io.netty.channel.pool包,在下文中一共展示了ChannelPool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createChannelPoolMap

import io.netty.channel.pool.ChannelPool; //导入依赖的package包/类
private ChannelPoolMap<URI, ChannelPool> createChannelPoolMap() {
    return new SdkChannelPoolMap<URI, ChannelPool>() {
        @Override
        protected ChannelPool newPool(URI key) {
            Bootstrap bootstrap =
                    new Bootstrap()
                            .group(group)
                            .channel(resolveSocketChannelClass(group))
                            .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, configuration.connectionTimeout())
                            .option(ChannelOption.TCP_NODELAY, true)
                            .remoteAddress(key.getHost(), key.getPort());
            SslContext sslContext = sslContext(key.getScheme());
            return new FixedChannelPool(bootstrap,
                                        // TODO expose better options for this
                                        new ChannelPipelineInitializer(sslContext),
                                        ChannelHealthChecker.ACTIVE,
                                        FixedChannelPool.AcquireTimeoutAction.FAIL,
                                        configuration.connectionAcquisitionTimeout(),
                                        configuration.maxConnectionsPerEndpoint(),
                                        10_000);
        }
    };
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:24,代码来源:NettyNioAsyncHttpClient.java

示例2: releaseChannelBackToPoolIfCallIsActive

import io.netty.channel.pool.ChannelPool; //导入依赖的package包/类
protected static void releaseChannelBackToPoolIfCallIsActive(Channel ch, ChannelPool pool,
                                                             ObjectHolder<Boolean> callActiveHolder,
                                                             String contextReason,
                                                             Deque<Span> distributedTracingStack,
                                                             Map<String, String> distributedTracingMdcInfo) {
    if (callActiveHolder.heldObject) {
        if (logger.isDebugEnabled()) {
            runnableWithTracingAndMdc(
                () -> logger.debug(
                    "Marking call as inactive and releasing channel back to pool. "
                    + "channel_release_reason=\"{}\"", contextReason
                ),
                distributedTracingStack, distributedTracingMdcInfo
            ).run();
        }

        callActiveHolder.heldObject = false;
        pool.release(ch);
    }
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:21,代码来源:StreamingAsyncHttpClient.java

示例3: getChannel

import io.netty.channel.pool.ChannelPool; //导入依赖的package包/类
/**
 * <p>Acquires a {@link Channel} from the {@link ChannelPool}</p>
 *
 * @param message
 *         An {@link AbstractRequest} that will be used as the lookup reference for the {@link
 *         io.netty.channel.pool.ChannelPoolMap} key
 *
 * @return A {@link CompletableFuture} containing the acquired {@link Channel}
 */
@Override
public CompletableFuture<Channel> getChannel(M message) {
    final CompletableFuture<Channel> channelFuture = new CompletableFuture<>();
    //Retrieve our channel pool based on the message
    final ChannelPool pool = poolMap.get(message);

    log.debug("Acquiring channel from pool '{}' for message : {}", pool, message);

    //Acquire a channel from the pool and listen for completion
    pool.acquire().addListener((Future<Channel> future) -> {
        if (future.isSuccess()) {
            log.debug("Successfully acquired Channel from pool");
            Channel channel = future.get();
            channel.attr(ChannelAttributes.CHANNEL_POOL).set(pool);
            channelFuture.complete(channel);
        } else {
            log.debug("Failed to acquire Channel from Pool");
            channelFuture.completeExceptionally(new ConnectException(future.cause()));
        }
    });
    return channelFuture;
}
 
开发者ID:ribasco,项目名称:async-gamequery-lib,代码行数:32,代码来源:NettyPooledTransport.java

示例4: newClientContext

import io.netty.channel.pool.ChannelPool; //导入依赖的package包/类
/**
 * Create a new client context with optional pool support
 *
 * @param sink
 * @param options
 * @param loggingHandler
 * @param secure
 * @param providedAddress
 * @param channelOpFactory
 * @param pool
 * @param <CHANNEL>
 *
 * @return a new {@link ContextHandler} for clients
 */
public static <CHANNEL extends Channel> ContextHandler<CHANNEL> newClientContext(
		MonoSink<NettyContext> sink,
		ClientOptions options,
		LoggingHandler loggingHandler,
		boolean secure,
		SocketAddress providedAddress,
		ChannelPool pool, ChannelOperations.OnNew<CHANNEL> channelOpFactory) {
	if (pool != null) {
		return new PooledClientContextHandler<>(channelOpFactory,
				options,
				sink,
				loggingHandler,
				secure,
				providedAddress,
				pool);
	}
	return new ClientContextHandler<>(channelOpFactory,
			options,
			sink,
			loggingHandler,
			secure,
			providedAddress);
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:38,代码来源:ContextHandler.java

示例5: doHandler

import io.netty.channel.pool.ChannelPool; //导入依赖的package包/类
/**
 * Create a {@link ContextHandler} for {@link Bootstrap#handler()}
 *
 * @param handler user provided in/out handler
 * @param sink user provided bind handler
 * @param secure if operation should be secured
 * @param pool if channel pool
 * @param onSetup if operation has local setup callback
 *
 * @return a new {@link ContextHandler}
 */
protected ContextHandler<SocketChannel> doHandler(BiFunction<? super NettyInbound, ? super NettyOutbound, ? extends Publisher<Void>> handler,
		MonoSink<NettyContext> sink,
		boolean secure,
		SocketAddress providedAddress,
		ChannelPool pool,
		Consumer<? super Channel> onSetup) {
	return ContextHandler.newClientContext(sink,
			options,
			loggingHandler,
			secure,
			providedAddress,
			pool,
			handler == null ? EMPTY :
					(ch, c, msg) -> ChannelOperations.bind(ch, handler, c));
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:27,代码来源:TcpClient.java

示例6: doHandler

import io.netty.channel.pool.ChannelPool; //导入依赖的package包/类
@Override
protected ContextHandler<SocketChannel> doHandler(BiFunction<? super NettyInbound, ? super NettyOutbound, ? extends Publisher<Void>> handler,
		MonoSink<NettyContext> sink,
		boolean secure,
		SocketAddress providedAddress,
		ChannelPool pool,
		Consumer<? super Channel> onSetup) {
	return ContextHandler.<SocketChannel>newClientContext(sink,
			options,
			loggingHandler,
			secure,
			providedAddress,
			pool,
			handler != null ? (ch, c, msg) -> {
				if(onSetup != null){
					onSetup.accept(ch);
				}
				return HttpClientOperations.bindHttp(ch, handler, c);
			} : EMPTY).onPipeline(this);
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:21,代码来源:HttpClient.java

示例7: RequestContext

import io.netty.channel.pool.ChannelPool; //导入依赖的package包/类
public RequestContext(ChannelPool channelPool,
                      SdkHttpRequest sdkRequest,
                      SdkHttpRequestProvider requestProvider,
                      HttpRequest nettyRequest,
                      SdkHttpResponseHandler handler,
                      NettyConfiguration configuration) {
    this.channelPool = channelPool;
    this.sdkRequest = sdkRequest;
    this.requestProvider = requestProvider;
    this.nettyRequest = nettyRequest;
    this.handler = handler;
    this.configuration = configuration;
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:14,代码来源:RequestContext.java

示例8: StreamingChannel

import io.netty.channel.pool.ChannelPool; //导入依赖的package包/类
StreamingChannel(Channel channel,
                 ChannelPool pool,
                 ObjectHolder<Boolean> callActiveHolder,
                 ObjectHolder<Boolean> downstreamLastChunkSentHolder,
                 Deque<Span> distributedTracingSpanStack,
                 Map<String, String> distributedTracingMdcInfo) {
    this.channel = channel;
    this.pool = pool;
    this.callActiveHolder = callActiveHolder;
    this.downstreamLastChunkSentHolder = downstreamLastChunkSentHolder;
    this.distributedTracingSpanStack = distributedTracingSpanStack;
    this.distributedTracingMdcInfo = distributedTracingMdcInfo;
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:14,代码来源:StreamingAsyncHttpClient.java

示例9: beforeMethod

import io.netty.channel.pool.ChannelPool; //导入依赖的package包/类
@Before
public void beforeMethod() {
    channelMock = mock(Channel.class);
    channelPoolMock = mock(ChannelPool.class);
    eventLoopMock = mock(EventLoop.class);

    contentChunkMock = mock(HttpContent.class);

    callActiveHolder = new ObjectHolder<>();
    callActiveHolder.heldObject = true;

    downstreamLastChunkSentHolder = new ObjectHolder<>();
    downstreamLastChunkSentHolder.heldObject = false;

    streamingChannelSpy = spy(new StreamingChannel(channelMock, channelPoolMock, callActiveHolder,
                                                   downstreamLastChunkSentHolder, null, null));

    writeAndFlushChannelFutureMock = mock(ChannelFuture.class);

    doReturn(eventLoopMock).when(channelMock).eventLoop();

    doReturn(writeAndFlushChannelFutureMock).when(channelMock).writeAndFlush(contentChunkMock);

    channelIsBrokenAttrMock = mock(Attribute.class);
    doReturn(channelIsBrokenAttrMock).when(channelMock).attr(CHANNEL_IS_BROKEN_ATTR);

    streamChunkChannelPromiseMock = mock(ChannelPromise.class);
    doReturn(streamChunkChannelPromiseMock).when(channelMock).newPromise();

    failedFutureMock = mock(ChannelFuture.class);
    doReturn(failedFutureMock).when(channelMock).newFailedFuture(any(Throwable.class));
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:33,代码来源:StreamingAsyncHttpClientTest.java

示例10: PooledClientContextHandler

import io.netty.channel.pool.ChannelPool; //导入依赖的package包/类
PooledClientContextHandler(ChannelOperations.OnNew<CHANNEL> channelOpFactory,
		ClientOptions options,
		MonoSink<NettyContext> sink,
		LoggingHandler loggingHandler,
		boolean secure,
		SocketAddress providedAddress,
		ChannelPool pool) {
	super(channelOpFactory, options, sink, loggingHandler, providedAddress);
	this.clientOptions = options;
	this.secure = secure;
	this.pool = pool;
	this.onReleaseEmitter = DirectProcessor.create();
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:14,代码来源:PooledClientContextHandler.java

示例11: selectOrCreate

import io.netty.channel.pool.ChannelPool; //导入依赖的package包/类
@Override
public ChannelPool selectOrCreate(SocketAddress remote,
		Supplier<? extends Bootstrap> bootstrap,
		Consumer<? super Channel> onChannelCreate,
		EventLoopGroup group) {
	SocketAddress address = remote;
	for (; ; ) {
		Pool pool = channelPools.get(remote);
		if (pool != null) {
			return pool;
		}
		Bootstrap b = bootstrap.get();
		if (remote != null) {
			b = b.remoteAddress(remote);
		}
		else {
			address = b.config()
			          .remoteAddress();
		}
		if (log.isDebugEnabled()) {
			log.debug("New {} client pool for {}", name, address);
		}
		pool = new Pool(b, provider, onChannelCreate, group);
		if (channelPools.putIfAbsent(address, pool) == null) {
			return pool;
		}
		pool.close();
	}
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:30,代码来源:DefaultPoolResources.java

示例12: selectOrCreate

import io.netty.channel.pool.ChannelPool; //导入依赖的package包/类
@Override
public ChannelPool selectOrCreate(SocketAddress address,
		Supplier<? extends Bootstrap> bootstrap,
		Consumer<? super Channel> onChannelCreate,
		EventLoopGroup group) {
	return defaultPools.selectOrCreate(address, bootstrap, onChannelCreate, group);
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:8,代码来源:TcpResources.java

示例13: newHandler

import io.netty.channel.pool.ChannelPool; //导入依赖的package包/类
/**
 * @param handler
 * @param address
 * @param secure
 * @param onSetup
 *
 * @return a new Mono to connect on subscribe
 */
protected Mono<NettyContext> newHandler(BiFunction<? super NettyInbound, ? super NettyOutbound, ? extends Publisher<Void>> handler,
		InetSocketAddress address,
		boolean secure,
		Consumer<? super Channel> onSetup) {

	final BiFunction<? super NettyInbound, ? super NettyOutbound, ? extends Publisher<Void>>
			targetHandler =
			null == handler ? ChannelOperations.noopHandler() : handler;

	return Mono.create(sink -> {
		SocketAddress remote = address != null ? address : options.getAddress();

		ChannelPool pool = null;

		PoolResources poolResources = options.getPoolResources();
		if (poolResources != null) {
			pool = poolResources.selectOrCreate(remote, options,
					doHandler(null, sink, secure, remote, null, null),
					options.getLoopResources().onClient(options.preferNative()));
		}

		ContextHandler<SocketChannel> contextHandler =
				doHandler(targetHandler, sink, secure, remote, pool, onSetup);
		sink.onCancel(contextHandler);

		if (pool == null) {
			Bootstrap b = options.get();
			b.remoteAddress(remote);
			b.handler(contextHandler);
			contextHandler.setFuture(b.connect());
		}
		else {
			contextHandler.setFuture(pool.acquire());
		}
	});
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:45,代码来源:TcpClient.java

示例14: RequestSender

import io.netty.channel.pool.ChannelPool; //导入依赖的package包/类
RequestSender(String s3Location, Request requestData, SubscriptionCompletionHandler completionHandler, HandlerDemultiplexer demultiplexer, ChannelPool channelPool) {
    this.s3Location = s3Location;
    this.requestData = requestData;
    this.completionHandler = completionHandler;
    this.demultiplexer = demultiplexer;
    this.channelPool = channelPool;
}
 
开发者ID:codewise,项目名称:RxS3,代码行数:8,代码来源:RequestSender.java

示例15: channelPool

import io.netty.channel.pool.ChannelPool; //导入依赖的package包/类
ChannelPool channelPool() {
    return channelPool;
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:4,代码来源:RequestContext.java


注:本文中的io.netty.channel.pool.ChannelPool类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。