Interface KeyAffinityService<K>

All Superinterfaces:
Lifecycle
All Known Implementing Classes:
KeyAffinityServiceImpl

public interface KeyAffinityService<K> extends Lifecycle
Defines a service that generates keys to be mapped to specific nodes in a distributed(vs. replicated) cluster. The service is instantiated through through one of the factory methods from 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.

Since:
4.1
Author:
Mircea.Markus@jboss.com
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    getCollocatedKey(K otherKey)
    Returns a key that will be distributed on the same node as the supplied key.
    Returns a key that will be distributed on the cluster node identified by address.
    boolean
    Checks weather or not the service is started.

    Methods inherited from interface org.infinispan.commons.api.Lifecycle

    start, stop
  • Method Details

    • getKeyForAddress

      K getKeyForAddress(Address address)
      Returns a key that will be distributed on the cluster node identified by address.
      Parameters:
      address - identifying the cluster node.
      Returns:
      a key object
      Throws:
      IllegalStateException - if the service has not been started or it is shutdown
    • getCollocatedKey

      K getCollocatedKey(K otherKey)
      Returns a key that will be distributed on the same node as the supplied key.
      Parameters:
      otherKey - the key for which we need a collocation
      Returns:
      a key object
      Throws:
      IllegalStateException - if the service has not been started or it is shutdown
    • isStarted

      boolean isStarted()
      Checks weather or not the service is started.