use of org.keycloak.cluster.ClusterProvider 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);
}
use of org.keycloak.cluster.ClusterProvider in project keycloak by keycloak.
the class InfinispanPublicKeyStorageProvider method runInvalidations.
protected void runInvalidations() {
ClusterProvider cluster = session.getProvider(ClusterProvider.class);
for (String cacheKey : invalidations) {
keys.remove(cacheKey);
cluster.notify(InfinispanPublicKeyStorageProviderFactory.PUBLIC_KEY_STORAGE_INVALIDATION_EVENT, PublicKeyStorageInvalidationEvent.create(cacheKey), true, ClusterProvider.DCNotify.ALL_DCS);
}
}
use of org.keycloak.cluster.ClusterProvider 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());
}
});
}
use of org.keycloak.cluster.ClusterProvider in project keycloak by keycloak.
the class InfinispanPublicKeyStorageProviderFactory method lazyInit.
private void lazyInit(KeycloakSession session) {
if (keysCache == null) {
synchronized (this) {
if (keysCache == null) {
this.keysCache = session.getProvider(InfinispanConnectionProvider.class).getCache(InfinispanConnectionProvider.KEYS_CACHE_NAME);
ClusterProvider cluster = session.getProvider(ClusterProvider.class);
cluster.registerListener(PUBLIC_KEY_STORAGE_INVALIDATION_EVENT, (ClusterEvent event) -> {
PublicKeyStorageInvalidationEvent invalidationEvent = (PublicKeyStorageInvalidationEvent) event;
keysCache.remove(invalidationEvent.getCacheKey());
});
cluster.registerListener(KEYS_CLEAR_CACHE_EVENTS, (ClusterEvent event) -> {
keysCache.clear();
});
}
}
}
}
use of org.keycloak.cluster.ClusterProvider in project keycloak by keycloak.
the class ClusterProviderTaskCommand method doRunCommand.
@Override
protected void doRunCommand(KeycloakSession session) {
String taskName = getArg(0);
int taskTimeout = getIntArg(1);
int sleepTime = getIntArg(2);
ClusterProvider cluster = session.getProvider(ClusterProvider.class);
Future future = cluster.executeIfNotExecutedAsync(taskName, taskTimeout, () -> {
log.infof("Started sleeping for " + sleepTime + " seconds");
Thread.sleep(sleepTime * 1000);
log.infof("Stopped sleeping");
return null;
});
log.info("I've retrieved future successfully");
executors.execute(() -> {
try {
future.get();
log.info("Successfully finished future!");
} catch (Exception e) {
e.printStackTrace();
}
});
}
Aggregations