Search in sources :

Example 1 with StaticRingProvider

use of com.linkedin.d2.balancer.util.hashing.StaticRingProvider in project rest.li by linkedin.

the class TestScatterGather method getKeyToHostMapper.

private static ConsistentHashKeyMapper getKeyToHostMapper(int n, int partitionNum) throws URISyntaxException {
    Map<URI, Integer> endpoints = new HashMap<URI, Integer>();
    for (int ii = 0; ii < n; ++ii) {
        endpoints.put(new URI("test" + String.valueOf(ii)), 100);
    }
    final int partitionSize = endpoints.size() / partitionNum;
    List<Map<URI, Integer>> mapList = new ArrayList<Map<URI, Integer>>();
    int count = 0;
    for (final URI uri : endpoints.keySet()) {
        final int index = count / partitionSize;
        if (index == mapList.size()) {
            mapList.add(new HashMap<URI, Integer>());
        }
        Map<URI, Integer> map = mapList.get(index);
        map.put(uri, endpoints.get(uri));
        count++;
    }
    List<Ring<URI>> rings = new ArrayList<Ring<URI>>();
    for (final Map<URI, Integer> map : mapList) {
        final ConsistentHashRing<URI> ring = new ConsistentHashRing<URI>(map);
        rings.add(ring);
    }
    return new ConsistentHashKeyMapper(new StaticRingProvider(rings), new TestPartitionInfoProvider());
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StaticRingProvider(com.linkedin.d2.balancer.util.hashing.StaticRingProvider) URI(java.net.URI) ConsistentHashRing(com.linkedin.d2.balancer.util.hashing.ConsistentHashRing) ConsistentHashRing(com.linkedin.d2.balancer.util.hashing.ConsistentHashRing) Ring(com.linkedin.d2.balancer.util.hashing.Ring) ConsistentHashKeyMapper(com.linkedin.d2.balancer.util.hashing.ConsistentHashKeyMapper) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DataMap(com.linkedin.data.DataMap)

Aggregations

ConsistentHashKeyMapper (com.linkedin.d2.balancer.util.hashing.ConsistentHashKeyMapper)1 ConsistentHashRing (com.linkedin.d2.balancer.util.hashing.ConsistentHashRing)1 Ring (com.linkedin.d2.balancer.util.hashing.Ring)1 StaticRingProvider (com.linkedin.d2.balancer.util.hashing.StaticRingProvider)1 DataMap (com.linkedin.data.DataMap)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1