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