简体   繁体   中英

Hazelcast killing a user session

I'm looking into killing an user active session for my hazelcast cluster.

We have the session map and that appears to have two entries per session

[SESSIONID] mapped to a boolean value and [SESSIONID]::hz::user mapped to our user object

The way I see it to kill a session I have to loop through the map and find the user object, and once that's found remove that entry parse the key and look for the other sessionId mapped to boolean and kill that as well.

Is there an easier way that I'm missing?

It is well described in Hazelcast Mastering book : http://hazelcast.org/mastering-hazelcast/ You need to register to read that book. You can use Predicate with :

  1. Criteria API
  2. Distributed SQL Query
  3. RegexPredicate to search the sessionid in map

Imagine that we have a Hazelcast IMap where the key is some ID, the value is a Person object, and we want to retrieve all persons with a given name using the following (and naive) implementation:

public Set<Person> getWithNameNaive(String name){
    Set<Person> result = new HashSet<Person>();
    for(Person person: personMap.values()){
        if(person.name.equals(name)){
            result.add(person);
        }
    }
    return result;

Hazelcast way to solve that problem :

 public Set<Person> getWithName(String name) {
    Predicate namePredicate = equal("name", name);
    return (Set<Person>) personMap.values(namePredicate);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM