001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.cluster;
016    
017    import com.liferay.portal.kernel.util.StringBundler;
018    import com.liferay.portal.kernel.util.Validator;
019    
020    import java.io.Serializable;
021    
022    import java.net.InetAddress;
023    
024    /**
025     * @author Tina Tian
026     */
027    public class ClusterNode implements Comparable<ClusterNode>, Serializable {
028    
029            public ClusterNode(String clusterNodeId) {
030                    _clusterNodeId = clusterNodeId;
031            }
032    
033            public int compareTo(ClusterNode clusterNode) {
034                    InetAddress inetAddress = clusterNode.getInetAddress();
035    
036                    String ipAddress = inetAddress.getHostAddress();
037    
038                    String curIpAddress = _inetAddress.getHostAddress();
039    
040                    return curIpAddress.compareTo(ipAddress);
041            }
042    
043            @Override
044            public boolean equals(Object obj) {
045                    if (this == obj) {
046                            return true;
047                    }
048    
049                    if (!(obj instanceof ClusterNode)) {
050                            return false;
051                    }
052    
053                    ClusterNode clusterNode = (ClusterNode)obj;
054    
055                    if (Validator.equals(_clusterNodeId, clusterNode._clusterNodeId)) {
056                            return true;
057                    }
058    
059                    return false;
060            }
061    
062            public String getClusterNodeId() {
063                    return _clusterNodeId;
064            }
065    
066            public String getHostName() {
067                    return _hostName;
068            }
069    
070            public InetAddress getInetAddress() {
071                    return _inetAddress;
072            }
073    
074            public int getPort() {
075                    return _port;
076            }
077    
078            @Override
079            public int hashCode() {
080                    return _clusterNodeId.hashCode();
081            }
082    
083            public void setHostName(String hostName) {
084                    _hostName = hostName;
085            }
086    
087            public void setInetAddress(InetAddress inetAddress) {
088                    _inetAddress = inetAddress;
089            }
090    
091            public void setPort(int port) {
092                    _port = port;
093            }
094    
095            @Override
096            public String toString() {
097                    StringBundler sb = new StringBundler(9);
098    
099                    sb.append("{clusterNodeId=");
100                    sb.append(_clusterNodeId);
101                    sb.append(", hostName=");
102                    sb.append(_hostName);
103                    sb.append(", inetAddress=");
104                    sb.append(_inetAddress);
105                    sb.append(", port=");
106                    sb.append(_port);
107                    sb.append("}");
108    
109                    return sb.toString();
110            }
111    
112            private String _clusterNodeId;
113            private String _hostName;
114            private InetAddress _inetAddress;
115            private int _port;
116    
117    }