001    /**
002     * Copyright (c) 2000-2013 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.StringBundler;
018    
019    import java.io.Serializable;
020    
021    /**
022     * @author Tina Tian
023     */
024    public class ClusterNodeResponse implements Serializable {
025    
026            public Address getAddress() {
027                    return _address;
028            }
029    
030            public ClusterMessageType getClusterMessageType() {
031                    return _clusterMessageType;
032            }
033    
034            public ClusterNode getClusterNode() {
035                    return _clusterNode;
036            }
037    
038            public Exception getException() {
039                    return _exception;
040            }
041    
042            public Object getResult() throws Exception {
043                    if (_exception != null) {
044                            throw _exception;
045                    }
046    
047                    return _result;
048            }
049    
050            public String getUuid() {
051                    return _uuid;
052            }
053    
054            public boolean hasException() {
055                    if (_exception != null) {
056                            return true;
057                    }
058                    else {
059                            return false;
060                    }
061            }
062    
063            public boolean isMulticast() {
064                    return _multicast;
065            }
066    
067            public void setAddress(Address address) {
068                    _address = address;
069            }
070    
071            public void setClusterMessageType(ClusterMessageType clusterMessageType) {
072                    _clusterMessageType = clusterMessageType;
073            }
074    
075            public void setClusterNode(ClusterNode clusterNode) {
076                    _clusterNode = clusterNode;
077            }
078    
079            public void setException(Exception exception) {
080                    _exception = exception;
081            }
082    
083            public void setMulticast(boolean multicast) {
084                    _multicast = multicast;
085            }
086    
087            public void setResult(Object result) {
088                    _result = result;
089            }
090    
091            public void setUuid(String uuid) {
092                    _uuid = uuid;
093            }
094    
095            @Override
096            public String toString() {
097                    StringBundler sb = new StringBundler(9);
098    
099                    sb.append("{clusterMessageType=");
100                    sb.append(_clusterMessageType);
101    
102                    boolean clusterMessageTypeNotifyOrUpdate = false;
103    
104                    if (_clusterMessageType.equals(ClusterMessageType.NOTIFY) ||
105                            _clusterMessageType.equals(ClusterMessageType.UPDATE)) {
106    
107                            clusterMessageTypeNotifyOrUpdate = true;
108                    }
109    
110                    if (clusterMessageTypeNotifyOrUpdate) {
111                            sb.append(", clusterNode=");
112                            sb.append(_clusterNode);
113                    }
114    
115                    if (!clusterMessageTypeNotifyOrUpdate && hasException()) {
116                            sb.append(", exception=");
117                            sb.append(_exception);
118                    }
119    
120                    sb.append(", multicast=");
121                    sb.append(_multicast);
122    
123                    if (!clusterMessageTypeNotifyOrUpdate && !hasException()) {
124                            sb.append(", result=");
125                            sb.append(_result);
126                    }
127    
128                    sb.append(", uuid=");
129                    sb.append(_uuid);
130                    sb.append("}");
131    
132                    return sb.toString();
133            }
134    
135            private Address _address;
136            private ClusterMessageType _clusterMessageType;
137            private ClusterNode _clusterNode;
138            private Exception _exception;
139            private boolean _multicast;
140            private Object _result;
141            private String _uuid;
142    
143    }