Search in sources :

Example 1 with RemoteStore

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

the class InfinispanUserLoginFailureProviderFactory 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 2 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 3 with RemoteStore

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

the class CrossDCAwareCacheFactory method getFactory.

static CrossDCAwareCacheFactory getFactory(Cache<String, Serializable> workCache, Set<RemoteStore> remoteStores) {
    if (remoteStores.isEmpty()) {
        logger.debugf("No configured remoteStore available. Cross-DC scenario is not used");
        return new InfinispanCacheWrapperFactory(workCache);
    } else {
        logger.debugf("RemoteStore is available. Cross-DC scenario will be used");
        if (remoteStores.size() > 1) {
            logger.warnf("More remoteStores configured for work cache. Will use just the first one");
        }
        // For cross-DC scenario, we need to return underlying remoteCache for atomic operations to work properly
        RemoteStore remoteStore = remoteStores.iterator().next();
        RemoteCache remoteCache = remoteStore.getRemoteCache();
        if (remoteCache == null) {
            String cacheName = remoteStore.getConfiguration().remoteCacheName();
            throw new IllegalStateException("Remote cache '" + cacheName + "' is not available.");
        }
        return new RemoteCacheWrapperFactory(remoteCache);
    }
}
Also used : RemoteCache(org.infinispan.client.hotrod.RemoteCache) RemoteStore(org.infinispan.persistence.remote.RemoteStore)

Example 4 with RemoteStore

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

the class InfinispanClusterProviderFactory method lazyInit.

private void lazyInit(KeycloakSession session) {
    if (workCache == null) {
        synchronized (this) {
            if (workCache == null) {
                InfinispanConnectionProvider ispnConnections = session.getProvider(InfinispanConnectionProvider.class);
                workCache = ispnConnections.getCache(InfinispanConnectionProvider.WORK_CACHE_NAME);
                workCacheListener = new ViewChangeListener();
                workCache.getCacheManager().addListener(workCacheListener);
                // See if we have RemoteStore (external JDG) configured for cross-Data-Center scenario
                Set<RemoteStore> remoteStores = InfinispanUtil.getRemoteStores(workCache);
                crossDCAwareCacheFactory = CrossDCAwareCacheFactory.getFactory(workCache, remoteStores);
                clusterStartupTime = initClusterStartupTime(session);
                TopologyInfo topologyInfo = InfinispanUtil.getTopologyInfo(session);
                String myAddress = topologyInfo.getMyNodeName();
                String mySite = topologyInfo.getMySiteName();
                notificationsManager = InfinispanNotificationsManager.create(session, workCache, myAddress, mySite, remoteStores);
            }
        }
    }
}
Also used : InfinispanConnectionProvider(org.keycloak.connections.infinispan.InfinispanConnectionProvider) TopologyInfo(org.keycloak.connections.infinispan.TopologyInfo) RemoteStore(org.infinispan.persistence.remote.RemoteStore)

Example 5 with RemoteStore

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

the class ConcurrencyJDGRemoteCacheClientListenersTest method createWorker.

private static Worker createWorker(int threadId) {
    EmbeddedCacheManager manager = new TestCacheManagerFactory().createManager(threadId, InfinispanConnectionProvider.WORK_CACHE_NAME, RemoteStoreConfigurationBuilder.class);
    Cache<String, Integer> cache = manager.getCache(InfinispanConnectionProvider.WORK_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(cache, threadId);
    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)

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