public void clear() {
   Hashtable<String, Object> ht = tlm.get();
   if (ht != null) {
     ht.clear();
   }
   tlm.remove();
 }
 public void putAll(Map<String, Object> context) {
   Hashtable<String, Object> ht = tlm.get();
   if (ht == null) {
     ht = new Hashtable<String, Object>(HT_SIZE);
     tlm.set(ht);
   }
   ht.putAll(context);
 }
 public void put(String key, Object o) {
   Hashtable<String, Object> ht = tlm.get();
   if (ht == null) {
     ht = new Hashtable<String, Object>(HT_SIZE);
     tlm.set(ht);
   }
   ht.put(key, o);
 }
 public void setContextMap(Map<String, Object> contextMap) {
   Hashtable<String, Object> ht = tlm.get();
   if (ht != null) {
     ht.clear();
   } else {
     ht = new Hashtable<String, Object>(HT_SIZE);
     tlm.set(ht);
   }
   ht.putAll(contextMap);
 }
Exemplo n.º 5
0
  @Override
  public T get() {
    ThreadLocalMap threadLocalMap = _getThreadLocalMap();

    Entry entry = threadLocalMap.getEntry(this);

    if (entry == null) {
      T value = initialValue();

      threadLocalMap.putEntry(this, value);

      return value;
    } else {
      return (T) entry._value;
    }
  }
 public Map<String, Object> getCopyOfContextMap() {
   Hashtable<String, Object> ht = tlm.get();
   if (ht != null) {
     return new Hashtable<String, Object>(ht);
   } else {
     return null;
   }
 }
 public Object get(String key) {
   Hashtable ht = tlm.get();
   if (ht != null && key != null) {
     return ht.get(key);
   } else {
     return null;
   }
 }
Exemplo n.º 8
0
  public static void setThreadLocals(
      Map<CentralizedThreadLocal<?>, Object> longLivedThreadLocals,
      Map<CentralizedThreadLocal<?>, Object> shortLivedThreadLocals) {

    ThreadLocalMap threadLocalMap = _longLivedThreadLocals.get();

    for (Map.Entry<CentralizedThreadLocal<?>, Object> entry : longLivedThreadLocals.entrySet()) {

      threadLocalMap.putEntry(entry.getKey(), entry.getValue());
    }

    threadLocalMap = _shortLivedThreadLocals.get();

    for (Map.Entry<CentralizedThreadLocal<?>, Object> entry : shortLivedThreadLocals.entrySet()) {

      threadLocalMap.putEntry(entry.getKey(), entry.getValue());
    }
  }
 public Map<String, Object> getContext() {
   return tlm.get();
 }
Exemplo n.º 10
0
 public void remove(String key) {
   Hashtable ht = tlm.get();
   if (ht != null) {
     ht.remove(key);
   }
 }
Exemplo n.º 11
0
 public static void createLoggerForThread(String fileName) {
   TrafficLogger logger = new TrafficLogger(fileName);
   ThreadLocalMap.put("logger", logger);
 }
Exemplo n.º 12
0
 public static TrafficLogger getLoggerForThread() {
   return (TrafficLogger) ThreadLocalMap.get("logger");
 }
Exemplo n.º 13
0
  @Override
  public void set(T value) {
    ThreadLocalMap threadLocalMap = _getThreadLocalMap();

    threadLocalMap.putEntry(this, value);
  }
Exemplo n.º 14
0
  @Override
  public void remove() {
    ThreadLocalMap threadLocalMap = _getThreadLocalMap();

    threadLocalMap.removeEntry(this);
  }