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<ClusterNode> getClusterNodes() {
070 if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
071 if (_log.isWarnEnabled()) {
072 _log.warn("ClusterExecutorUtil has not been initialized");
073 }
074
075 return Collections.EMPTY_LIST;
076 }
077
078 return _clusterExecutor.getClusterNodes();
079 }
080
081 public static ClusterNode getLocalClusterNode() throws SystemException {
082 if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
083 if (_log.isWarnEnabled()) {
084 _log.warn("ClusterExecutorUtil has not been initialized");
085 }
086
087 return null;
088 }
089
090 return _clusterExecutor.getLocalClusterNode();
091 }
092
093 public static void initialize() {
094 if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
095 if (_log.isWarnEnabled()) {
096 _log.warn("ClusterExecutorUtil has not been initialized");
097 }
098
099 return;
100 }
101
102 _clusterExecutor.initialize();
103 }
104
105 public static boolean isClusterNodeAlive(String clusterNodeId) {
106 if ((_clusterExecutor == null) || !_clusterExecutor .isEnabled()) {
107 if (_log.isWarnEnabled()) {
108 _log.warn("ClusterExecutorUtil has not been initialized");
109 }
110
111 return false;
112 }
113
114 return _clusterExecutor.isClusterNodeAlive(clusterNodeId);
115 }
116
117 public static boolean isEnabled() {
118 if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
119 if (_log.isWarnEnabled()) {
120 _log.warn("ClusterExecutorUtil has not been initialized");
121 }
122
123 return false;
124 }
125
126 return true;
127 }
128
129 public static void removeClusterEventListener(
130 ClusterEventListener clusterEventListener) {
131
132 if ((_clusterExecutor == null) || !_clusterExecutor.isEnabled()) {
133 if (_log.isWarnEnabled()) {
134 _log.warn("ClusterExecutorUtil has not been initialized");
135 }
136
137 return;
138 }
139
140 _clusterExecutor.removeClusterEventListener(clusterEventListener);
141 }
142
143 public void setClusterExecutor(ClusterExecutor clusterExecutor) {
144 _clusterExecutor = clusterExecutor;
145 }
146
147 private static Log _log = LogFactoryUtil.getLog(ClusterExecutorUtil.class);
148
149 private static ClusterExecutor _clusterExecutor;
150
151 }