Class DefaultKeyAffinityService<K>

java.lang.Object
org.wildfly.clustering.cache.infinispan.embedded.affinity.DefaultKeyAffinityService<K>
Type Parameters:
K - the cache key type
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
  • Method Details

    • 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
    • get

      public BlockingQueue<K> get()
      Specified by:
      get in interface Supplier<K>
    • 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)
      Handler for topology change events.
      Parameters:
      event - a topology change event
      Returns:
      a completion stage