001
014
015 package com.liferay.portal.dao.shard.advice;
016
017 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018 import com.liferay.portal.kernel.dao.shard.ShardUtil;
019 import com.liferay.portal.kernel.log.Log;
020 import com.liferay.portal.kernel.log.LogFactoryUtil;
021 import com.liferay.portlet.journal.service.JournalArticleLocalService;
022
023 import java.lang.reflect.Method;
024
025 import org.aopalliance.intercept.MethodInterceptor;
026 import org.aopalliance.intercept.MethodInvocation;
027
028
033 public class ShardGloballyAdvice implements MethodInterceptor {
034
035
041 @Override
042 public Object invoke(MethodInvocation methodInvocation) throws Throwable {
043 Object returnValue = null;
044
045 _shardAdvice.setGlobalCall(new Object());
046
047 try {
048 for (String shardName : ShardUtil.getAvailableShardNames()) {
049 if (_log.isInfoEnabled()) {
050 _log.info(
051 "Invoking shard " + shardName + " for " +
052 methodInvocation.toString());
053 }
054
055 ShardUtil.setTargetSource(shardName);
056
057 _shardAdvice.pushCompanyService(shardName);
058
059 try {
060 Object value = methodInvocation.proceed();
061
062 if (shardName.equals(ShardUtil.getDefaultShardName())) {
063 returnValue = value;
064 }
065 }
066 finally {
067 _shardAdvice.popCompanyService();
068
069 Method method = methodInvocation.getMethod();
070
071 Class<?> clazz = method.getDeclaringClass();
072
073 String className = clazz.getName();
074
075 String methodName = method.getName();
076
077 if (className.equals(
078 JournalArticleLocalService.class.getName()) &&
079 methodName.equals("checkArticles")) {
080
081 continue;
082 }
083
084 CacheRegistryUtil.clear();
085 }
086 }
087 }
088 finally {
089 _shardAdvice.setGlobalCall(null);
090 }
091
092 return returnValue;
093 }
094
095 public void setShardAdvice(ShardAdvice shardAdvice) {
096 _shardAdvice = shardAdvice;
097 }
098
099 private static Log _log = LogFactoryUtil.getLog(ShardGloballyAdvice.class);
100
101 private ShardAdvice _shardAdvice;
102
103 }