Class SessionAffinityService<K>

java.lang.Object
org.keycloak.models.sessions.infinispan.SessionAffinityService<K>
Type Parameters:
K - the type of keys generated by this service
All Implemented Interfaces:
Supplier<K>

public class SessionAffinityService<K> extends Object implements Supplier<K>
A key affinity service that generates keys with affinity to the local node in a distributed cache.

This service provides similar functionality to KeyAffinityService, but with a more lenient, best-effort approach. Unlike KeyAffinityService, this implementation never blocks or throws exceptions when unable to generate a key belonging to the local node. Instead, it attempts to generate an affine key up to 32 times, and if unsuccessful, returns a random key.

The service automatically tracks topology changes and updates its knowledge of which cache segments are owned by the local node. It prefers keys that map to primary segments owned by this node, but falls back to backup segments if no primary segments are available.

  • Field Details

  • Constructor Details

    • SessionAffinityService

      public SessionAffinityService(Supplier<K> generator, org.infinispan.distribution.ch.KeyPartitioner keyPartitioner, org.infinispan.remoting.transport.Address localAddress)
  • Method Details

    • create

      public static <T> Supplier<T> create(org.infinispan.Cache<T,?> cache, Supplier<T> generator)
    • get

      public K get()
      Specified by:
      get in interface Supplier<K>
    • handleViewChange

      public void handleViewChange(org.infinispan.notifications.cachelistener.event.TopologyChangedEvent<K,?> tce)