Java Code Examples for io.netty.util.collection.IntObjectMap#put()

The following examples show how to use io.netty.util.collection.IntObjectMap#put() . 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: DnsQueryContextManager.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
int add(DnsQueryContext qCtx) {
    final IntObjectMap<DnsQueryContext> contexts = getOrCreateContextMap(qCtx.nameServerAddr());

    int id = PlatformDependent.threadLocalRandom().nextInt(65536 - 1) + 1;
    final int maxTries = 65535 << 1;
    int tries = 0;

    synchronized (contexts) {
        for (;;) {
            if (!contexts.containsKey(id)) {
                contexts.put(id, qCtx);
                return id;
            }

            id = id + 1 & 0xFFFF;

            if (++tries >= maxTries) {
                throw new IllegalStateException("query ID space exhausted: " + qCtx.question());
            }
        }
    }
}
 
Example 2
Source File: RoundRobinProxyHandler.java    From xio with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
Optional<ClientConfig> getClientConfig(
    IntObjectMap<Optional<ClientConfig>> cachedClientConfig, Request request) {
  int hashKey = request.streamId();
  // we only do a fresh round robin if the request is a either a FULL HTTP REQUEST or the First Part of a Chunked Requets
  if (request.isFullMessage()) {
    return computationFunction.get();
  } else if (request.startOfMessage()) {
    Optional<ClientConfig> newClientConfig = computationFunction.get();
    cachedClientConfig.put(hashKey, newClientConfig);
    return newClientConfig;
  } else if (request.endOfMessage()) {
    return cachedClientConfig.remove(hashKey);
  } else {
    return cachedClientConfig.get(hashKey);
  }
}
 
Example 3
Source File: StreamIdSupplierTest.java    From rsocket-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testSkipFound() {
  IntObjectMap<Object> map = new SynchronizedIntObjectHashMap<>();
  map.put(5, new Object());
  map.put(9, new Object());
  StreamIdSupplier s = StreamIdSupplier.clientSupplier();
  assertEquals(1, s.nextStreamId(map));
  assertEquals(3, s.nextStreamId(map));
  assertEquals(7, s.nextStreamId(map));
  assertEquals(11, s.nextStreamId(map));
}