keycloak
公開メンバ関数 | 静的公開メンバ関数 | 限定公開メンバ関数 | 静的限定公開変数類 | 全メンバ一覧
org.keycloak.models.sessions.infinispan.remotestore.RemoteCacheSessionListener< K, V extends SessionEntity >.DontFetchInitialStateCacheListener クラス
org.keycloak.models.sessions.infinispan.remotestore.RemoteCacheSessionListener< K, V extends SessionEntity >.DontFetchInitialStateCacheListener の継承関係図
Inheritance graph
org.keycloak.models.sessions.infinispan.remotestore.RemoteCacheSessionListener< K, V extends SessionEntity >.DontFetchInitialStateCacheListener 連携図
Collaboration graph

公開メンバ関数

void created (ClientCacheEntryCreatedEvent event)
 
void updated (ClientCacheEntryModifiedEvent event)
 
void removed (ClientCacheEntryRemovedEvent event)
 

静的公開メンバ関数

static< K, V extends SessionEntity > RemoteCacheSessionListener createListener (KeycloakSession session, Cache< K, SessionEntityWrapper< V >> cache, RemoteCache< K, SessionEntityWrapper< V >> remoteCache)
 

限定公開メンバ関数

void init (KeycloakSession session, Cache< K, SessionEntityWrapper< V >> cache, RemoteCache< K, SessionEntityWrapper< V >> remoteCache)
 
void createRemoteEntityInCache (K key, long eventVersion)
 
void replaceRemoteEntityInCache (K key, long eventVersion)
 
boolean shouldUpdateLocalCache (ClientEvent.Type type, K key, boolean commandRetried)
 

静的限定公開変数類

static final Logger logger = Logger.getLogger(RemoteCacheSessionListener.class)
 

詳解

関数詳解

◆ created()

void org.keycloak.models.sessions.infinispan.remotestore.RemoteCacheSessionListener< K, V extends SessionEntity >.created ( ClientCacheEntryCreatedEvent  event)
inlineinherited
74  {
75  K key = (K) event.getKey();
76 
77  if (shouldUpdateLocalCache(event.getType(), key, event.isCommandRetried())) {
78  this.executor.submit(event, () -> {
79 
80  // Doesn't work due https://issues.jboss.org/browse/ISPN-9323. Needs to explicitly retrieve and create it
81  //cache.get(key);
82 
83  createRemoteEntityInCache(key, event.getVersion());
84 
85  });
86  }
87  }
boolean shouldUpdateLocalCache(ClientEvent.Type type, K key, boolean commandRetried)
Definition: RemoteCacheSessionListener.java:192
ClientListenerExecutorDecorator< K > executor
Definition: RemoteCacheSessionListener.java:55
void createRemoteEntityInCache(K key, long eventVersion)
Definition: RemoteCacheSessionListener.java:105

◆ createListener()

static <K, V extends SessionEntity> RemoteCacheSessionListener org.keycloak.models.sessions.infinispan.remotestore.RemoteCacheSessionListener< K, V extends SessionEntity >.createListener ( KeycloakSession  session,
Cache< K, SessionEntityWrapper< V >>  cache,
RemoteCache< K, SessionEntityWrapper< V >>  remoteCache 
)
inlinestaticinherited
223  {
224  /*boolean isCoordinator = InfinispanUtil.isCoordinator(cache);
225 
226  // Just cluster coordinator will fetch userSessions from remote cache.
227  // In case that coordinator is failover during state fetch, there is slight risk that not all userSessions will be fetched to local cluster. Assume acceptable for now
228  RemoteCacheSessionListener listener;
229  if (isCoordinator) {
230  logger.infof("Will fetch initial state from remote cache for cache '%s'", cache.getName());
231  listener = new FetchInitialStateCacheListener();
232  } else {
233  logger.infof("Won't fetch initial state from remote cache for cache '%s'", cache.getName());
234  listener = new DontFetchInitialStateCacheListener();
235  }*/
236 
237  RemoteCacheSessionListener<K, V> listener = new RemoteCacheSessionListener<>();
238  listener.init(session, cache, remoteCache);
239 
240  return listener;
241  }
Cache< K, SessionEntityWrapper< V > > cache
Definition: RemoteCacheSessionListener.java:52
RemoteCache< K, SessionEntityWrapper< V > > remoteCache
Definition: RemoteCacheSessionListener.java:53

◆ createRemoteEntityInCache()

