Java Code Examples for org.infinispan.client.hotrod.RemoteCache#get()

The following examples show how to use org.infinispan.client.hotrod.RemoteCache#get() . 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: RemoteCaches.java    From khan-session with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void test() {

        RemoteCacheManager cacheManager = new RemoteCacheManager("192.168.0.58:11322;192.168.0.58:11422", true);
        RemoteCache<Object, Object> cache = cacheManager.getCache("KHAN_SESSION");

        Set<Object> keySet = cache.keySet();

        Iterator<Object> i = keySet.iterator();
        System.out.println("============= KHAN_SESSION");
        while (i.hasNext()) {
            Object key = i.next();
            System.out.println("> key=" + key);
            Object value = cache.get(key);
            System.out.println("> value=" + value);
            System.out.println("");
        }
        System.out.println("=============");
    }
 
Example 2
Source File: RemoteCaches.java    From khan-session with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void test2() {
    RemoteCacheManager cacheManager = new RemoteCacheManager("192.168.0.58:11322;192.168.0.58:11422", true);
    RemoteCache<Object, Object> cache = cacheManager.getCache("KHAN_SESSION_LOGIN");

    Set<Object> keySet = cache.keySet();

    Iterator<Object> i = keySet.iterator();
    System.out.println("============= KHAN_SESSION_LOGIN");
    while (i.hasNext()) {
        Object key = i.next();
        System.out.println("> key=" + key);
        Object value = cache.get(key);
        System.out.println("> value=" + value);
        System.out.println("");
    }
    System.out.println("=============");
}
 
Example 3
Source File: RemoteCaches.java    From khan-session with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testRemoteCache() {
    RemoteCacheManager cacheManager = new RemoteCacheManager("192.168.0.58:11422;192.168.0.58:11322", true);
    RemoteCache<Object, Object> cache = cacheManager.getCache("KHAN_SESSION_REMOTE");

    Set<Object> keySet = cache.keySet();

    Iterator<Object> i = keySet.iterator();
    System.out.println("============= KHAN_SESSION_REMOTE");
    while (i.hasNext()) {
        Object key = i.next();
        System.out.println("> key=" + key);
        Object value = cache.get(key);
        System.out.println("> value=" + value);
        System.out.println("");
    }
    System.out.println("=============");
}
 
Example 4
Source File: RemoteCaches.java    From khan-session with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testRemoteLoginCache() {
    RemoteCacheManager cacheManager = new RemoteCacheManager("192.168.0.58:11422;192.168.0.58:11322", true);
    RemoteCache<Object, Object> cache = cacheManager.getCache("KHAN_SESSION_LOGIN_REMOTE");

    Set<Object> keySet = cache.keySet();

    Iterator<Object> i = keySet.iterator();
    System.out.println("============= KHAN_SESSION_LOGIN_REMOTE");
    while (i.hasNext()) {
        Object key = i.next();
        System.out.println("> key=" + key);
        Object value = cache.get(key);
        System.out.println("> value=" + value);
        System.out.println("");
    }
    System.out.println("=============");
}
 
Example 5
Source File: TestCacheResource.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@GET
@Path("/remote-cache-last-session-refresh/{user-session-id}")
@Produces(MediaType.APPLICATION_JSON)
public int getRemoteCacheLastSessionRefresh(@PathParam("user-session-id") String userSessionId) {
    RemoteCache remoteCache = InfinispanUtil.getRemoteCache(cache);
    if (remoteCache == null) {
        return -1;
    } else {
        SessionEntityWrapper<UserSessionEntity> userSession = (SessionEntityWrapper<UserSessionEntity>) remoteCache.get(userSessionId);
        if (userSession == null) {
            return -1;
        } else {
            return userSession.getEntity().getLastSessionRefresh();
        }
    }
}
 
Example 6
Source File: InfinispanUserSessionProvider.java    From keycloak with Apache License 2.0 4 votes vote down vote up
@Override
public UserSessionModel getUserSessionWithPredicate(RealmModel realm, String id, boolean offline, Predicate<UserSessionModel> predicate) {
    UserSessionModel userSession = getUserSession(realm, id, offline);
    if (userSession == null) {
        return null;
    }

    // We have userSession, which passes predicate. No need for remote lookup.
    if (predicate.test(userSession)) {
        log.debugf("getUserSessionWithPredicate(%s): found in local cache", id);
        return userSession;
    }

    // Try lookup userSession from remoteCache
    Cache<String, SessionEntityWrapper<UserSessionEntity>> cache = getCache(offline);
    RemoteCache remoteCache = InfinispanUtil.getRemoteCache(cache);

    if (remoteCache != null) {
        SessionEntityWrapper<UserSessionEntity> remoteSessionEntityWrapper = (SessionEntityWrapper<UserSessionEntity>) remoteCache.get(id);
        if (remoteSessionEntityWrapper != null) {
            UserSessionEntity remoteSessionEntity = remoteSessionEntityWrapper.getEntity();
            log.debugf("getUserSessionWithPredicate(%s): remote cache contains session entity %s", id, remoteSessionEntity);

            UserSessionModel remoteSessionAdapter = wrap(realm, remoteSessionEntity, offline);
            if (predicate.test(remoteSessionAdapter)) {

                InfinispanChangelogBasedTransaction<String, UserSessionEntity> tx = getTransaction(offline);

                // Remote entity contains our predicate. Update local cache with the remote entity
                SessionEntityWrapper<UserSessionEntity> sessionWrapper = remoteSessionEntity.mergeRemoteEntityWithLocalEntity(tx.get(id));

                // Replace entity just in ispn cache. Skip remoteStore
                cache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_STORE, Flag.SKIP_CACHE_LOAD, Flag.IGNORE_RETURN_VALUES)
                        .replace(id, sessionWrapper);

                tx.reloadEntityInCurrentTransaction(realm, id, sessionWrapper);

                // Recursion. We should have it locally now
                return getUserSessionWithPredicate(realm, id, offline, predicate);
            } else {
                log.debugf("getUserSessionWithPredicate(%s): found, but predicate doesn't pass", id);

                return null;
            }
        } else {
            log.debugf("getUserSessionWithPredicate(%s): not found", id);

            // Session not available on remoteCache. Was already removed there. So removing locally too.
            // TODO: Can be optimized to skip calling remoteCache.remove
            removeUserSession(realm, userSession);

            return null;
        }
    } else {

        log.debugf("getUserSessionWithPredicate(%s): remote cache not available", id);

        return null;
    }
}