Example usage for io.netty.util AttributeKey valueOf

List of usage examples for io.netty.util AttributeKey valueOf

Introduction

In this page you can find the example usage for io.netty.util AttributeKey valueOf.

Prototype

@SuppressWarnings("unchecked")
public static <T> AttributeKey<T> valueOf(String name) 

Source Link

Document

Returns the singleton instance of the AttributeKey which has the specified name .

Usage

From source file:com.farsunset.cim.sdk.server.session.CIMSession.java

License:Apache License

public Object getAttribute(String key) {
    if (session != null)
        return session.attr(AttributeKey.valueOf(key)).get();
    return null;
}

From source file:com.farsunset.cim.sdk.server.session.CIMSession.java

License:Apache License

public void removeAttribute(String key) {
    if (session != null)
        session.attr(AttributeKey.valueOf(key)).set(null);
    ;
}

From source file:com.heliosapm.webrpc.jsonservice.JSONResponse.java

License:Apache License

/**
 * Sets a channel option/*from  ww  w  .jav  a  2s .c  o m*/
 * @param name The option name
 * @param value The option value
 * @return this JSONResponse
 */
public JSONResponse setChannelOption(final String name, final Object value) {
    channel.attr(AttributeKey.valueOf(name)).setIfAbsent(value);
    return this;
}

From source file:com.heliosapm.webrpc.jsonservice.JSONResponse.java

License:Apache License

/**
 * Removes a channel option/*from  w ww  . j  a  va  2s  . co m*/
 * @param name The name of the option to remove
 * @return this JSONReponse
 */
public JSONResponse removeChannelOption(final String name) {
    channel.attr(AttributeKey.valueOf(name)).set(null);
    return this;
}

From source file:com.heliosapm.webrpc.jsonservice.JSONResponse.java

License:Apache License

/**
 * Retrieves a channel option/*from ww  w.  j a  v  a2  s  . c  o m*/
 * @param name The name of the option to retrieve
 * @param defaultOption The default value to return if the named option was not bound.
 * @return the named channel option or the defalt if it was not found.
 */
public Object getChannelOption(final String name, final Object defaultOption) {
    Object value = channel.attr(AttributeKey.valueOf(name)).get();
    return value != null ? value : defaultOption;
}

From source file:com.linecorp.armeria.common.logback.RequestContextExporterBuilder.java

License:Apache License

void export(String mdcKey) {
    requireNonNull(mdcKey, "mdcKey");

    final Optional<BuiltInProperty> opt = BuiltInProperty.findByMdcKey(mdcKey);
    if (opt.isPresent()) {
        builtIns.add(opt.get());//from   w  ww .  j a  v a2  s  . c o m
        return;
    }

    if (mdcKey.startsWith(PREFIX_ATTRS)) {
        final String[] components = mdcKey.split(":");
        switch (components.length) {
        case 2:
            addAttribute(components[0].substring(PREFIX_ATTRS.length()), AttributeKey.valueOf(components[1]));
            break;
        case 3:
            final Function<?, String> stringifier = newStringifier(mdcKey, components[2]);

            addAttribute(components[0].substring(PREFIX_ATTRS.length()), AttributeKey.valueOf(components[1]),
                    stringifier);
            break;
        default:
            throw new IllegalArgumentException("invalid attribute export: " + mdcKey
                    + " (expected: attrs.<alias>:<AttributeKey.name>[:<FQCN of Function<?, String>>])");
        }
        return;
    }

    if (mdcKey.startsWith(PREFIX_HTTP_REQ_HEADERS)) {
        addHttpRequestHeader(mdcKey.substring(PREFIX_HTTP_REQ_HEADERS.length()));
        return;
    }

    if (mdcKey.startsWith(PREFIX_HTTP_RES_HEADERS)) {
        addHttpResponseHeader(mdcKey.substring(PREFIX_HTTP_RES_HEADERS.length()));
        return;
    }

    throw new IllegalArgumentException("unknown MDC key: " + mdcKey);
}

From source file:com.linecorp.armeria.common.logback.RequestContextExportingAppenderTest.java

License:Apache License

@Test
public void testXmlConfig() throws Exception {
    try {//from   w  ww  . j  a v  a 2 s .co  m
        final JoranConfigurator configurator = new JoranConfigurator();
        configurator.setContext(context);
        context.reset();

        configurator.doConfigure(getClass().getResource("testXmlConfig.xml"));

        final RequestContextExportingAppender rcea = (RequestContextExportingAppender) logger
                .getAppender("RCEA");

        assertThat(rcea).isNotNull();
        assertThat(rcea.getBuiltIns()).containsExactly(BuiltInProperty.REMOTE_HOST);
        assertThat(rcea.getHttpRequestHeaders()).containsExactly(HttpHeaderNames.USER_AGENT);
        assertThat(rcea.getHttpResponseHeaders()).containsExactly(HttpHeaderNames.SET_COOKIE);

        final AttributeKey<Object> fooAttr = AttributeKey.valueOf("com.example.AttrKeys#FOO");
        final AttributeKey<Object> barAttr = AttributeKey.valueOf("com.example.AttrKeys#BAR");
        assertThat(rcea.getAttributes()).containsOnly(new SimpleEntry<>("foo", fooAttr),
                new SimpleEntry<>("bar", barAttr));
    } finally {
        // Revert to the original configuration.
        final JoranConfigurator configurator = new JoranConfigurator();
        configurator.setContext(context);
        context.reset();

        configurator.doConfigure(getClass().getResource("/logback-test.xml"));
    }
}

From source file:com.linecorp.armeria.internal.DefaultAttributeMapTest.java

License:Apache License

@Test
public void testGetSetString() {
    AttributeKey<String> key = AttributeKey.valueOf("Nothing");
    Attribute<String> one = map.attr(key);

    assertSame(one, map.attr(key));/*from  w  w w  .  j  a v a2 s. co m*/

    one.setIfAbsent("Whoohoo");
    assertSame("Whoohoo", one.get());

    one.setIfAbsent("What");
    assertNotSame("What", one.get());

    one.remove();
    assertNull(one.get());
}

From source file:com.linecorp.armeria.internal.DefaultAttributeMapTest.java

License:Apache License

@Test
public void testGetSetInt() {
    AttributeKey<Integer> key = AttributeKey.valueOf("Nada");
    Attribute<Integer> one = map.attr(key);

    assertSame(one, map.attr(key));//from   ww  w  . j av a2  s  .  c o  m

    one.setIfAbsent(3653);
    assertEquals(Integer.valueOf(3653), one.get());

    one.setIfAbsent(1);
    assertNotSame(1, one.get());

    one.remove();
    assertNull(one.get());
}

From source file:com.linecorp.armeria.internal.DefaultAttributeMapTest.java

License:Apache License

@Test
public void testSetRemove() {
    AttributeKey<Integer> key = AttributeKey.valueOf("key");

    Attribute<Integer> attr = map.attr(key);
    attr.set(1);/*from w w  w  . ja  v  a 2  s.c o  m*/
    assertSame(1, attr.getAndRemove());

    Attribute<Integer> attr2 = map.attr(key);
    attr2.set(2);
    assertSame(2, attr2.get());
    assertNotSame(attr, attr2);
}