void org.keycloak.models.sessions.infinispan.remotestore.RemoteCacheSessionListener< K, V extends SessionEntity >.createRemoteEntityInCache ( key,
long  eventVersion 
)
inlineprotectedinherited
105  {
106  VersionedValue<SessionEntityWrapper<V>> remoteSessionVersioned = remoteCache.getWithMetadata(key);
107 
108  // Maybe can happen under some circumstances that remoteCache doesn't yet contain the value sent in the event (maybe just theoretically...)
109  if (remoteSessionVersioned == null || remoteSessionVersioned.getValue() == null) {
110  logger.debugf("Entity '%s' not present in remoteCache. Ignoring create",
111  key.toString());
112  return;
113  }
114 
115 
116  V remoteSession = remoteSessionVersioned.getValue().getEntity();
117  SessionEntityWrapper<V> newWrapper = new SessionEntityWrapper<>(remoteSession);
118 
119  logger.debugf("Read session entity wrapper from the remote cache: %s", remoteSession.toString());
120 
121  // Using putIfAbsent. Theoretic possibility that entity was already put to cache by someone else
122  cache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_STORE, Flag.SKIP_CACHE_LOAD, Flag.IGNORE_RETURN_VALUES)
123  .putIfAbsent(key, newWrapper);
124  }
Cache< K, SessionEntityWrapper< V > > cache
Definition: RemoteCacheSessionListener.java:52
static final Logger logger
Definition: RemoteCacheSessionListener.java:48
RemoteCache< K, SessionEntityWrapper< V > > remoteCache
Definition: RemoteCacheSessionListener.java:53

◆ init()

void org.keycloak.models.sessions.infinispan.remotestore.RemoteCacheSessionListener< K, V extends SessionEntity >.init ( KeycloakSession  session,
Cache< K, SessionEntityWrapper< V >>  cache,
RemoteCache< K, SessionEntityWrapper< V >>  remoteCache 
)
inlineprotectedinherited
62  {
63  this.cache = cache;
64  this.remoteCache = remoteCache;
65 
66  this.topologyInfo = InfinispanUtil.getTopologyInfo(session);
67 
68  ExecutorService executor = session.getProvider(ExecutorsProvider.class).getExecutor("client-listener-" + cache.getName());
69  this.executor = new ClientListenerExecutorDecorator<>(executor);
70  }
Cache< K, SessionEntityWrapper< V > > cache
Definition: RemoteCacheSessionListener.java:52
TopologyInfo topologyInfo
Definition: RemoteCacheSessionListener.java:54
RemoteCache< K, SessionEntityWrapper< V > > remoteCache
Definition: RemoteCacheSessionListener.java:53
ClientListenerExecutorDecorator< K > executor
Definition: RemoteCacheSessionListener.java:55

◆ removed()

void org.keycloak.models.sessions.infinispan.remotestore.RemoteCacheSessionListener< K, V extends SessionEntity >.removed ( ClientCacheEntryRemovedEvent  event)
inlineinherited
175  {
176  K key = (K) event.getKey();
177 
178  if (shouldUpdateLocalCache(event.getType(), key, event.isCommandRetried())) {
179 
180  this.executor.submit(event, () -> {
181 
182  // We received event from remoteCache, so we won't update it back
183  cache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_STORE, Flag.SKIP_CACHE_LOAD, Flag.IGNORE_RETURN_VALUES)
184  .remove(key);
185 
186  });
187  }
188  }
Cache< K, SessionEntityWrapper< V > > cache
Definition: RemoteCacheSessionListener.java:52
boolean shouldUpdateLocalCache(ClientEvent.Type type, K key, boolean commandRetried)
Definition: RemoteCacheSessionListener.java:192
ClientListenerExecutorDecorator< K > executor
Definition: RemoteCacheSessionListener.java:55

◆ replaceRemoteEntityInCache()

