LocalSessionStore.java [src/csip] Revision: 71821307bfe742c00c6dc582c171224a9ac59935  Date: Fri Apr 21 11:46:19 MDT 2017
/*
 * $Id$
 *
 * This file is part of the Cloud Services Integration Platform (CSIP),
 * a Model-as-a-Service framework, API and application suite.
 *
 * 2012-2017, Olaf David and others, OMSLab, Colorado State University.
 *
 * OMSLab licenses this file to you under the MIT license.
 * See the LICENSE file in the project root for more information.
 */
package csip;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * This is a local session store. One instance only, no failover.
 */
class LocalSessionStore implements SessionStore {

    Map<String, ModelSession> m = Collections.synchronizedMap(new HashMap<String, ModelSession>());


    public LocalSessionStore() {
        Config.LOG.info("Using local session store.");
    }


    @Override
    public void shutdown() throws Exception {
        m.clear();
    }


    @Override
    public void setSession(String key, ModelSession session) throws Exception {
        m.put(key, session);
    }


    @Override
    public ModelSession getSession(String key) throws Exception {
        return m.get(key);
    }


    @Override
    public void removeSession(String key) {
        m.remove(key);
    }


    @Override
    public Set<String> keys(int skip, int limit, String sortby, boolean sortAscending) {
        return m.keySet();
    }


    @Override
    public long getCount() {
        return m.size();
    }


    @Override
    public void ping() {
        if (m == null) {
            throw new NullPointerException("Illegal hashtable store.");
        }
    }


    @Override
    public boolean hasSession(String suid) throws Exception {
        return m.containsKey(suid);
    }
    
}