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 }
034
035
038 public SerialDestination(String name) {
039 super(name, _WORKERS_CORE_SIZE, _WORKERS_MAX_SIZE);
040 }
041
042 protected void dispatch(
043 final Set<MessageListener> messageListeners, final Message message) {
044
045 ThreadPoolExecutor threadPoolExecutor = getThreadPoolExecutor();
046
047 Runnable runnable = new Runnable() {
048
049 public void run() {
050 try {
051 for (MessageListener messageListener : messageListeners) {
052 messageListener.receive(message);
053 }
054 }
055 finally {
056 ThreadLocalRegistry.resetThreadLocals();
057 }
058 }
059
060 };
061
062 threadPoolExecutor.execute(runnable);
063 }
064
065 private static final int _WORKERS_CORE_SIZE = 1;
066
067 private static final int _WORKERS_MAX_SIZE = 1;
068
069 }