io.netty.channel.Channel#alloc ( )源码实例Demo

下面列出了io.netty.channel.Channel#alloc ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: grpc-nebula-java   文件: NettyClientStream.java
NettyClientStream(
    TransportState state,
    MethodDescriptor<?, ?> method,
    Metadata headers,
    Channel channel,
    AsciiString authority,
    AsciiString scheme,
    AsciiString userAgent,
    StatsTraceContext statsTraceCtx,
    TransportTracer transportTracer,
    CallOptions callOptions) {
  super(
      new NettyWritableBufferAllocator(channel.alloc()),
      statsTraceCtx,
      transportTracer,
      headers,
      callOptions,
      useGet(method));
  this.state = checkNotNull(state, "transportState");
  this.writeQueue = state.handler.getWriteQueue();
  this.method = checkNotNull(method, "method");
  this.channel = checkNotNull(channel, "channel");
  this.authority = checkNotNull(authority, "authority");
  this.scheme = checkNotNull(scheme, "scheme");
  this.userAgent = userAgent;
}
 
源代码2 项目: grpc-java   文件: NettyClientStream.java
NettyClientStream(
    TransportState state,
    MethodDescriptor<?, ?> method,
    Metadata headers,
    Channel channel,
    AsciiString authority,
    AsciiString scheme,
    AsciiString userAgent,
    StatsTraceContext statsTraceCtx,
    TransportTracer transportTracer,
    CallOptions callOptions,
    boolean useGetForSafeMethods) {
  super(
      new NettyWritableBufferAllocator(channel.alloc()),
      statsTraceCtx,
      transportTracer,
      headers,
      callOptions,
      useGetForSafeMethods && method.isSafe());
  this.state = checkNotNull(state, "transportState");
  this.writeQueue = state.handler.getWriteQueue();
  this.method = checkNotNull(method, "method");
  this.authority = checkNotNull(authority, "authority");
  this.scheme = checkNotNull(scheme, "scheme");
  this.userAgent = userAgent;
}
 
源代码3 项目: grpc-java   文件: NettyServerStream.java
public NettyServerStream(
    Channel channel,
    TransportState state,
    Attributes transportAttrs,
    String authority,
    StatsTraceContext statsTraceCtx,
    TransportTracer transportTracer) {
  super(new NettyWritableBufferAllocator(channel.alloc()), statsTraceCtx);
  this.state = checkNotNull(state, "transportState");
  this.writeQueue = state.handler.getWriteQueue();
  this.attributes = checkNotNull(transportAttrs);
  this.authority = authority;
  this.transportTracer = checkNotNull(transportTracer, "transportTracer");
  // Read the id early to avoid reading transportState later.
  this.streamId = transportState().id();
}
 
源代码4 项目: grpc-nebula-java   文件: NettyServerStream.java
public NettyServerStream(
    Channel channel,
    TransportState state,
    Attributes transportAttrs,
    String authority,
    StatsTraceContext statsTraceCtx,
    TransportTracer transportTracer) {
  super(new NettyWritableBufferAllocator(channel.alloc()), statsTraceCtx);
  this.state = checkNotNull(state, "transportState");
  this.channel = checkNotNull(channel, "channel");
  this.writeQueue = state.handler.getWriteQueue();
  this.attributes = checkNotNull(transportAttrs);
  this.authority = authority;
  this.transportTracer = checkNotNull(transportTracer, "transportTracer");
}
 
@SuppressWarnings("SubscriberImplementation")
@Override
public reactor.core.publisher.Flux<DataBuffer> getBody() {
    final Optional<Channel> opt = channelResolver.resolveChannel(request);
    if (opt.isPresent()) {
        final Channel channel = opt.get();
        final NettyDataBufferFactory nettyDataBufferFactory = new NettyDataBufferFactory(channel.alloc());

        final Optional<HttpContentProcessor<ByteBufHolder>> httpContentProcessor = channelResolver.resolveContentProcessor(request);

        if (httpContentProcessor.isPresent()) {

            final HttpContentProcessor<ByteBufHolder> processor = httpContentProcessor.get();
            return Flux.from(subscriber -> processor.subscribe(new Subscriber<ByteBufHolder>() {
                @Override
                public void onSubscribe(Subscription s) {
                    subscriber.onSubscribe(s);
                }

                @Override
                public void onNext(ByteBufHolder byteBufHolder) {
                    subscriber.onNext(nettyDataBufferFactory.wrap(byteBufHolder.content()));
                }

                @Override
                public void onError(Throwable t) {
                    subscriber.onError(t);
                }

                @Override
                public void onComplete() {
                    subscriber.onComplete();
                }
            }));
        }
    }

    return Flux.empty();
}
 
源代码6 项目: xrpc   文件: XrpcRequest.java
public XrpcRequest(
    FullHttpRequest request,
    ServerContext connectionContext,
    Map<String, String> groups,
    Channel channel) {
  this.h1Request = request;
  this.h2Headers = null;
  this.connectionContext = connectionContext;
  this.groups = groups;
  this.upstreamChannel = channel;
  this.alloc = channel.alloc();
  this.eventLoop = channel.eventLoop();
  this.h2Data = null;
}
 
源代码7 项目: xrpc   文件: XrpcRequest.java
public XrpcRequest(
    Http2Headers headers,
    ServerContext connectionContext,
    Map<String, String> groups,
    Channel channel) {
  this.h1Request = null;
  this.h2Headers = headers;
  this.connectionContext = connectionContext;
  this.groups = groups;
  this.upstreamChannel = channel;
  this.alloc = channel.alloc();
  this.eventLoop = channel.eventLoop();
  this.h2Data = alloc.compositeBuffer();
}
 
源代码8 项目: reactor-netty   文件: TransportConfig.java
@Override
protected void initChannel(Channel channel) {
	ChannelPipeline pipeline = channel.pipeline();

	if (config.metricsRecorder != null) {
		ChannelOperations.addMetricsHandler(channel,
				Objects.requireNonNull(config.metricsRecorder.get(), "Metrics recorder supplier returned null"),
				remoteAddress,
				onServer);

		ByteBufAllocator alloc = channel.alloc();
		if (alloc instanceof PooledByteBufAllocator) {
			ByteBufAllocatorMetrics.INSTANCE.registerMetrics("pooled", ((PooledByteBufAllocator) alloc).metric());
		}
		else if (alloc instanceof UnpooledByteBufAllocator) {
			ByteBufAllocatorMetrics.INSTANCE.registerMetrics("unpooled", ((UnpooledByteBufAllocator) alloc).metric());
		}
	}

	if (config.loggingHandler != null) {
		pipeline.addFirst(NettyPipeline.LoggingHandler, config.loggingHandler);
	}

	ChannelOperations.addReactiveBridge(channel, config.channelOperationsProvider(), connectionObserver);

	config.defaultOnChannelInit()
	      .then(config.doOnChannelInit)
	      .onChannelInit(connectionObserver, channel, remoteAddress);

	pipeline.remove(this);

	if (log.isDebugEnabled()) {
		log.debug(format(channel, "Initialized pipeline {}"), pipeline.toString());
	}
}
 
源代码9 项目: armeria   文件: DefaultClientRequestContext.java
@Override
public ByteBufAllocator alloc() {
    final Channel channel = channel();
    return channel != null ? channel.alloc() : PooledByteBufAllocator.DEFAULT;
}