org.jboss.netty.channel.Channel.getConfig()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(149)

本文整理了Java中org.jboss.netty.channel.Channel.getConfig()方法的一些代码示例,展示了Channel.getConfig()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Channel.getConfig()方法的具体详情如下:
包路径:org.jboss.netty.channel.Channel
类名称:Channel
方法名:getConfig

Channel.getConfig介绍

[英]Returns the configuration of this channel.
[中]返回此通道的配置。

代码示例

代码示例来源:origin: io.netty/netty

/**
 * Creates a new embedder whose pipeline is composed of the specified
 * handlers.
 *
 * @param bufferFactory the {@link ChannelBufferFactory} to be used when
 *                      creating a new buffer.
 */
protected AbstractCodecEmbedder(ChannelBufferFactory bufferFactory, ChannelHandler... handlers) {
  this(handlers);
  getChannel().getConfig().setBufferFactory(bufferFactory);
}

代码示例来源:origin: io.netty/netty

/**
 * Create a new {@link ChannelBuffer} which is used for the cumulation.
 * Sub-classes may override this.
 *
 * @param ctx {@link ChannelHandlerContext} for this handler
 * @return buffer the {@link ChannelBuffer} which is used for cumulation
 */
protected ChannelBuffer newCumulationBuffer(
    ChannelHandlerContext ctx, int minimumCapacity) {
  ChannelBufferFactory factory = ctx.getChannel().getConfig().getBufferFactory();
  return factory.getBuffer(Math.max(minimumCapacity, 256));
}

代码示例来源:origin: io.netty/netty

evt.getChannel().getConfig().setPipelineFactory(getPipelineFactory());
  evt.getChannel().getConfig().setOptions(parentOptions);
} finally {
  ctx.sendUpstream(evt);

代码示例来源:origin: io.netty/netty

private ChannelBuffer buffer(ChannelHandlerContext ctx) throws Exception {
    ChannelBuffer buf = buffer.get();
    if (buf == null) {
      ChannelBufferFactory factory = ctx.getChannel().getConfig().getBufferFactory();
      buf = ChannelBuffers.dynamicBuffer(factory);
      if (buffer.compareAndSet(null, buf)) {
        boolean success = false;
        try {
          oout = newObjectOutputStream(new ChannelBufferOutputStream(buf));
          success = true;
        } finally {
          if (!success) {
            oout = null;
          }
        }
      } else {
        buf = buffer.get();
      }
    }
    return buf;
  }
}

代码示例来源:origin: io.netty/netty

@Override
  protected ChannelBuffer newCumulationBuffer(ChannelHandlerContext ctx, int minimumCapacity) {
    ChannelBufferFactory factory = ctx.getChannel().getConfig().getBufferFactory();
    if (allocateFullBuffer) {
      return factory.getBuffer(frameLength);
    }
    return super.newCumulationBuffer(ctx, minimumCapacity);
  }
}

代码示例来源:origin: io.netty/netty

@Override
  protected Object encode(
      ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
    if (msg instanceof String) {
      return copiedBuffer(
          ctx.getChannel().getConfig().getBufferFactory().getDefaultOrder(), (String) msg, charset);
    }

    return msg;
  }
}

代码示例来源:origin: io.netty/netty

@Override
  protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
    ChannelBufferOutputStream bout =
      new ChannelBufferOutputStream(dynamicBuffer(
          estimatedLength, ctx.getChannel().getConfig().getBufferFactory()));
    bout.write(LENGTH_PLACEHOLDER);
    ObjectOutputStream oout = new CompactObjectOutputStream(bout);
    oout.writeObject(msg);
    oout.flush();
    oout.close();

    ChannelBuffer encoded = bout.buffer();
    encoded.setInt(0, encoded.writerIndex() - 4);
    return encoded;
  }
}

代码示例来源:origin: io.netty/netty

@Override
  protected Object encode(
      ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
    if (msg instanceof MessageLite) {
      byte[] array = ((MessageLite) msg).toByteArray();
      return ctx.getChannel().getConfig().getBufferFactory().getBuffer(array, 0, array.length);
    }
    if (msg instanceof MessageLite.Builder) {
      byte[] array = ((MessageLite.Builder) msg).build().toByteArray();
      return ctx.getChannel().getConfig().getBufferFactory().getBuffer(array, 0, array.length);
    }
    return msg;
  }
}

代码示例来源:origin: io.netty/netty

