001
014
015 package com.liferay.portal.kernel.cluster;
016
017 import com.liferay.portal.kernel.util.ReflectionUtil;
018 import com.liferay.portal.kernel.util.StringBundler;
019
020 import java.io.Serializable;
021
022
025 public class ClusterNodeResponse implements Serializable {
026
027 public static ClusterNodeResponse createExceptionClusterNodeResponse(
028 ClusterNode clusterNode, String uuid, Exception exception) {
029
030 return new ClusterNodeResponse(clusterNode, uuid, null, exception);
031 }
032
033 public static ClusterNodeResponse createResultClusterNodeResponse(
034 ClusterNode clusterNode, String uuid, Serializable result) {
035
036 return new ClusterNodeResponse(clusterNode, uuid, result, null);
037 }
038
039 public ClusterNode getClusterNode() {
040 return _clusterNode;
041 }
042
043 public Exception getException() {
044 return _exception;
045 }
046
047 public Serializable getResult() {
048 if (_exception != null) {
049 return ReflectionUtil.throwException(_exception);
050 }
051
052 return _result;
053 }
054
055 public String getUuid() {
056 return _uuid;
057 }
058
059 public boolean hasException() {
060 if (_exception != null) {
061 return true;
062 }
063 else {
064 return false;
065 }
066 }
067
068 @Override
069 public String toString() {
070 StringBundler sb = new StringBundler(7);
071
072 sb.append("{clusterNode=");
073 sb.append(_clusterNode);
074
075 if (hasException()) {
076 sb.append(", exception=");
077 sb.append(_exception);
078 }
079 else {
080 sb.append(", result=");
081 sb.append(_result);
082 }
083
084 sb.append(", uuid=");
085 sb.append(_uuid);
086 sb.append("}");
087
088 return sb.toString();
089 }
090
091 private ClusterNodeResponse(
092 ClusterNode clusterNode, String uuid, Serializable result,
093 Exception exception) {
094
095 if (clusterNode == null) {
096 throw new NullPointerException("Cluster node is null");
097 }
098
099 _clusterNode = clusterNode;
100 _uuid = uuid;
101 _result = result;
102 _exception = exception;
103 }
104
105 private final ClusterNode _clusterNode;
106 private final Exception _exception;
107 private final Serializable _result;
108 private final String _uuid;
109
110 }