001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.cluster;
016    
017    import com.liferay.portal.kernel.util.InitialThreadLocal;
018    
019    import java.io.Serializable;
020    
021    import java.util.HashMap;
022    import java.util.Map;
023    
024    /**
025     * @author Tina Tian
026     */
027    public class ClusterableContextThreadLocal {
028    
029            public static void putThreadLocalContext(String key, Serializable value) {
030                    Map<String, Serializable> context = _contextThreadLocal.get();
031    
032                    context.put(key, value);
033            }
034    
035            protected static Map<String, Serializable> collectThreadLocalContext() {
036                    Map<String, Serializable> context = _contextThreadLocal.get();
037    
038                    _contextThreadLocal.remove();
039    
040                    return context;
041            }
042    
043            private static ThreadLocal<HashMap<String, Serializable>>
044                    _contextThreadLocal =
045                            new InitialThreadLocal<HashMap<String, Serializable>>(
046                                    ClusterableContextThreadLocal.class.getName() +
047                                            "._contextThreadLocal",
048                                    new HashMap<String, Serializable>(), true);
049    
050    }