001
014
015 package com.liferay.portal.kernel.messaging;
016
017 import com.liferay.portal.kernel.cache.Lifecycle;
018 import com.liferay.portal.kernel.cache.ThreadLocalCacheManager;
019 import com.liferay.portal.kernel.concurrent.ThreadPoolExecutor;
020 import com.liferay.portal.kernel.log.Log;
021 import com.liferay.portal.kernel.log.LogFactoryUtil;
022 import com.liferay.portal.kernel.util.CentralizedThreadLocal;
023
024 import java.util.Set;
025
026
034 public class SerialDestination extends BaseAsyncDestination {
035
036 public SerialDestination() {
037 setWorkersCoreSize(_WORKERS_CORE_SIZE);
038 setWorkersMaxSize(_WORKERS_MAX_SIZE);
039 }
040
041
044 @Deprecated
045 public SerialDestination(String name) {
046 super(name, _WORKERS_CORE_SIZE, _WORKERS_MAX_SIZE);
047 }
048
049 @Override
050 protected void dispatch(
051 final Set<MessageListener> messageListeners, final Message message) {
052
053 ThreadPoolExecutor threadPoolExecutor = getThreadPoolExecutor();
054
055 Runnable runnable = new MessageRunnable(message) {
056
057 @Override
058 public void run() {
059 try {
060 populateThreadLocalsFromMessage(message);
061
062 for (MessageListener messageListener : messageListeners) {
063 try {
064 messageListener.receive(message);
065 }
066 catch (MessageListenerException mle) {
067 _log.error(
068 "Unable to process message " + message, mle);
069 }
070 }
071 }
072 finally {
073 ThreadLocalCacheManager.clearAll(Lifecycle.REQUEST);
074
075 CentralizedThreadLocal.clearShortLivedThreadLocals();
076 }
077 }
078
079 };
080
081 threadPoolExecutor.execute(runnable);
082 }
083
084 private static final int _WORKERS_CORE_SIZE = 1;
085
086 private static final int _WORKERS_MAX_SIZE = 1;
087
088 private static final Log _log = LogFactoryUtil.getLog(
089 SerialDestination.class);
090
091 }