@Override
public void childChannelOpen(
    ChannelHandlerContext ctx,
    ChildChannelStateEvent e) throws Exception {
  // Apply child options.
  try {
    e.getChildChannel().getConfig().setOptions(childOptions);
  } catch (Throwable t) {
    fireExceptionCaught(e.getChildChannel(), t);
  }
  ctx.sendUpstream(e);
}

代码示例来源:origin: io.netty/netty

@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
  if (!(msg instanceof ChannelBuffer) || finished.get()) {
    return msg;
  }
  final ChannelBuffer uncompressed = (ChannelBuffer) msg;
  final int uncompressedLen = uncompressed.readableBytes();
  if (uncompressedLen == 0) {
    return uncompressed;
  }
  final byte[] in = new byte[uncompressedLen];
  uncompressed.readBytes(in);
  final int sizeEstimate = estimateCompressedSize(uncompressedLen);
  final ChannelBuffer compressed =
      ChannelBuffers.dynamicBuffer(sizeEstimate, channel.getConfig().getBufferFactory());
  synchronized (deflater) {
    if (isGzip()) {
      crc.update(in);
      if (writeHeader) {
        compressed.writeBytes(gzipHeader);
        writeHeader = false;
      }
    }
    deflater.setInput(in);
    while (!deflater.needsInput()) {
      deflate(compressed);
    }
  }
  return compressed;
}

代码示例来源:origin: io.netty/netty

ChannelBuffer header = channel.getConfig().getBufferFactory().getBuffer(body.order(), lengthFieldLength);

代码示例来源:origin: io.netty/netty

result = ctx.getChannel().getConfig().getBufferFactory().getBuffer(
      uncompressed.order(), out, 0, z.next_out_index);
} else {

代码示例来源:origin: io.netty/netty

@Override
  protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
    Marshaller marshaller = provider.getMarshaller(ctx);
    ChannelBufferByteOutput output =
        new ChannelBufferByteOutput(ctx.getChannel().getConfig().getBufferFactory(), 256);
    marshaller.start(output);
    marshaller.writeObject(msg);
    marshaller.finish();
    marshaller.close();

    return output.getBuffer();
  }
}

代码示例来源:origin: io.netty/netty

boolean success = false;
try {
  ch.getConfig().setOptions(getOptions());
  success = true;
} finally {

代码示例来源:origin: io.netty/netty

boolean success = false;
try {
  ch.getConfig().setOptions(getOptions());
  success = true;
} finally {

代码示例来源:origin: io.netty/netty

@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel,
    Object msg) throws Exception {
  if (!(msg instanceof ChannelBuffer)) {
    return msg;
  }
  ChannelBuffer body = (ChannelBuffer) msg;
  int length = body.readableBytes();
  ChannelBuffer header =
    channel.getConfig().getBufferFactory().getBuffer(
        body.order(),
        CodedOutputStream.computeRawVarint32Size(length));
  CodedOutputStream codedOutputStream = CodedOutputStream
      .newInstance(new ChannelBufferOutputStream(header));
  codedOutputStream.writeRawVarint32(length);
  codedOutputStream.flush();
  return wrappedBuffer(header, body);
}

代码示例来源:origin: io.netty/netty

final ChannelBuffer footer = ChannelBuffers.dynamicBuffer(ctx.getChannel().getConfig().getBufferFactory());
final boolean gzip = isGzip();
synchronized (deflater) {

代码示例来源:origin: io.netty/netty

@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
  Marshaller marshaller = provider.getMarshaller(ctx);
  ChannelBufferByteOutput output = new ChannelBufferByteOutput(
      ctx.getChannel().getConfig().getBufferFactory(), estimatedLength);
  output.getBuffer().writeBytes(LENGTH_PLACEHOLDER);
  marshaller.start(output);
  marshaller.writeObject(msg);
  marshaller.finish();
  marshaller.close();
  ChannelBuffer encoded = output.getBuffer();
  encoded.setInt(0, encoded.writerIndex() - 4);
  return encoded;
}

代码示例来源:origin: io.netty/netty

ch.getConfig().setOptions(getOptions());
  success = true;
} finally {

代码示例来源:origin: io.netty/netty

ChannelBuffer encoded = channel.getConfig().getBufferFactory()
    .getBuffer(data.order(), data.readableBytes() + 2);
encoded.writeByte((byte) 0x00);
ChannelBuffer encoded = channel.getConfig().getBufferFactory().getBuffer(data.order(), 2);
encoded.writeByte((byte) 0xFF);
encoded.writeByte((byte) 0x00);
ChannelBuffer encoded = channel.getConfig().getBufferFactory().getBuffer(data.order(), dataLen + 5);

相关文章