summaryrefslogtreecommitdiffstats
path: root/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionCache.java
blob: 60fa037e99a9586f26e3c9bab5e8afe134201824 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.session;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * A session cache that can store any type of {@link Session}.
 *
 * @author Ulf Lilleengen
 * @author hmusum
 */
public class SessionCache<SESSIONTYPE extends Session> {

    private final HashMap<Long, SESSIONTYPE> sessions = new HashMap<>();

    public synchronized void putSession(SESSIONTYPE session) {
        sessions.put(session.getSessionId(), session);
    }

    synchronized void removeSession(long id) {
        sessions.remove(id);
    }

    public synchronized SESSIONTYPE getSession(long id) {
        return sessions.get(id);
    }

    public synchronized List<SESSIONTYPE> getSessions() {
        return new ArrayList<>(sessions.values());
    }
    
}