001
014
015 package com.liferay.portal.kernel.staging;
016
017 import com.liferay.portal.kernel.util.AutoResetThreadLocal;
018 import com.liferay.portal.kernel.util.StringBundler;
019
020 import java.util.HashSet;
021 import java.util.Set;
022
023
026 public class MergeLayoutPrototypesThreadLocal {
027
028 public static boolean isInProgress() {
029 return _inProgress.get();
030 }
031
032 public static boolean isMergeComplete(
033 String methodName, Object[] arguments, Class<?>[] parameterTypes) {
034
035 Set<String> methodKeys = _mergeComplete.get();
036
037 String methodKey = _buildMethodKey(
038 methodName, arguments, parameterTypes);
039
040 return methodKeys.contains(methodKey);
041 }
042
043 public static void setInProgress(boolean inProgress) {
044 _inProgress.set(inProgress);
045 }
046
047 public static void setMergeComplete(
048 String methodName, Object[] arguments, Class<?>[] parameterTypes) {
049
050 Set<String> methodKeys = _mergeComplete.get();
051
052 String methodKey = _buildMethodKey(
053 methodName, arguments, parameterTypes);
054
055 methodKeys.add(methodKey);
056
057 setInProgress(false);
058 }
059
060 private static String _buildMethodKey(
061 String methodName, Object[] arguments, Class<?>[] parameterTypes) {
062
063 StringBundler sb = new StringBundler(arguments.length * 2 + 1);
064
065 sb.append(methodName);
066
067 for (int i = 0; i < arguments.length; i++) {
068 sb.append(parameterTypes[0].getClass().getName());
069
070 sb.append(arguments.toString());
071 }
072
073 return sb.toString();
074 }
075
076 private static ThreadLocal<Boolean> _inProgress =
077 new AutoResetThreadLocal<Boolean>(
078 MergeLayoutPrototypesThreadLocal.class + "._inProgress", false);
079 private static ThreadLocal<Set<String>> _mergeComplete =
080 new AutoResetThreadLocal<Set<String>>(
081 MergeLayoutPrototypesThreadLocal.class + "._mergeComplete",
082 new HashSet<String>());
083
084 }