Class DefaultKeyAffinityService<K>
java.lang.Object
org.wildfly.clustering.infinispan.affinity.impl.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 Summary
ConstructorsConstructorDescriptionDefaultKeyAffinityService(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. -
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)
-
Constructor Details
-
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 cachegenerator- a key generator
-
-
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
- Specified by:
getCollocatedKeyin interfaceorg.infinispan.affinity.KeyAffinityService<K>
-
getKeyForAddress
- Specified by:
getKeyForAddressin interfaceorg.infinispan.affinity.KeyAffinityService<K>
-
topologyChanged
public CompletionStage<Void> topologyChanged(org.infinispan.notifications.cachelistener.event.TopologyChangedEvent<?, ?> event)
-