| ParallelDestination.java |
1 /**
2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by the Free
6 * Software Foundation; either version 2.1 of the License, or (at your option)
7 * any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
13 */
14
15 package com.liferay.portal.kernel.messaging;
16
17 import com.liferay.portal.kernel.util.ThreadLocalRegistry;
18
19 import java.util.Set;
20 import java.util.concurrent.ThreadPoolExecutor;
21
22 /**
23 * <a href="ParallelDestination.java.html"><b><i>View Source</i></b></a>
24 *
25 * <p>
26 * Destination that delivers a message to a list of message listeners in
27 * parallel.
28 * </p>
29 *
30 * @author Michael C. Han
31 */
32 public class ParallelDestination extends BaseDestination {
33
34 public ParallelDestination() {
35 }
36
37 /**
38 * @deprecated
39 */
40 public ParallelDestination(String name) {
41 super(name);
42 }
43
44 /**
45 * @deprecated
46 */
47 public ParallelDestination(
48 String name, int workersCoreSize, int workersMaxSize) {
49
50 super(name, workersCoreSize, workersMaxSize);
51 }
52
53 protected void dispatch(
54 Set<MessageListener> messageListeners, final Message message) {
55
56 ThreadPoolExecutor threadPoolExecutor = getThreadPoolExecutor();
57
58 for (final MessageListener messageListener : messageListeners) {
59 Runnable runnable = new Runnable() {
60
61 public void run() {
62 try {
63 messageListener.receive(message);
64 }
65 finally {
66 ThreadLocalRegistry.resetThreadLocals();
67 }
68 }
69
70 };
71
72 threadPoolExecutor.execute(runnable);
73 }
74 }
75
76 }