Java Code Examples for org.infinispan.Cache#getName()

The following examples show how to use org.infinispan.Cache#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InfinispanUserSessionProviderFactory.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private <K, V extends SessionEntity> boolean checkRemoteCache(KeycloakSession session, Cache<K, SessionEntityWrapper<V>> ispnCache, RemoteCacheInvoker.MaxIdleTimeLoader maxIdleLoader) {
    Set<RemoteStore> remoteStores = InfinispanUtil.getRemoteStores(ispnCache);

    if (remoteStores.isEmpty()) {
        log.debugf("No remote store configured for cache '%s'", ispnCache.getName());
        return false;
    } 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);
        remoteCache.addClientListener(hotrodListener);
        return true;
    }
}
 
Example 2
Source File: InfinispanKeyGenerator.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private <K> K generateKey(KeycloakSession session, Cache<K, ?> cache, KeyGenerator<K> keyGenerator) {
    String cacheName = cache.getName();

    // "wantsLocalKey" is true if route is not attached to the sticky session cookie. Without attached route, We want the key, which will be "owned" by this node.
    // This is needed due the fact that external loadbalancer will attach route corresponding to our node, which will be the owner of the particular key, hence we
    // will be able to lookup key locally.
    boolean wantsLocalKey = !session.getProvider(StickySessionEncoderProvider.class).shouldAttachRoute();

    if (wantsLocalKey && cache.getCacheConfiguration().clustering().cacheMode().isClustered()) {
        KeyAffinityService<K> keyAffinityService = keyAffinityServices.get(cacheName);
        if (keyAffinityService == null) {
            keyAffinityService = createKeyAffinityService(cache, keyGenerator);
            keyAffinityServices.put(cacheName, keyAffinityService);

            log.debugf("Registered key affinity service for cache '%s'", cacheName);
        }

        return keyAffinityService.getKeyForAddress(cache.getCacheManager().getAddress());
    } else {
        return keyGenerator.getKey();
    }

}
 
Example 3
Source File: InfinispanCacheMeterBinder.java    From infinispan-spring-boot with Apache License 2.0 4 votes vote down vote up
public InfinispanCacheMeterBinder(Cache cache, Iterable<Tag> tags) {
   super(cache, cache.getName(), tags);
   this.cache = cache;
}
 
Example 4
Source File: InfinispanChangelogBasedTransaction.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public InfinispanChangelogBasedTransaction(KeycloakSession kcSession, Cache<K, SessionEntityWrapper<V>> cache, RemoteCacheInvoker remoteCacheInvoker) {
    this.kcSession = kcSession;
    this.cacheName = cache.getName();
    this.cache = cache;
    this.remoteCacheInvoker = remoteCacheInvoker;
}