本文整理汇总了Java中io.netty.util.AttributeKey.valueOf方法的典型用法代码示例。如果您正苦于以下问题:Java AttributeKey.valueOf方法的具体用法?Java AttributeKey.valueOf怎么用?Java AttributeKey.valueOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.util.AttributeKey
的用法示例。
在下文中一共展示了AttributeKey.valueOf方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGetSetString
import io.netty.util.AttributeKey; //导入方法依赖的package包/类
@Test
public void testGetSetString() {
AttributeKey<String> key = AttributeKey.valueOf("Nothing");
Attribute<String> one = map.attr(key);
assertSame(one, map.attr(key));
one.setIfAbsent("Whoohoo");
assertSame("Whoohoo", one.get());
one.setIfAbsent("What");
assertNotSame("What", one.get());
one.remove();
assertNull(one.get());
}
示例2: testGetSetInt
import io.netty.util.AttributeKey; //导入方法依赖的package包/类
@Test
public void testGetSetInt() {
AttributeKey<Integer> key = AttributeKey.valueOf("Nada");
Attribute<Integer> one = map.attr(key);
assertSame(one, map.attr(key));
one.setIfAbsent(3653);
assertEquals(Integer.valueOf(3653), one.get());
one.setIfAbsent(1);
assertNotSame(1, one.get());
one.remove();
assertNull(one.get());
}
示例3: channelInactive
import io.netty.util.AttributeKey; //导入方法依赖的package包/类
/**
* 连接被关闭
* @param ctx
* @throws Exception
*/
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
AttributeKey<Session> attrKeySession = AttributeKey.valueOf("Session");
Attribute<Session> attrSession = ctx.attr(attrKeySession);
Session session = attrSession.get();
logger.warn("client diconnect!");
super.channelInactive(ctx);
}
示例4: testMutabilityAndImmutability
import io.netty.util.AttributeKey; //导入方法依赖的package包/类
@Test
public void testMutabilityAndImmutability() {
final AttributeKey<Object> someAttr =
AttributeKey.valueOf(RequestContextExportingAppenderTest.class, "SOME_ATTR");
final RequestContextExportingAppender a = new RequestContextExportingAppender();
// Ensure mutability before start.
a.addBuiltIn(BuiltInProperty.ELAPSED_NANOS);
assertThat(a.getBuiltIns()).containsExactly(BuiltInProperty.ELAPSED_NANOS);
a.addAttribute("some-attr", someAttr);
assertThat(a.getAttributes()).containsOnlyKeys("some-attr")
.containsValue(someAttr);
a.addHttpRequestHeader(HttpHeaderNames.USER_AGENT);
assertThat(a.getHttpRequestHeaders()).containsExactly(HttpHeaderNames.USER_AGENT);
a.addHttpResponseHeader(HttpHeaderNames.SET_COOKIE);
assertThat(a.getHttpResponseHeaders()).containsExactly(HttpHeaderNames.SET_COOKIE);
final ListAppender<ILoggingEvent> la = new ListAppender<>();
a.addAppender(la);
a.start();
la.start();
// Ensure immutability after start.
assertThatThrownBy(() -> a.addBuiltIn(BuiltInProperty.REQ_PATH))
.isExactlyInstanceOf(IllegalStateException.class);
assertThatThrownBy(() -> a.addAttribute("my-attr", MY_ATTR))
.isExactlyInstanceOf(IllegalStateException.class);
assertThatThrownBy(() -> a.addHttpRequestHeader(HttpHeaderNames.ACCEPT))
.isExactlyInstanceOf(IllegalStateException.class);
assertThatThrownBy(() -> a.addHttpResponseHeader(HttpHeaderNames.DATE))
.isExactlyInstanceOf(IllegalStateException.class);
}
示例5: AttributeComponent
import io.netty.util.AttributeKey; //导入方法依赖的package包/类
AttributeComponent(String attributeName, Function<Object, String> stringifer, boolean addQuote,
@Nullable Function<HttpHeaders, Boolean> condition) {
super(condition);
key = AttributeKey.valueOf(requireNonNull(attributeName, "attributeName"));
this.stringifer = requireNonNull(stringifer, "stringifer");
this.addQuote = addQuote;
}
示例6: deriveContext
import io.netty.util.AttributeKey; //导入方法依赖的package包/类
@Test
public void deriveContext() {
final DefaultClientRequestContext originalCtx = new DefaultClientRequestContext(
mock(EventLoop.class), NoopMeterRegistry.get(), SessionProtocol.H2C,
Endpoint.of("example.com", 8080), HttpMethod.POST, "/foo", null, null,
ClientOptions.DEFAULT, mock(Request.class));
final AttributeKey<String> foo = AttributeKey.valueOf(DefaultClientRequestContextTest.class, "foo");
originalCtx.attr(foo).set("foo");
Request newRequest = mock(Request.class);
final ClientRequestContext derivedCtx = originalCtx.newDerivedContext(newRequest);
assertThat(derivedCtx.endpoint()).isSameAs(originalCtx.endpoint());
assertThat(derivedCtx.sessionProtocol()).isSameAs(originalCtx.sessionProtocol());
assertThat(derivedCtx.method()).isSameAs(originalCtx.method());
assertThat(derivedCtx.options()).isSameAs(originalCtx.options());
assertThat(derivedCtx.<Request>request()).isSameAs(newRequest);
assertThat(derivedCtx.path()).isEqualTo(originalCtx.path());
assertThat(derivedCtx.maxResponseLength()).isEqualTo(originalCtx.maxResponseLength());
assertThat(derivedCtx.responseTimeoutMillis()).isEqualTo(originalCtx.responseTimeoutMillis());
assertThat(derivedCtx.writeTimeoutMillis()).isEqualTo(originalCtx.writeTimeoutMillis());
// the attribute is derived as well
assertThat(derivedCtx.attr(foo).get()).isEqualTo("foo");
// log is different
assertThat(derivedCtx.log()).isNotSameAs(originalCtx.log());
final AttributeKey<String> bar = AttributeKey.valueOf(DefaultClientRequestContextTest.class, "bar");
originalCtx.attr(bar).set("bar");
// the Attribute added to the original context after creation is not propagated to the derived context
assertThat(derivedCtx.attr(bar).get()).isEqualTo(null);
}
示例7: deriveContext
import io.netty.util.AttributeKey; //导入方法依赖的package包/类
@Test
public void deriveContext() {
final VirtualHost virtualHost = virtualHost();
final DefaultPathMappingContext mappingCtx = new DefaultPathMappingContext(
virtualHost, "example.com", HttpMethod.GET, "/hello", null, MediaType.JSON_UTF_8,
ImmutableList.of(MediaType.JSON_UTF_8, MediaType.XML_UTF_8));
final ServiceRequestContext originalCtx = new DefaultServiceRequestContext(
virtualHost.serviceConfigs().get(0), mock(Channel.class), NoopMeterRegistry.get(),
SessionProtocol.H2,
mappingCtx, PathMappingResult.of("/foo", null, ImmutableMap.of()), mock(Request.class), null);
final AttributeKey<String> foo = AttributeKey.valueOf(DefaultServiceRequestContextTest.class, "foo");
originalCtx.attr(foo).set("foo");
Request newRequest = mock(Request.class);
final ServiceRequestContext derivedCtx = originalCtx.newDerivedContext(newRequest);
assertThat(derivedCtx.server()).isSameAs(originalCtx.server());
assertThat(derivedCtx.sessionProtocol()).isSameAs(originalCtx.sessionProtocol());
assertThat(derivedCtx.<Service<HttpRequest, HttpResponse>>service()).isSameAs(originalCtx.service());
assertThat(derivedCtx.pathMapping()).isSameAs(originalCtx.pathMapping());
assertThat(derivedCtx.<Request>request()).isSameAs(newRequest);
assertThat(derivedCtx.path()).isEqualTo(originalCtx.path());
assertThat(derivedCtx.maxRequestLength()).isEqualTo(originalCtx.maxRequestLength());
assertThat(derivedCtx.requestTimeoutMillis()).isEqualTo(originalCtx.requestTimeoutMillis());
// the attribute is derived as well
assertThat(derivedCtx.attr(foo).get()).isEqualTo("foo");
// log is different
assertThat(derivedCtx.log()).isNotSameAs(originalCtx.log());
final AttributeKey<String> bar = AttributeKey.valueOf(DefaultServiceRequestContextTest.class, "bar");
originalCtx.attr(bar).set("bar");
// the Attribute added to the original context after creation is not propagated to the derived context
assertThat(derivedCtx.attr(bar).get()).isEqualTo(null);
}
示例8: testSetRemove
import io.netty.util.AttributeKey; //导入方法依赖的package包/类
@Test
public void testSetRemove() {
AttributeKey<Integer> key = AttributeKey.valueOf("key");
Attribute<Integer> attr = map.attr(key);
attr.set(1);
assertSame(1, attr.getAndRemove());
Attribute<Integer> attr2 = map.attr(key);
attr2.set(2);
assertSame(2, attr2.get());
assertNotSame(attr, attr2);
}
示例9: testGetAndSetWithNull
import io.netty.util.AttributeKey; //导入方法依赖的package包/类
@Test
public void testGetAndSetWithNull() {
AttributeKey<Integer> key = AttributeKey.valueOf("key");
Attribute<Integer> attr = map.attr(key);
attr.set(1);
assertSame(1, attr.getAndSet(null));
Attribute<Integer> attr2 = map.attr(key);
attr2.set(2);
assertSame(2, attr2.get());
assertSame(attr, attr2);
}
示例10: testIteratorWithSparseMap
import io.netty.util.AttributeKey; //导入方法依赖的package包/类
@Test
public void testIteratorWithSparseMap() {
final AttributeKey<Integer> key = AttributeKey.valueOf(DefaultAttributeMap.class, "KEY");
map.attr(key).set(42);
final List<Attribute<?>> attrs = Lists.newArrayList(map.attrs());
assertEquals(Collections.singletonList(map.attr(key)), attrs);
map.attr(key).remove();
assertFalse(map.attrs().hasNext());
}
示例11: testIteratorWithFullMap
import io.netty.util.AttributeKey; //导入方法依赖的package包/类
@Test
public void testIteratorWithFullMap() {
final List<AttributeKey<Integer>> expectedKeys = new ArrayList<>();
for (int i = 0; i < 1024; i++) {
final AttributeKey<Integer> key =
AttributeKey.valueOf(DefaultAttributeMapTest.class, String.valueOf(i));
expectedKeys.add(key);
map.attr(key).set(i);
}
// Make sure all buckets are filled.
for (int i = 0; i < map.attributes.length(); i++) {
assertNotNull(map.attributes.get(i));
}
// Make sure the Iterator yields all attributes.
assertEquals(expectedKeys, actualKeys());
// Make sure the Iterator does not yield the attributes whose 'removed' property is 'true'.
for (int i = 0; i < map.attributes.length(); i++) {
Attribute<?> a = map.attributes.get(i);
a.remove();
// A head attribute is never removed from the linked list.
assertSame(a, map.attributes.get(i));
// Remove the removed key from the list of expected expectedKeys.
expectedKeys.remove(a.key());
}
assertEquals(expectedKeys, actualKeys());
}
示例12: testNewChannel
import io.netty.util.AttributeKey; //导入方法依赖的package包/类
@Test
public void testNewChannel() {
final AttributeKey<String> attributeKey = AttributeKey.valueOf(getClass(), "attributeKey");
final AugmentingReflectiveChannelFactory<LocalChannel, String> factory =
new AugmentingReflectiveChannelFactory<>(LocalChannel.class, attributeKey, "Test!");
final LocalChannel channel = factory.newChannel();
assertTrue("Newly-created channels should have attribute provided to factory.",
channel.hasAttr(attributeKey));
}
示例13: keyFor
import io.netty.util.AttributeKey; //导入方法依赖的package包/类
private static <T> AttributeKey<T> keyFor(String name) {
return AttributeKey.valueOf("yarpc." + name);
}