1
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
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 }