001    /**
002     * Copyright (c) 2000-2011 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.kernel.util;
016    
017    import java.util.HashSet;
018    import java.util.Set;
019    
020    /**
021     * @author     Shuyang Zhou
022     * @deprecated {@link CentralizedThreadLocal}
023     */
024    public class ThreadLocalRegistry {
025    
026            public static ThreadLocal<?>[] captureSnapshot() {
027                    Set<ThreadLocal<?>> threadLocalSet = _threadLocalSet.get();
028    
029                    return threadLocalSet.toArray(
030                            new ThreadLocal<?>[threadLocalSet.size()]);
031            }
032    
033            public static void registerThreadLocal(ThreadLocal<?> threadLocal) {
034                    Set<ThreadLocal<?>> threadLocalSet = _threadLocalSet.get();
035    
036                    threadLocalSet.add(threadLocal);
037            }
038    
039            public static void resetThreadLocals() {
040                    Set<ThreadLocal<?>> threadLocalSet = _threadLocalSet.get();
041    
042                    if (threadLocalSet == null) {
043                            return;
044                    }
045    
046                    for (ThreadLocal<?> threadLocal : threadLocalSet) {
047                            threadLocal.remove();
048                    }
049            }
050    
051            private static ThreadLocal<Set<ThreadLocal<?>>> _threadLocalSet =
052                    new InitialThreadLocal<Set<ThreadLocal<?>>>(
053                            ThreadLocalRegistry.class + "._threadLocalSet",
054                            new HashSet<ThreadLocal<?>>());
055    
056    }