Search in sources :

Example 11 with RemoteCache

use of org.infinispan.client.hotrod.RemoteCache in project keycloak by keycloak.

the class InfinispanUtil method toHotrodTimeMs.

/**
 * Convert the given value to the proper value, which can be used when calling operations for the infinispan remoteCache.
 *
 * Infinispan HotRod protocol of versions older than 3.0 uses the "lifespan" or "maxIdle" as the normal expiration time when the value is 30 days or less.
 * However for the bigger values, it assumes that the value is unix timestamp.
 *
 * @param ispnCache
 * @param lifespanOrigMs
 * @return
 */
public static long toHotrodTimeMs(BasicCache ispnCache, long lifespanOrigMs) {
    if (ispnCache instanceof RemoteCache && lifespanOrigMs > 2592000000L) {
        RemoteCache remoteCache = (RemoteCache) ispnCache;
        ProtocolVersion protocolVersion = remoteCache.getRemoteCacheManager().getConfiguration().version();
        if (ProtocolVersion.PROTOCOL_VERSION_30.compareTo(protocolVersion) > 0) {
            return Time.currentTimeMillis() + lifespanOrigMs;
        }
    }
    return lifespanOrigMs;
}
Also used : RemoteCache(org.infinispan.client.hotrod.RemoteCache) ProtocolVersion(org.infinispan.client.hotrod.ProtocolVersion)

Example 12 with RemoteCache

use of org.infinispan.client.hotrod.RemoteCache in project keycloak by keycloak.

the class DistributedCacheConcurrentWritesTest method printStats.

private static void printStats(BasicCache cache) {
    if (cache instanceof Cache) {
        Cache cache1 = (Cache) cache;
        JChannel channel = ((JGroupsTransport) cache1.getAdvancedCache().getRpcManager().getTransport()).getChannel();
        System.out.println("Sent MB: " + channel.getSentBytes() / 1000000 + ", sent messages: " + channel.getSentMessages() + ", received MB: " + channel.getReceivedBytes() / 1000000 + ", received messages: " + channel.getReceivedMessages());
    } else {
        Map<String, String> stats = ((RemoteCache) cache).stats().getStatsMap();
        System.out.println("Stats: " + stats);
    }
}
Also used : JChannel(org.jgroups.JChannel) JGroupsTransport(org.infinispan.remoting.transport.jgroups.JGroupsTransport) Cache(org.infinispan.Cache) RemoteCache(org.infinispan.client.hotrod.RemoteCache) BasicCache(org.infinispan.commons.api.BasicCache)

Example 13 with RemoteCache

use of org.infinispan.client.hotrod.RemoteCache in project indy by Commonjava.

the class MetadataCacheProducer method registerTransformer.

private void registerTransformer(BasicCacheHandle handler) {
    // for embedded mode
    if (handler instanceof CacheHandle) {
        ((CacheHandle<MetadataKey, MetadataKey>) handler).executeCache(cache -> {
            SearchManagerImplementor searchManager = (SearchManagerImplementor) Search.getSearchManager(cache);
            searchManager.registerKeyTransformer(MetadataKey.class, MetadataKeyTransformer.class);
            return null;
        });
    }
    if (handler.getCache() instanceof RemoteCache) {
        ((RemoteCache) handler.getCache()).addClientListener(cacheListener);
    } else {
        ((Cache) handler.getCache()).addListener(cacheListener);
    }
}
Also used : SearchManagerImplementor(org.infinispan.query.spi.SearchManagerImplementor) BasicCacheHandle(org.commonjava.indy.subsys.infinispan.BasicCacheHandle) CacheHandle(org.commonjava.indy.subsys.infinispan.CacheHandle) RemoteCache(org.infinispan.client.hotrod.RemoteCache) Cache(org.infinispan.Cache) RemoteCache(org.infinispan.client.hotrod.RemoteCache)

Example 14 with RemoteCache

use of org.infinispan.client.hotrod.RemoteCache in project wildfly by wildfly.

the class RemoteCacheServiceConfigurator method build.

@Override
public final ServiceBuilder<?> build(ServiceTarget target) {
    ServiceBuilder<?> builder = new AsyncServiceConfigurator(this.getServiceName()).build(target);
    Consumer<RemoteCache<K, V>> cache = this.container.register(builder).provides(this.getServiceName());
    Service service = new FunctionalService<>(cache, Function.identity(), this, this);
    return builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
Also used : FunctionalService(org.wildfly.clustering.service.FunctionalService) RemoteCache(org.infinispan.client.hotrod.RemoteCache) AsyncServiceConfigurator(org.wildfly.clustering.service.AsyncServiceConfigurator) FunctionalService(org.wildfly.clustering.service.FunctionalService) Service(org.jboss.msc.Service)

Example 15 with RemoteCache

use of org.infinispan.client.hotrod.RemoteCache in project wildfly by wildfly.

the class CoarseSessionsFactory method findEntryContaining.

@Override
public Map.Entry<String, Map<D, S>> findEntryContaining(S session) {
    SessionFilter<CoarseSessionsKey, D, S> filter = new SessionFilter<>(session);
    // Erase type to handle compilation issues with generics
    // Our filter will handle type safety and casting
    @SuppressWarnings("rawtypes") RemoteCache cache = this.cache;
    try (Stream<Map.Entry<?, ?>> stream = cache.entrySet().stream()) {
        Map.Entry<CoarseSessionsKey, Map<D, S>> entry = stream.filter(this.filter).map(this.filter).filter(filter).findAny().orElse(null);
        return (entry != null) ? new AbstractMap.SimpleImmutableEntry<>(entry.getKey().getId(), entry.getValue()) : null;
    }
}
Also used : AbstractMap(java.util.AbstractMap) SessionFilter(org.wildfly.clustering.web.cache.sso.coarse.SessionFilter) RemoteCache(org.infinispan.client.hotrod.RemoteCache) AbstractMap(java.util.AbstractMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

RemoteCache (org.infinispan.client.hotrod.RemoteCache)26 SessionEntityWrapper (org.keycloak.models.sessions.infinispan.changes.SessionEntityWrapper)9 Cache (org.infinispan.Cache)8 Map (java.util.Map)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 HotRodClientException (org.infinispan.client.hotrod.exceptions.HotRodClientException)5 RemoteStore (org.infinispan.persistence.remote.RemoteStore)5 UUID (java.util.UUID)4 BasicCache (org.infinispan.commons.api.BasicCache)4 Logger (org.jboss.logging.Logger)4 KeycloakSession (org.keycloak.models.KeycloakSession)4 RealmModel (org.keycloak.models.RealmModel)4 UserSessionEntity (org.keycloak.models.sessions.infinispan.entities.UserSessionEntity)4 HashMap (java.util.HashMap)3 Objects (java.util.Objects)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 TimeUnit (java.util.concurrent.TimeUnit)3 BiFunction (java.util.function.BiFunction)3 Function (java.util.function.Function)3 Collectors (java.util.stream.Collectors)3