Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…@6214 4ca5cf0f-1a52-0410-96e1-5992aa8baeaf
badqiu committed Jan 4, 2011
1 parent 9ac4301 commit 9ec0ca0
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -2,45 +2,50 @@

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
* 分布式 ThreadLocal, 存放在ThreadLocal中的数据可以传输至另外一台机器上
*
* @author badqiu
*
*/
public class DistributedThreadLocal {
/**
* 分布式ThreadLocal的ID
**/
public static String DISTRIBUTED_THREAD_LOCAL_ID = "DISTRIBUTED_THREAD_LOCAL_ID";


public static String DISTRIBUTED_THREAD_LOCAL_KEY_PREFIX = "tl_";

public static ThreadLocal<Map<String, String>> threadLocal = new ThreadLocal<Map<String, String>>();

public static void putAll(Map<String, String> map) {
getMap().putAll(map);
getMap().putAll(map);
}

public static void put(String key, String value) {
getMap().put(key, value);
getMap().put(key, value);
}

public static String get(String key) {
Map<String, String> map = threadLocal.get();
if (map == null)
return null;
return (String) map.get(key);
return (String) getMap().get(key);
}

public static Map<String, String> getMap() {
Map<String, String> map = threadLocal.get();
if (map == null) {
map = new HashMap();
map = new HashMap<String, String>();
map.put(DISTRIBUTED_THREAD_LOCAL_ID, UUID.randomUUID().toString().replace("-", ""));

threadLocal.set(map);
}
return map;
}

public static void clear() {
threadLocal.set(null);
}


public static void onBeforeRemoteCall() {
}

0 comments on commit 9ec0ca0

Please sign in to comment.