Java Code Examples for io.netty.util.AttributeKey#newInstance()

The following examples show how to use io.netty.util.AttributeKey#newInstance() . 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: NettyClient.java    From nuls-v2 with MIT License 6 votes vote down vote up
public NettyClient(Node node) {
    this.node = node;
    boot = new Bootstrap();

    AttributeKey<Node> key = null;
    synchronized (NettyClient.class) {
        if (AttributeKey.exists("node")) {
            key = AttributeKey.valueOf("node");
        } else {
            key = AttributeKey.newInstance("node");
        }
    }
    boot.attr(key, node);
    boot.group(worker)
            .channel(NioSocketChannel.class)
            .option(ChannelOption.TCP_NODELAY, true)
            .option(ChannelOption.SO_KEEPALIVE, true)
            .option(ChannelOption.SO_SNDBUF, 128 * 1024)
            .option(ChannelOption.SO_RCVBUF, 128 * 1024)
            .option(ChannelOption.RCVBUF_ALLOCATOR, AdaptiveRecvByteBufAllocator.DEFAULT)
            .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
            .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONNETCI_TIME_OUT)
            .handler(new NulsChannelInitializer<>(new ClientChannelHandler()));
}
 
Example 2
Source File: Http2MultiplexCodecTest.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Test
public void settingChannelOptsAndAttrs() {
    AttributeKey<String> key = AttributeKey.newInstance("foo");

    Channel childChannel = newOutboundStream();
    childChannel.config().setAutoRead(false).setWriteSpinCount(1000);
    childChannel.attr(key).set("bar");
    assertFalse(childChannel.config().isAutoRead());
    assertEquals(1000, childChannel.config().getWriteSpinCount());
    assertEquals("bar", childChannel.attr(key).get());
}
 
Example 3
Source File: ConnectionManager.java    From nuls-v2 with MIT License 5 votes vote down vote up
private void cacheNode(Node node, SocketChannel channel) {

        String name = "node-" + node.getId();
        boolean exists = AttributeKey.exists(name);
        AttributeKey attributeKey;
        if (exists) {
            attributeKey = AttributeKey.valueOf(name);
        } else {
            attributeKey = AttributeKey.newInstance(name);
        }
        Attribute<Node> attribute = channel.attr(attributeKey);

        attribute.set(node);
    }
 
Example 4
Source File: NodeManager.java    From nuls with MIT License 5 votes vote down vote up
private void cacheNode(Node node, SocketChannel channel) {

        String name = "node-" + node.getId();
        boolean exists = AttributeKey.exists(name);
        AttributeKey attributeKey;
        if (exists) {
            attributeKey = AttributeKey.valueOf(name);
        } else {
            attributeKey = AttributeKey.newInstance(name);
        }
        Attribute<Node> attribute = channel.attr(attributeKey);
        attribute.set(node);
    }
 
Example 5
Source File: NettyUtils.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * @return an {@code AttributeKey} for {@code attr}. This returns an existing instance if it was previously created.
 */
public static <T> AttributeKey<T> getOrCreateAttributeKey(String attr) {
    if (AttributeKey.exists(attr)) {
        return AttributeKey.valueOf(attr);
    }
    //CHECKSTYLE:OFF - This is the only place allowed to call AttributeKey.newInstance()
    return AttributeKey.newInstance(attr);
    //CHECKSTYLE:ON
}
 
Example 6
Source File: NettyClientTransport.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
/**
 * Get the existing {@link ChannelLogger} key in case a separate, isolated class loader has
 * already created {@link LOGGER_KEY}.
 */
private static final AttributeKey<ChannelLogger> getOrCreateChannelLogger() {
  AttributeKey<ChannelLogger> key = AttributeKey.valueOf("channelLogger");
  if (key == null) {
    key = AttributeKey.newInstance("channelLogger");
  }
  return key;
}
 
Example 7
Source File: HttpChannelFlags.java    From zuul with Apache License 2.0 4 votes vote down vote up
public Flag(String name)
{
    attributeKey = AttributeKey.newInstance(name);
}