All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.mkolisnyk.sirius.client.Context Maven / Gradle / Ivy

The newest version!
package com.github.mkolisnyk.sirius.client;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

public final class Context {

    private Context() {
    }

    private static ConcurrentHashMap> contextVariables
        = new ConcurrentHashMap>();
    private static String getThreadName() {
        return Thread.currentThread().getName() + "-" + Thread.currentThread().getId();
    }
    public static void put(String name, Object value) {
        Map dataMap = new HashMap();
        String threadName = getThreadName();
        if (contextVariables.containsKey(threadName)) {
            dataMap = contextVariables.get(threadName);
        }
        dataMap.put(name, value);
        contextVariables.put(threadName, dataMap);
    }
    public static Object get(String name) {
        String threadName = getThreadName();
        if (contextVariables.containsKey(threadName)) {
            return contextVariables.get(threadName).get(name);
        }
        return null;
    }
    public static void clearCurrent() {
        contextVariables.put(getThreadName(), new HashMap());
    }
    public static Set variables() {
        return contextVariables.get(getThreadName()).keySet();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy