001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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    /**
023     * @author Tina Tian
024     */
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    }