1 // Copyright (C) 2018-2019 HuntLabs. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 module hunt.gossip.model.SeedMember;
16 
17 import hunt.Integer;
18 import hunt.io.Common;
19 
20 public class SeedMember : Serializable {
21     private string cluster;
22     private string ipAddress;
23     private Integer port;
24     private string id;
25 
26     public this(string cluster, string ipAddress, Integer port, string id) {
27         this.cluster = cluster;
28         this.ipAddress = ipAddress;
29         this.port = port;
30         this.id = id;
31     }
32 
33     public this() {
34 
35     }
36 
37     public string getCluster() {
38         return cluster;
39     }
40 
41     public void setCluster(string cluster) {
42         this.cluster = cluster;
43     }
44 
45     public string getIpAddress() {
46         return ipAddress;
47     }
48 
49     public void setIpAddress(string ipAddress) {
50         this.ipAddress = ipAddress;
51     }
52 
53     public Integer getPort() {
54         return port;
55     }
56 
57     public void setPort(Integer port) {
58         this.port = port;
59     }
60 
61     public string getId() {
62         return id;
63     }
64 
65     public void setId(string id) {
66         this.id = id;
67     }
68     
69     public string eigenvalue(){
70         return getCluster() ~ (":") ~ (getIpAddress()) ~ (":") ~ (getPort().toString());
71     }
72 
73     override
74     public bool opEquals(Object o) {
75         if (this is o) return true;
76         if (o is null || typeid(this) != typeid(o)) return false;
77 
78         SeedMember that = cast(SeedMember) o;
79 
80         if (!(cluster == that.cluster)) return false;
81         if (!(ipAddress == that.ipAddress)) return false;
82         return port.intValue() == that.port.intValue();
83     }
84 
85     override
86     public size_t toHash() @trusted nothrow {
87         size_t result = cluster.hashOf();
88         result = 31 * result + ipAddress.hashOf();
89         result = 31 * result + port.hashOf();
90         return result;
91     }
92 
93     override
94     public string toString() {
95         return "SeedMember{" ~
96                 "cluster='" ~ cluster ~ '\'' ~
97                 ", ipAddress='" ~ ipAddress ~ '\'' ~
98                 ", port=" ~ port.toString ~
99                 ", id='" ~ id ~ '\'' ~
100                 '}';
101     }
102 }