001
014
015 package com.liferay.portal.kernel.cluster;
016
017 import com.liferay.portal.kernel.exception.SystemException;
018 import com.liferay.portal.kernel.log.Log;
019 import com.liferay.portal.kernel.log.LogFactoryUtil;
020
021 import java.util.Collections;
022 import java.util.List;
023
024
027 public class ClusterExecutorUtil {
028
029 public static void addClusterEventListener(
030 ClusterEventListener clusterEventListener) {
031
032 if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
033 if (_log.isWarnEnabled()) {
034 _log.warn("ClusterExecutorUtil has not been initialized");
035 }
036
037 return;
038 }
039
040 _clusterExecutor.addClusterEventListener(clusterEventListener);
041 }
042
043 public static void destroy() {
044 if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
045 if (_log.isWarnEnabled()) {
046 _log.warn("ClusterExecutorUtil has not been initialized");
047 }
048
049 return;
050 }
051
052 _clusterExecutor.destroy();
053 }
054
055 public static FutureClusterResponses execute(ClusterRequest clusterRequest)
056 throws SystemException {
057
058 if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
059 if (_log.isWarnEnabled()) {
060 _log.warn("ClusterExecutorUtil has not been initialized");
061 }
062
063 return null;
064 }
065
066 return _clusterExecutor.execute(clusterRequest);
067 }
068
069 public static List<Address> getClusterNodeAddresses() {
070 if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
071 if (_log.isWarnEnabled()) {
072 _log.warn("ClusterExecutorUtil has not been initialized");
073 }
074
075 return Collections.emptyList();
076 }
077
078 return _clusterExecutor.getClusterNodeAddresses();
079 }
080
081 public static List<ClusterNode> getClusterNodes() {
082 if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
083 if (_log.isWarnEnabled()) {
084 _log.warn("ClusterExecutorUtil has not been initialized");
085 }
086
087 return Collections.emptyList();
088 }
089
090 return _clusterExecutor.getClusterNodes();
091 }
092
093 public static ClusterNode getLocalClusterNode() throws SystemException {
094 if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
095 if (_log.isWarnEnabled()) {
096 _log.warn("ClusterExecutorUtil has not been initialized");
097 }
098
099 return null;
100 }
101
102 return _clusterExecutor.getLocalClusterNode();
103 }
104
105 public static Address getLocalClusterNodeAddress() {
106 if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
107 if (_log.isWarnEnabled()) {
108 _log.warn("ClusterExecutorUtil has not been initialized");
109 }
110
111 return null;
112 }
113
114 return _clusterExecutor.getLocalClusterNodeAddress();
115 }
116
117 public static void initialize() {
118 if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
119 if (_log.isWarnEnabled()) {
120 _log.warn("ClusterExecutorUtil has not been initialized");
121 }
122
123 return;
124 }
125
126 _clusterExecutor.initialize();
127 }
128
129 public static boolean isClusterNodeAlive(Address address) {
130 if ((_clusterExecutor == null) || !_clusterExecutor .isEnabled()) {
131 if (_log.isWarnEnabled()) {
132 _log.warn("ClusterExecutorUtil has not been initialized");
133 }
134
135 return false;
136 }
137
138 return _clusterExecutor.isClusterNodeAlive(address);
139 }
140
141 public static boolean isClusterNodeAlive(String clusterNodeId) {
142 if ((_clusterExecutor == null) || !_clusterExecutor .isEnabled()) {
143 if (_log.isWarnEnabled()) {
144 _log.warn("ClusterExecutorUtil has not been initialized");
145 }
146
147 return false;
148 }
149
150 return _clusterExecutor.isClusterNodeAlive(clusterNodeId);
151 }
152
153 public static boolean isEnabled() {
154 if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
155 if (_log.isWarnEnabled()) {
156 _log.warn("ClusterExecutorUtil has not been initialized");
157 }
158
159 return false;
160 }
161
162 return true;
163 }
164
165 public static void removeClusterEventListener(
166 ClusterEventListener clusterEventListener) {
167
168 if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
169 if (_log.isWarnEnabled()) {
170 _log.warn("ClusterExecutorUtil has not been initialized");
171 }
172
173 return;
174 }
175
176 _clusterExecutor.removeClusterEventListener(clusterEventListener);
177 }
178
179 public void setClusterExecutor(ClusterExecutor clusterExecutor) {
180 _clusterExecutor = clusterExecutor;
181 }
182
183 private static Log _log = LogFactoryUtil.getLog(ClusterExecutorUtil.class);
184
185 private static ClusterExecutor _clusterExecutor;
186
187 }