public interface KeyAffinityService<K> extends Lifecycle
KeyAffinityServiceFactory
.
Sample usage:
Cache<String, Long> cache = getDistributedCache();
KeyAffinityService<String> service = KeyAffinityServiceFactory.newKeyAffinityService(cache, 100);
...
String sessionId = sessionObject.getId();
String newCollocatedSession = service.getCollocatedKey(sessionId);
//this will reside on the same node in the cluster
cache.put(newCollocatedSession, someInfo);
Uniqueness: the service does not guarantee that the generated keys are unique. It relies on an
KeyGenerator
for obtaining and distributing the generated keys. If key uniqueness is
needed that should be enforced in the generator.
The service might also drop key generated through the KeyGenerator
.KeyAffinityServiceFactory
Modifier and Type | Method and Description |
---|---|
K |
getCollocatedKey(K otherKey)
Returns a key that will be distributed on the same node as the supplied key.
|
K |
getKeyForAddress(Address address)
Returns a key that will be distributed on the cluster node identified by address.
|
boolean |
isStarted()
Checks weather or not the service is started.
|
K getKeyForAddress(Address address)
address
- identifying the cluster node.IllegalStateException
- if the service has not been started or it is shutdownK getCollocatedKey(K otherKey)
otherKey
- the key for which we need a collocationIllegalStateException
- if the service has not been started or it is shutdownboolean isStarted()
Copyright © 2018 JBoss, a division of Red Hat. All rights reserved.