@Override public boolean isFinished(BaseCacheInitializer initializer) { Cache<String, Serializable> workCache = initializer.getWorkCache(); Boolean sessionsLoaded = (Boolean) workCache.get(PERSISTENT_SESSIONS_LOADED); if (sessionsLoaded != null && sessionsLoaded) { log.debugf("Persistent sessions loaded already."); return true; } else { log.debugf("Persistent sessions not yet loaded."); return false; } }
@Override public boolean isFinished(BaseCacheInitializer initializer) { Cache<String, Serializable> workCache = initializer.getWorkCache(); // Check if persistent sessions were already loaded in this DC. This is possible just for offline sessions ATM Boolean sessionsLoaded = (Boolean) workCache .getAdvancedCache().withFlags(Flag.SKIP_CACHE_LOAD, Flag.SKIP_CACHE_STORE) .get(OfflinePersistentUserSessionLoader.PERSISTENT_SESSIONS_LOADED_IN_CURRENT_DC); if ((cacheName.equals(InfinispanConnectionProvider.OFFLINE_USER_SESSION_CACHE_NAME) || (cacheName.equals(InfinispanConnectionProvider.OFFLINE_CLIENT_SESSION_CACHE_NAME))) && sessionsLoaded != null && sessionsLoaded) { log.debugf("Sessions already loaded in current DC. Skip sessions loading from remote cache '%s'", cacheName); return true; } else { log.debugf("Sessions maybe not yet loaded in current DC. Will load them from remote cache '%s'", cacheName); return false; } }
@Override public void afterAllSessionsLoaded(BaseCacheInitializer initializer) { Cache<String, Serializable> workCache = initializer.getWorkCache(); // Will retry few times for the case when backup site not available in cross-dc environment. // The site might be taken offline automatically if "take-offline" properly configured Retry.executeWithBackoff((int iteration) -> { try { // Cross-DC aware flag workCache .getAdvancedCache().withFlags(Flag.SKIP_REMOTE_LOOKUP) .put(PERSISTENT_SESSIONS_LOADED, true); } catch (HotRodClientException re) { log.warnf(re, "Failed to write flag PERSISTENT_SESSIONS_LOADED in iteration '%d' . Retrying", iteration); // Rethrow the exception. Retry will take care of handle the exception and eventually retry the operation. throw re; } }, 10, 10); // Just local-DC aware flag workCache .getAdvancedCache().withFlags(Flag.SKIP_REMOTE_LOOKUP, Flag.SKIP_CACHE_LOAD, Flag.SKIP_CACHE_STORE) .put(PERSISTENT_SESSIONS_LOADED_IN_CURRENT_DC, true); log.debugf("Persistent sessions loaded successfully!"); }