1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   * 
13   */
14  
15  package com.liferay.portal.kernel.cluster;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portal.kernel.messaging.Message;
20  import com.liferay.portal.kernel.util.MethodWrapper;
21  
22  import java.util.Collections;
23  import java.util.List;
24  import java.util.Map;
25  import java.util.concurrent.Future;
26  
27  /**
28   * <a href="ClusterExecutorUtil.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Tina Tian
31   */
32  public class ClusterExecutorUtil {
33  
34      public static Map<Address, Future<?>> executeMulticastCall(
35          MethodWrapper methodWrapper) {
36  
37          if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
38              if (_log.isWarnEnabled()) {
39                  _log.warn("ClusterExecutorUtil has not been initialized");
40              }
41  
42              return null;
43          }
44  
45          return _clusterExecutor.executeMulticastCall(methodWrapper);
46      }
47  
48      public static Future<?> executeUnicastCall(
49          Address address, MethodWrapper methodWrapper) {
50  
51          if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
52              if (_log.isWarnEnabled()) {
53                  _log.warn("ClusterExecutorUtil has not been initialized");
54              }
55  
56              return null;
57          }
58  
59          return _clusterExecutor.executeUnicastCall(address, methodWrapper);
60      }
61  
62      public static Address getAddress(Message message) {
63          return (Address)message.get(_ADDRESS);
64      }
65  
66      public static ClusterExecutor getClusterExecutor() {
67          if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
68              if (_log.isWarnEnabled()) {
69                  _log.warn("ClusterExecutorUtil has not been initialized");
70              }
71  
72              return null;
73          }
74  
75          return _clusterExecutor;
76      }
77  
78      public static List<Address> getControlAddresses() {
79          if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
80              if (_log.isWarnEnabled()) {
81                  _log.warn("ClusterExecutorUtil has not been initialized");
82              }
83  
84              return Collections.EMPTY_LIST;
85          }
86  
87          return _clusterExecutor.getControlAddresses();
88      }
89  
90      public static Address getLocalControlAddresses() {
91          if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
92              if (_log.isWarnEnabled()) {
93                  _log.warn("ClusterExecutorUtil has not been initialized");
94              }
95  
96              return null;
97          }
98  
99          return _clusterExecutor.getLocalControlAddress();
100     }
101 
102     public static boolean isShortcutLocalMethod() {
103         if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
104             if (_log.isWarnEnabled()) {
105                 _log.warn("ClusterExecutorUtil has not been initialized");
106             }
107 
108             return true;
109         }
110 
111         return _clusterExecutor.isShortcutLocalMethod();
112     }
113 
114     public void setClusterExecutor(ClusterExecutor clusterExecutor) {
115         _clusterExecutor = clusterExecutor;
116     }
117 
118     private static final String _ADDRESS = "CLUSTER_CONTROL_ADDRESS";
119 
120     private static Log _log = LogFactoryUtil.getLog(ClusterExecutorUtil.class);
121 
122     private static ClusterExecutor _clusterExecutor;
123 
124 }