Search in sources :

Example 21 with ClusterProvider

use of org.keycloak.cluster.ClusterProvider in project keycloak by keycloak.

the class CrossDCLastSessionRefreshStore method sendMessage.

protected void sendMessage(KeycloakSession kcSession, Map<String, SessionData> refreshesToSend) {
    LastSessionRefreshEvent event = new LastSessionRefreshEvent(refreshesToSend);
    if (logger.isDebugEnabled()) {
        logger.debugf("Sending lastSessionRefreshes for key '%s'. Refreshes: %s", eventKey, event.getLastSessionRefreshes().toString());
    }
    // Don't notify local DC about the lastSessionRefreshes. They were processed here already
    ClusterProvider cluster = kcSession.getProvider(ClusterProvider.class);
    cluster.notify(eventKey, event, true, ClusterProvider.DCNotify.ALL_BUT_LOCAL_DC);
}
Also used : ClusterProvider(org.keycloak.cluster.ClusterProvider)

Example 22 with ClusterProvider

use of org.keycloak.cluster.ClusterProvider in project keycloak by keycloak.

the class ClusterAwareScheduledTaskRunner method runTask.

@Override
protected void runTask(final KeycloakSession session) {
    session.getTransactionManager().begin();
    ClusterProvider clusterProvider = session.getProvider(ClusterProvider.class);
    String taskKey = task.getClass().getSimpleName();
    ExecutionResult<Void> result = clusterProvider.executeIfNotExecuted(taskKey, intervalSecs, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            task.run(session);
            return null;
        }
    });
    session.getTransactionManager().commit();
    if (result.isExecuted()) {
        logger.debugf("Executed scheduled task %s", taskKey);
    } else {
        logger.debugf("Skipped execution of task %s as other cluster node is executing it", taskKey);
    }
}
Also used : ClusterProvider(org.keycloak.cluster.ClusterProvider)

Aggregations

ClusterProvider (org.keycloak.cluster.ClusterProvider)22 ClusterEvent (org.keycloak.cluster.ClusterEvent)5 KeycloakSession (org.keycloak.models.KeycloakSession)5 InfinispanConnectionProvider (org.keycloak.connections.infinispan.InfinispanConnectionProvider)4 KeycloakSessionFactory (org.keycloak.models.KeycloakSessionFactory)4 Revisioned (org.keycloak.models.cache.infinispan.entities.Revisioned)3 InvalidationEvent (org.keycloak.models.cache.infinispan.events.InvalidationEvent)3 RealmRemovedSessionEvent (org.keycloak.models.sessions.infinispan.events.RealmRemovedSessionEvent)3 UserStorageProvider (org.keycloak.storage.UserStorageProvider)3 UserStorageProviderFactory (org.keycloak.storage.UserStorageProviderFactory)3 ImportSynchronization (org.keycloak.storage.user.ImportSynchronization)3 KeycloakSessionTask (org.keycloak.models.KeycloakSessionTask)2 ClearCacheEvent (org.keycloak.models.cache.infinispan.ClearCacheEvent)2 ClientRemovedSessionEvent (org.keycloak.models.sessions.infinispan.events.ClientRemovedSessionEvent)2 SynchronizationResult (org.keycloak.storage.user.SynchronizationResult)2 Future (java.util.concurrent.Future)1 UserLoginFailureProvider (org.keycloak.models.UserLoginFailureProvider)1 UserSessionProvider (org.keycloak.models.UserSessionProvider)1 RealmRemovedEvent (org.keycloak.models.cache.infinispan.events.RealmRemovedEvent)1 RealmUpdatedEvent (org.keycloak.models.cache.infinispan.events.RealmUpdatedEvent)1