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 Summary
Modifier and TypeMethodDescriptionget()getCollocatedKey(K otherKey) getKeyForAddress(org.infinispan.remoting.transport.Address address) booleanvoidsetPollTimeout(Duration timeout) Overrides the duration of time for which calls togetKeyForAddress(Address)will wait for an available pre-generated key, after which a random key will be returned.voidsetQueueSize(int size) Overrides the maximum number of keys with affinity to a given member to pre-generate.voidstart()voidstop()topologyChanged(org.infinispan.notifications.cachelistener.event.TopologyChangedEvent<?, ?> event) Handler for topology change events.
-
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
Overrides the duration of time for which calls togetKeyForAddress(Address)will wait for an available pre-generated key, after which a random key will be returned.- Parameters:
timeout- a queue poll timeout
-
get
-
isStarted
public boolean isStarted()- Specified by:
isStartedin interfaceorg.infinispan.affinity.KeyAffinityService<K>
-
start
public void start()- Specified by:
startin interfaceorg.infinispan.commons.api.Lifecycle
-
stop
public void stop()- Specified by:
stopin interfaceorg.infinispan.commons.api.Lifecycle
-
getCollocatedKey
-
getKeyForAddress
-
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
-