Interface KeyAffinityService<K>

  • All Superinterfaces:
    Lifecycle

    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:
    KeyAffinityServiceFactory
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      K getCollocatedKey​(K otherKey)
      Returns a key that will be distributed on the same node as the supplied key.
      K getKeyForAddress​(org.infinispan.remoting.transport.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.
    • Method Detail

      • getKeyForAddress

        K getKeyForAddress​(org.infinispan.remoting.transport.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.