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 java.util.Set;
18  import java.util.concurrent.ThreadPoolExecutor;
19  
20  /**
21   * <a href="ParallelDestination.java.html"><b><i>View Source</i></b></a>
22   *
23   * <p>
24   * Destination that delivers a message to a list of message listeners in
25   * parallel.
26   * </p>
27   *
28   * @author Michael C. Han
29   */
30  public class ParallelDestination extends BaseDestination {
31  
32      public ParallelDestination() {
33      }
34  
35      /**
36       * @deprecated
37       */
38      public ParallelDestination(String name) {
39          super(name);
40      }
41  
42      /**
43       * @deprecated
44       */
45      public ParallelDestination(
46          String name, int workersCoreSize, int workersMaxSize) {
47  
48          super(name, workersCoreSize, workersMaxSize);
49      }
50  
51      protected void dispatch(
52          Set<MessageListener> messageListeners, final Message message) {
53  
54          ThreadPoolExecutor threadPoolExecutor = getThreadPoolExecutor();
55  
56          for (final MessageListener messageListener : messageListeners) {
57              Runnable runnable = new Runnable() {
58  
59                  public void run() {
60                      messageListener.receive(message);
61                  }
62  
63              };
64  
65              threadPoolExecutor.execute(runnable);
66          }
67      }
68  
69  }