Search in sources :

Example 1 with ClearCacheEvent

use of org.keycloak.models.cache.infinispan.ClearCacheEvent in project keycloak by keycloak.

the class InfinispanPublicKeyStorageProvider method clearCache.

@Override
public void clearCache() {
    keys.clear();
    ClusterProvider cluster = session.getProvider(ClusterProvider.class);
    cluster.notify(InfinispanPublicKeyStorageProviderFactory.KEYS_CLEAR_CACHE_EVENTS, new ClearCacheEvent(), true, ClusterProvider.DCNotify.ALL_DCS);
}
Also used : ClearCacheEvent(org.keycloak.models.cache.infinispan.ClearCacheEvent) ClusterProvider(org.keycloak.cluster.ClusterProvider)

Example 2 with ClearCacheEvent

use of org.keycloak.models.cache.infinispan.ClearCacheEvent in project keycloak by keycloak.

the class DefaultInfinispanConnectionProviderFactory method registerSystemWideListeners.

private void registerSystemWideListeners(KeycloakSession session) {
    KeycloakSessionFactory sessionFactory = session.getKeycloakSessionFactory();
    ClusterProvider cluster = session.getProvider(ClusterProvider.class);
    cluster.registerListener(REALM_CLEAR_CACHE_EVENTS, (ClusterEvent event) -> {
        if (event instanceof ClearCacheEvent) {
            sessionFactory.invalidate(ObjectType._ALL_);
        }
    });
    cluster.registerListener(REALM_INVALIDATION_EVENTS, (ClusterEvent event) -> {
        if (event instanceof RealmUpdatedEvent) {
            RealmUpdatedEvent rr = (RealmUpdatedEvent) event;
            sessionFactory.invalidate(ObjectType.REALM, rr.getId());
        } else if (event instanceof RealmRemovedEvent) {
            RealmRemovedEvent rr = (RealmRemovedEvent) event;
            sessionFactory.invalidate(ObjectType.REALM, rr.getId());
        }
    });
}
Also used : ClusterEvent(org.keycloak.cluster.ClusterEvent) ClearCacheEvent(org.keycloak.models.cache.infinispan.ClearCacheEvent) ClusterProvider(org.keycloak.cluster.ClusterProvider) RealmRemovedEvent(org.keycloak.models.cache.infinispan.events.RealmRemovedEvent) KeycloakSessionFactory(org.keycloak.models.KeycloakSessionFactory) RealmUpdatedEvent(org.keycloak.models.cache.infinispan.events.RealmUpdatedEvent)

Aggregations

ClusterProvider (org.keycloak.cluster.ClusterProvider)2 ClearCacheEvent (org.keycloak.models.cache.infinispan.ClearCacheEvent)2 ClusterEvent (org.keycloak.cluster.ClusterEvent)1 KeycloakSessionFactory (org.keycloak.models.KeycloakSessionFactory)1 RealmRemovedEvent (org.keycloak.models.cache.infinispan.events.RealmRemovedEvent)1 RealmUpdatedEvent (org.keycloak.models.cache.infinispan.events.RealmUpdatedEvent)1