001
014
015 package com.liferay.portal.kernel.messaging;
016
017 import com.liferay.portal.kernel.util.ThreadLocalRegistry;
018
019 import java.util.Set;
020 import java.util.concurrent.ThreadPoolExecutor;
021
022
030 public class SerialDestination extends BaseDestination {
031
032 public SerialDestination() {
033 super();
034
035 setWorkersCoreSize(_WORKERS_CORE_SIZE);
036 setWorkersMaxSize(_WORKERS_MAX_SIZE);
037 }
038
039
042 public SerialDestination(String name) {
043 super(name, _WORKERS_CORE_SIZE, _WORKERS_MAX_SIZE);
044 }
045
046 protected void dispatch(
047 final Set<MessageListener> messageListeners, final Message message) {
048
049 ThreadPoolExecutor threadPoolExecutor = getThreadPoolExecutor();
050
051 Runnable runnable = new MessageRunnable(message) {
052
053 public void run() {
054 try {
055 for (MessageListener messageListener : messageListeners) {
056 messageListener.receive(message);
057 }
058 }
059 finally {
060 ThreadLocalRegistry.resetThreadLocals();
061 }
062 }
063
064 };
065
066 threadPoolExecutor.execute(runnable);
067 }
068
069 private static final int _WORKERS_CORE_SIZE = 1;
070
071 private static final int _WORKERS_MAX_SIZE = 1;
072
073 }