use of org.infinispan.client.hotrod.RemoteCache in project keycloak by keycloak.
the class RemoteCacheProvider method getRemoteCache.
public RemoteCache getRemoteCache(String cacheName) {
if (availableCaches.get(cacheName) == null) {
synchronized (this) {
if (availableCaches.get(cacheName) == null) {
RemoteCache remoteCache = loadRemoteCache(cacheName);
availableCaches.put(cacheName, remoteCache);
}
}
}
return availableCaches.get(cacheName);
}
use of org.infinispan.client.hotrod.RemoteCache in project keycloak by keycloak.
the class InfinispanUserSessionProviderFactory method checkRemoteCache.
private <K, V extends SessionEntity> RemoteCache checkRemoteCache(KeycloakSession session, Cache<K, SessionEntityWrapper<V>> ispnCache, RemoteCacheInvoker.MaxIdleTimeLoader maxIdleLoader, BiFunction<RealmModel, V, Long> lifespanMsLoader, BiFunction<RealmModel, V, Long> maxIdleTimeMsLoader) {
Set<RemoteStore> remoteStores = InfinispanUtil.getRemoteStores(ispnCache);
if (remoteStores.isEmpty()) {
log.debugf("No remote store configured for cache '%s'", ispnCache.getName());
return null;
} 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, lifespanMsLoader, maxIdleTimeMsLoader);
remoteCache.addClientListener(hotrodListener);
return remoteCache;
}
}
use of org.infinispan.client.hotrod.RemoteCache in project keycloak by keycloak.
the class HotRodMapStorage method delete.
@Override
public long delete(QueryParameters<M> queryParameters) {
IckleQueryMapModelCriteriaBuilder<E, M> iqmcb = queryParameters.getModelCriteriaBuilder().flashToModelCriteriaBuilder(createCriteriaBuilder());
String queryString = "SELECT id " + iqmcb.getIckleQuery();
if (!queryParameters.getOrderBy().isEmpty()) {
queryString += " ORDER BY " + queryParameters.getOrderBy().stream().map(HotRodMapStorage::toOrderString).collect(Collectors.joining(", "));
}
LOG.tracef("Executing delete Ickle query: %s", queryString);
QueryFactory queryFactory = Search.getQueryFactory(remoteCache);
Query<Object[]> query = paginateQuery(queryFactory.create(queryString), queryParameters.getOffset(), queryParameters.getLimit());
query.setParameters(iqmcb.getParameters());
AtomicLong result = new AtomicLong();
CloseableIterator<Object[]> iterator = query.iterator();
StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, 0), false).peek(e -> result.incrementAndGet()).map(a -> a[0]).map(String.class::cast).forEach(this::delete);
iterator.close();
return result.get();
}
use of org.infinispan.client.hotrod.RemoteCache in project keycloak by keycloak.
the class ConcurrencyJDGRemoveSessionTest method createWorker.
private static Thread createWorker(Cache<String, SessionEntityWrapper<UserSessionEntity>> cache, int threadId) {
System.out.println("Retrieved cache: " + threadId);
RemoteCache remoteCache = InfinispanUtil.getRemoteCache(cache);
if (threadId == 1) {
remoteCache1 = remoteCache;
} else {
remoteCache2 = remoteCache;
}
AtomicInteger counter = threadId == 1 ? successfulListenerWrites : successfulListenerWrites2;
HotRodListener listener = new HotRodListener(cache, remoteCache, counter);
remoteCache.addClientListener(listener);
return new RemoteCacheWorker(remoteCache, threadId);
// return new CacheWorker(cache, threadId);
}
use of org.infinispan.client.hotrod.RemoteCache in project keycloak by keycloak.
the class JDGPutTest method main.
public static void main(String[] args) throws Exception {
Cache<String, Object> cache1 = createManager(1).getCache(InfinispanConnectionProvider.USER_SESSION_CACHE_NAME);
Cache<String, Object> cache2 = createManager(2).getCache(InfinispanConnectionProvider.USER_SESSION_CACHE_NAME);
try {
// RemoteCache remoteCache1 = InfinispanUtil.getRemoteCache(cache1);
// RemoteCache remoteCache2 = InfinispanUtil.getRemoteCache(cache2);
// remoteCache1.put("key1", new Book("book1", "desc", 1));
// remoteCache2.put("key2", );
String uuidStr = UUID.randomUUID().toString();
System.out.println(uuidStr);
UUID uuid = UUID.fromString(uuidStr);
AuthenticatedClientSessionEntity ace = new AuthenticatedClientSessionEntity(uuid);
SessionEntityWrapper wrapper = new SessionEntityWrapper(ace);
cache1.put("key1", wrapper);
// cache1.put("key1", "val1");
// AuthenticatedClientSessionEntity val1 = (AuthenticatedClientSessionEntity) cache2.get("key1");
// RemoteCache remoteCache1 = InfinispanUtil.getRemoteCache(cache1);
// remoteCache1.put("key1", "val1");
RemoteCache remoteCache2 = InfinispanUtil.getRemoteCache(cache2);
Object o = remoteCache2.get("key1");
logger.info("Before retrieve entries");
try (CloseableIterator it = remoteCache2.retrieveEntries(null, 64)) {
Object o2 = it.next();
logger.info("o2: " + o2);
}
// Object key = remoteCache2.keySet().iterator().next();
// Object value = remoteCache2.values().iterator().next();
// logger.info("Key: " + key + ", val: " + value);
bulkLoadSessions(remoteCache2);
} finally {
Thread.sleep(2000);
// Finish JVM
cache1.getCacheManager().stop();
cache2.getCacheManager().stop();
}
}
Aggregations