List of usage examples for io.netty.util Attribute setIfAbsent
T setIfAbsent(T value);
From source file:com.ebay.jetstream.http.netty.server.KeepAliveHandler.java
License:MIT License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { Attribute<AtomicInteger> attr = ctx.attr(REQUEST_COUNT); if (attr.get() == null) { attr.setIfAbsent(new AtomicInteger()); }/*from w w w. j a va 2s . c om*/ attr.get().incrementAndGet(); ctx.fireChannelRead(msg); }
From source file:com.linecorp.armeria.common.logback.RequestContextExportingAppender.java
License:Apache License
private static State state(RequestContext ctx) { final Attribute<State> attr = ctx.attr(STATE); final State state = attr.get(); if (state == null) { final State newState = new State(); final State oldState = attr.setIfAbsent(newState); if (oldState != null) { return oldState; } else {/*from w ww . j a v a2 s . c o m*/ return newState; } } return state; }
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 ww w . ja v a 2 s . c o 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));//w w w . ja v a 2 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:de.unipassau.isl.evs.ssh.core.network.handler.TimeoutHandler.java
License:Open Source License
public static boolean getPingEnabled(Channel ch) { final Attribute<Boolean> attr = ch.attr(SEND_PINGS); attr.setIfAbsent(false); return attr.get(); }
From source file:org.jupiter.registry.ConfigClient.java
License:Apache License
private static boolean attachPublishEventOnChannel(RegisterMeta meta, Channel channel) { Attribute<ConcurrentSet<RegisterMeta>> attr = channel.attr(C_PUBLISH_KEY); ConcurrentSet<RegisterMeta> registerMetaSet = attr.get(); if (registerMetaSet == null) { ConcurrentSet<RegisterMeta> newRegisterMetaSet = new ConcurrentSet<>(); registerMetaSet = attr.setIfAbsent(newRegisterMetaSet); if (registerMetaSet == null) { registerMetaSet = newRegisterMetaSet; }/*w w w .j ava 2s .c om*/ } return registerMetaSet.add(meta); }
From source file:org.jupiter.registry.ConfigClient.java
License:Apache License
private static boolean attachSubscribeEventOnChannel(ServiceMeta serviceMeta, Channel channel) { Attribute<ConcurrentSet<ServiceMeta>> attr = channel.attr(C_SUBSCRIBE_KEY); ConcurrentSet<ServiceMeta> serviceMetaSet = attr.get(); if (serviceMetaSet == null) { ConcurrentSet<ServiceMeta> newServiceMetaSet = new ConcurrentSet<>(); serviceMetaSet = attr.setIfAbsent(newServiceMetaSet); if (serviceMetaSet == null) { serviceMetaSet = newServiceMetaSet; }/*from w w w .j av a 2 s. co m*/ } return serviceMetaSet.add(serviceMeta); }
From source file:org.jupiter.registry.ConfigServer.java
License:Apache License
private static boolean attachPublishEventOnChannel(RegisterMeta meta, Channel channel) { Attribute<ConcurrentSet<RegisterMeta>> attr = channel.attr(S_PUBLISH_KEY); ConcurrentSet<RegisterMeta> registerMetaSet = attr.get(); if (registerMetaSet == null) { ConcurrentSet<RegisterMeta> newRegisterMetaSet = new ConcurrentSet<>(); registerMetaSet = attr.setIfAbsent(newRegisterMetaSet); if (registerMetaSet == null) { registerMetaSet = newRegisterMetaSet; }//from w w w . j av a 2 s .co m } return registerMetaSet.add(meta); }
From source file:org.jupiter.registry.ConfigServer.java
License:Apache License
private static boolean attachPublishCancelEventOnChannel(RegisterMeta meta, Channel channel) { Attribute<ConcurrentSet<RegisterMeta>> attr = channel.attr(S_PUBLISH_KEY); ConcurrentSet<RegisterMeta> registerMetaSet = attr.get(); if (registerMetaSet == null) { ConcurrentSet<RegisterMeta> newRegisterMetaSet = new ConcurrentSet<>(); registerMetaSet = attr.setIfAbsent(newRegisterMetaSet); if (registerMetaSet == null) { registerMetaSet = newRegisterMetaSet; }//from w ww.ja v a2 s . com } return registerMetaSet.remove(meta); }
From source file:org.jupiter.registry.ConfigServer.java
License:Apache License
private static boolean attachSubscribeEventOnChannel(ServiceMeta serviceMeta, Channel channel) { Attribute<ConcurrentSet<ServiceMeta>> attr = channel.attr(S_SUBSCRIBE_KEY); ConcurrentSet<ServiceMeta> serviceMetaSet = attr.get(); if (serviceMetaSet == null) { ConcurrentSet<ServiceMeta> newServiceMetaSet = new ConcurrentSet<>(); serviceMetaSet = attr.setIfAbsent(newServiceMetaSet); if (serviceMetaSet == null) { serviceMetaSet = newServiceMetaSet; }/*from www .j av a2s . c o m*/ } return serviceMetaSet.add(serviceMeta); }