void org.keycloak.models.sessions.infinispan.remotestore.RemoteCacheSessionListener< K, V extends SessionEntity >.replaceRemoteEntityInCache ( key,
long  eventVersion 
)
inlineprotectedinherited
127  {
128  // TODO can be optimized and remoteSession sent in the event itself?
129  boolean replaced = false;
130  int replaceRetries = 0;
131  int sleepInterval = 25;
132  do {
133  replaceRetries++;
134 
135  SessionEntityWrapper<V> localEntityWrapper = cache.get(key);
136  VersionedValue<SessionEntityWrapper<V>> remoteSessionVersioned = remoteCache.getWithMetadata(key);
137 
138  // Probably already removed
139  if (remoteSessionVersioned == null || remoteSessionVersioned.getValue() == null) {
140  logger.debugf("Entity '%s' not present in remoteCache. Ignoring replace",
141  key.toString());
142  return;
143  }
144 
145  if (remoteSessionVersioned.getVersion() < eventVersion) {
146  try {
147  logger.debugf("Got replace remote entity event prematurely for entity '%s', will try again. Event version: %d, got: %d",
148  key.toString(), eventVersion, remoteSessionVersioned == null ? -1 : remoteSessionVersioned.getVersion());
149  Thread.sleep(new Random().nextInt(sleepInterval)); // using exponential backoff
150  continue;
151  } catch (InterruptedException ex) {
152  continue;
153  } finally {
154  sleepInterval = sleepInterval << 1;
155  }
156  }
157  SessionEntity remoteSession = remoteSessionVersioned.getValue().getEntity();
158 
159  logger.debugf("Read session entity from the remote cache: %s . replaceRetries=%d", remoteSession.toString(), replaceRetries);
160 
161  SessionEntityWrapper<V> sessionWrapper = remoteSession.mergeRemoteEntityWithLocalEntity(localEntityWrapper);
162 
163  // We received event from remoteCache, so we won't update it back
164  replaced = cache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_STORE, Flag.SKIP_CACHE_LOAD, Flag.IGNORE_RETURN_VALUES)
165  .replace(key, localEntityWrapper, sessionWrapper);
166 
167  if (! replaced) {
168  logger.debugf("Did not succeed in merging sessions, will try again: %s", remoteSession.toString());
169  }
170  } while (replaceRetries < MAXIMUM_REPLACE_RETRIES && ! replaced);
171  }
static final int MAXIMUM_REPLACE_RETRIES
Definition: RemoteCacheSessionListener.java:50
Cache< K, SessionEntityWrapper< V > > cache
Definition: RemoteCacheSessionListener.java:52
static final Logger logger
Definition: RemoteCacheSessionListener.java:48
RemoteCache< K, SessionEntityWrapper< V > > remoteCache
Definition: RemoteCacheSessionListener.java:53

◆ shouldUpdateLocalCache()

boolean org.keycloak.models.sessions.infinispan.remotestore.RemoteCacheSessionListener< K, V extends SessionEntity >.shouldUpdateLocalCache ( ClientEvent.Type  type,
key,
boolean  commandRetried 
)
inlineprotectedinherited
192  {
193  boolean result;
194 
195  // Case when cache is stopping or stopped already
196  if (!cache.getStatus().allowInvocations()) {
197  return false;
198  }
199 
200  if (commandRetried) {
201  result = true;
202  } else {
203  result = topologyInfo.amIOwner(cache, key);
204  }
205 
206  logger.debugf("Received event from remote store. Event '%s', key '%s', skip '%b'", type.toString(), key, !result);
207 
208  return result;
209  }
boolean amIOwner(Cache cache, Object key)
Definition: TopologyInfo.java:131
Cache< K, SessionEntityWrapper< V > > cache
Definition: RemoteCacheSessionListener.java:52
static final Logger logger
Definition: RemoteCacheSessionListener.java:48
TopologyInfo topologyInfo
Definition: RemoteCacheSessionListener.java:54

◆ updated()

void org.keycloak.models.sessions.infinispan.remotestore.RemoteCacheSessionListener< K, V extends SessionEntity >.updated ( ClientCacheEntryModifiedEvent  event)
inlineinherited
91  {
92  K key = (K) event.getKey();
93 
94  if (shouldUpdateLocalCache(event.getType(), key, event.isCommandRetried())) {
95 
96  this.executor.submit(event, () -> {
97 
98  replaceRemoteEntityInCache(key, event.getVersion());
99 
100  });
101  }
102  }
void replaceRemoteEntityInCache(K key, long eventVersion)
Definition: RemoteCacheSessionListener.java:127
boolean shouldUpdateLocalCache(ClientEvent.Type type, K key, boolean commandRetried)
Definition: RemoteCacheSessionListener.java:192
ClientListenerExecutorDecorator< K > executor
Definition: RemoteCacheSessionListener.java:55

メンバ詳解

◆ logger

final Logger org.keycloak.models.sessions.infinispan.remotestore.RemoteCacheSessionListener< K, V extends SessionEntity >.logger = Logger.getLogger(RemoteCacheSessionListener.class)
staticprotectedinherited

このクラス詳解は次のファイルから抽出されました: