Search in sources :

Example 6 with RemoteStore

use of org.infinispan.persistence.remote.RemoteStore in project keycloak by keycloak.

the class InfinispanSessionCacheIdMapperUpdater method addSsoCacheCrossDcListener.

private static void addSsoCacheCrossDcListener(Cache<String, String[]> ssoCache, SsoSessionCacheListener listener) {
    if (ssoCache.getCacheConfiguration().persistence() == null) {
        return;
    }
    final Set<RemoteStore> stores = getRemoteStores(ssoCache);
    if (stores == null || stores.isEmpty()) {
        return;
    }
    LOG.infov("Listening for events on remote stores configured for cache {0}", ssoCache.getName());
    for (RemoteStore store : stores) {
        store.getRemoteCache().addClientListener(listener);
    }
}
Also used : RemoteStore(org.infinispan.persistence.remote.RemoteStore)

Example 7 with RemoteStore

use of org.infinispan.persistence.remote.RemoteStore in project keycloak by keycloak.

the class InfinispanUserSessionProviderFactory method checkRemoteCache.

private <K, V extends SessionEntity> RemoteCache checkRemoteCache(KeycloakSession session, Cache<K, SessionEntityWrapper<V>> ispnCache, RemoteCacheInvoker.MaxIdleTimeLoader maxIdleLoader, BiFunction<RealmModel, V, Long> lifespanMsLoader, BiFunction<RealmModel, V, Long> maxIdleTimeMsLoader) {
    Set<RemoteStore> remoteStores = InfinispanUtil.getRemoteStores(ispnCache);
    if (remoteStores.isEmpty()) {
        log.debugf("No remote store configured for cache '%s'", ispnCache.getName());
        return null;
    } else {
        log.infof("Remote store configured for cache '%s'", ispnCache.getName());
        RemoteCache<K, SessionEntityWrapper<V>> remoteCache = (RemoteCache) remoteStores.iterator().next().getRemoteCache();
        if (remoteCache == null) {
            throw new IllegalStateException("No remote cache available for the infinispan cache: " + ispnCache.getName());
        }
        remoteCacheInvoker.addRemoteCache(ispnCache.getName(), remoteCache, maxIdleLoader);
        RemoteCacheSessionListener hotrodListener = RemoteCacheSessionListener.createListener(session, ispnCache, remoteCache, lifespanMsLoader, maxIdleTimeMsLoader);
        remoteCache.addClientListener(hotrodListener);
        return remoteCache;
    }
}
Also used : RemoteCacheSessionListener(org.keycloak.models.sessions.infinispan.remotestore.RemoteCacheSessionListener) RemoteCache(org.infinispan.client.hotrod.RemoteCache) SessionEntityWrapper(org.keycloak.models.sessions.infinispan.changes.SessionEntityWrapper) RemoteStore(org.infinispan.persistence.remote.RemoteStore)

Example 8 with RemoteStore

use of org.infinispan.persistence.remote.RemoteStore in project keycloak by keycloak.

the class ConcurrencyJDGCachePutTest method createWorker.

private static Worker createWorker(int threadId) {
    EmbeddedCacheManager manager = new TestCacheManagerFactory().createManager(threadId, InfinispanConnectionProvider.USER_SESSION_CACHE_NAME, RemoteStoreConfigurationBuilder.class);
    Cache<String, Integer> cache = manager.getCache(InfinispanConnectionProvider.USER_SESSION_CACHE_NAME);
    System.out.println("Retrieved cache: " + threadId);
    RemoteStore remoteStore = cache.getAdvancedCache().getComponentRegistry().getComponent(PersistenceManager.class).getStores(RemoteStore.class).iterator().next();
    HotRodListener listener = new HotRodListener();
    remoteStore.getRemoteCache().addClientListener(listener);
    return new Worker(cache, threadId);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) RemoteStore(org.infinispan.persistence.remote.RemoteStore)

Example 9 with RemoteStore

use of org.infinispan.persistence.remote.RemoteStore in project keycloak by keycloak.

the class InfinispanNotificationsManager method create.

// Create and init manager including all listeners etc
public static InfinispanNotificationsManager create(KeycloakSession session, Cache<String, Serializable> workCache, String myAddress, String mySite, Set<RemoteStore> remoteStores) {
    RemoteCache workRemoteCache = null;
    if (!remoteStores.isEmpty()) {
        RemoteStore remoteStore = remoteStores.iterator().next();
        workRemoteCache = remoteStore.getRemoteCache();
        if (mySite == null) {
            throw new IllegalStateException("Multiple datacenters available, but site name is not configured! Check your configuration");
        }
    }
    ExecutorService listenersExecutor = workRemoteCache == null ? null : session.getProvider(ExecutorsProvider.class).getExecutor("work-cache-event-listener");
    InfinispanNotificationsManager manager = new InfinispanNotificationsManager(workCache, workRemoteCache, myAddress, mySite, listenersExecutor);
    // We need CacheEntryListener for communication within current DC
    workCache.addListener(manager.new CacheEntryListener());
    logger.debugf("Added listener for infinispan cache: %s", workCache.getName());
    // Added listener for remoteCache to notify other DCs
    if (workRemoteCache != null) {
        workRemoteCache.addClientListener(manager.new HotRodListener(workRemoteCache));
        logger.debugf("Added listener for HotRod remoteStore cache: %s", workRemoteCache.getName());
    }
    return manager;
}
Also used : RemoteCache(org.infinispan.client.hotrod.RemoteCache) ExecutorService(java.util.concurrent.ExecutorService) RemoteStore(org.infinispan.persistence.remote.RemoteStore)

Aggregations

RemoteStore (org.infinispan.persistence.remote.RemoteStore)9 RemoteCache (org.infinispan.client.hotrod.RemoteCache)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)2 PersistenceManager (org.infinispan.persistence.manager.PersistenceManager)2 SessionEntityWrapper (org.keycloak.models.sessions.infinispan.changes.SessionEntityWrapper)2 RemoteCacheSessionListener (org.keycloak.models.sessions.infinispan.remotestore.RemoteCacheSessionListener)2 ExecutorService (java.util.concurrent.ExecutorService)1 InfinispanConnectionProvider (org.keycloak.connections.infinispan.InfinispanConnectionProvider)1 TopologyInfo (org.keycloak.connections.infinispan.TopologyInfo)1