1
14
15 package com.liferay.portal.kernel.cluster;
16
17 import com.liferay.portal.SystemException;
18 import com.liferay.portal.kernel.log.Log;
19 import com.liferay.portal.kernel.log.LogFactoryUtil;
20
21 import java.util.Collections;
22 import java.util.List;
23
24
29 public class ClusterExecutorUtil {
30
31 public static void addClusterEventListener(
32 ClusterEventListener clusterEventListener) {
33
34 if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
35 if (_log.isWarnEnabled()) {
36 _log.warn("ClusterExecutorUtil has not been initialized");
37 }
38
39 return;
40 }
41
42 _clusterExecutor.addClusterEventListener(clusterEventListener);
43 }
44
45 public static void destroy() {
46 if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
47 if (_log.isWarnEnabled()) {
48 _log.warn("ClusterExecutorUtil has not been initialized");
49 }
50
51 return;
52 }
53
54 _clusterExecutor.destroy();
55 }
56
57 public static FutureClusterResponses execute(ClusterRequest clusterRequest)
58 throws SystemException {
59
60 if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
61 if (_log.isWarnEnabled()) {
62 _log.warn("ClusterExecutorUtil has not been initialized");
63 }
64
65 return null;
66 }
67
68 return _clusterExecutor.execute(clusterRequest);
69 }
70
71 public static List<ClusterNode> getClusterNodes() {
72 if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
73 if (_log.isWarnEnabled()) {
74 _log.warn("ClusterExecutorUtil has not been initialized");
75 }
76
77 return Collections.EMPTY_LIST;
78 }
79
80 return _clusterExecutor.getClusterNodes();
81 }
82
83 public static ClusterNode getLocalClusterNode() throws SystemException {
84 if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
85 if (_log.isWarnEnabled()) {
86 _log.warn("ClusterExecutorUtil has not been initialized");
87 }
88
89 return null;
90 }
91
92 return _clusterExecutor.getLocalClusterNode();
93 }
94
95 public static void initialize() {
96 if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
97 if (_log.isWarnEnabled()) {
98 _log.warn("ClusterExecutorUtil has not been initialized");
99 }
100
101 return;
102 }
103
104 _clusterExecutor.initialize();
105 }
106
107 public static boolean isClusterNodeAlive(String clusterNodeId) {
108 if ((_clusterExecutor == null) || !_clusterExecutor .isEnabled()) {
109 if (_log.isWarnEnabled()) {
110 _log.warn("ClusterExecutorUtil has not been initialized");
111 }
112
113 return false;
114 }
115
116 return _clusterExecutor.isClusterNodeAlive(clusterNodeId);
117 }
118
119 public static boolean isEnabled() {
120 if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
121 if (_log.isWarnEnabled()) {
122 _log.warn("ClusterExecutorUtil has not been initialized");
123 }
124
125 return false;
126 }
127
128 return true;
129 }
130
131 public static void removeClusterEventListener(
132 ClusterEventListener clusterEventListener) {
133
134 if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
135 if (_log.isWarnEnabled()) {
136 _log.warn("ClusterExecutorUtil has not been initialized");
137 }
138
139 return;
140 }
141
142 _clusterExecutor.removeClusterEventListener(clusterEventListener);
143 }
144
145 public void setClusterExecutor(ClusterExecutor clusterExecutor) {
146 _clusterExecutor = clusterExecutor;
147 }
148
149 private static Log _log = LogFactoryUtil.getLog(ClusterExecutorUtil.class);
150
151 private static ClusterExecutor _clusterExecutor;
152
153 }