Class DefaultKeyAffinityService<K>

  • All Implemented Interfaces:
    Supplier<BlockingQueue<K>>, org.infinispan.affinity.KeyAffinityService<K>, org.infinispan.commons.api.Lifecycle

    public class DefaultKeyAffinityService<K>
    extends Object
    implements org.infinispan.affinity.KeyAffinityService<K>, Supplier<BlockingQueue<K>>
    A custom key affinity service implementation with the following distinct characteristics (as compared to KeyAffinityServiceImpl):
    • getKeyForAddress(Address) will return a random key (instead of throwing an ISE) if the specified address does not own any segments.
    • Uses a worker thread per address for which to generate keys.
    • Minimal CPU utilization when key queues are full.
    • Non-blocking topology change event handler.
    • getKeyForAddress(Address) calls will not block during topology change events.
    Author:
    Paul Ferraro
    • Constructor Detail

      • DefaultKeyAffinityService

        public DefaultKeyAffinityService​(org.infinispan.Cache<? extends K,​?> cache,
                                         org.infinispan.affinity.KeyGenerator<? extends K> generator,
                                         Predicate<org.infinispan.remoting.transport.Address> filter)
        Constructs a key affinity service that generates keys hashing to the members matching the specified filter.
        Parameters:
        cache - the target cache
        generator - a key generator
    • Method Detail

      • setQueueSize

        public void setQueueSize​(int size)
        Overrides the maximum number of keys with affinity to a given member to pre-generate.
        Parameters:
        size - a queue size threshold
      • setPollTimeout

        public void setPollTimeout​(Duration timeout)
        Overrides the duration of time for which calls to getKeyForAddress(Address) will wait for an available pre-generated key, after which a random key will be returned.
        Parameters:
        timeout - a queue poll timeout
      • isStarted

        public boolean isStarted()
        Specified by:
        isStarted in interface org.infinispan.affinity.KeyAffinityService<K>
      • start

        public void start()
        Specified by:
        start in interface org.infinispan.commons.api.Lifecycle
      • stop

        public void stop()
        Specified by:
        stop in interface org.infinispan.commons.api.Lifecycle
      • getCollocatedKey

        public K getCollocatedKey​(K otherKey)
        Specified by:
        getCollocatedKey in interface org.infinispan.affinity.KeyAffinityService<K>
      • getKeyForAddress

        public K getKeyForAddress​(org.infinispan.remoting.transport.Address address)
        Specified by:
        getKeyForAddress in interface org.infinispan.affinity.KeyAffinityService<K>
      • topologyChanged

        public CompletionStage<Void> topologyChanged​(org.infinispan.notifications.cachelistener.event.TopologyChangedEvent<?,​?> event)