1 package org.apache.commons.jcs3.utils.discovery;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.Serializable;
23 import java.util.ArrayList;
24 import java.util.Objects;
25
26
27
28
29
30 public class DiscoveredService
31 implements Serializable
32 {
33
34 private static final long serialVersionUID = -7810164772089509751L;
35
36
37 private ArrayList<String> cacheNames;
38
39
40 private String serviceAddress;
41
42
43 private int servicePort;
44
45
46 private long lastHearFromTime;
47
48
49
50
51 public DiscoveredService()
52 {
53
54 }
55
56
57
58
59
60
61
62 public DiscoveredService(UDPDiscoveryMessage message)
63 {
64 setServiceAddress( message.getHost() );
65 setCacheNames( message.getCacheNames() );
66 setServicePort( message.getPort() );
67 setLastHearFromTime( System.currentTimeMillis() );
68 }
69
70
71
72
73 public void setCacheNames( final ArrayList<String> cacheNames )
74 {
75 this.cacheNames = cacheNames;
76 }
77
78
79
80
81 public ArrayList<String> getCacheNames()
82 {
83 return cacheNames;
84 }
85
86
87
88
89 public void setServiceAddress( final String serviceAddress )
90 {
91 this.serviceAddress = serviceAddress;
92 }
93
94
95
96
97 public String getServiceAddress()
98 {
99 return serviceAddress;
100 }
101
102
103
104
105 public void setServicePort( final int servicePort )
106 {
107 this.servicePort = servicePort;
108 }
109
110
111
112
113 public int getServicePort()
114 {
115 return servicePort;
116 }
117
118
119
120
121 public void setLastHearFromTime( final long lastHearFromTime )
122 {
123 this.lastHearFromTime = lastHearFromTime;
124 }
125
126
127
128
129 public long getLastHearFromTime()
130 {
131 return lastHearFromTime;
132 }
133
134
135 @Override
136 public int hashCode()
137 {
138 return Objects.hash(serviceAddress, servicePort);
139 }
140
141
142
143
144
145
146
147
148
149
150
151 @Override
152 public boolean equals(final Object otherArg)
153 {
154 if (this == otherArg)
155 {
156 return true;
157 }
158 if (otherArg == null)
159 {
160 return false;
161 }
162 if (!(otherArg instanceof DiscoveredService))
163 {
164 return false;
165 }
166 final DiscoveredService other = (DiscoveredService) otherArg;
167 if (!Objects.equals(serviceAddress, other.serviceAddress))
168 {
169 return false;
170 }
171 return servicePort == other.servicePort;
172 }
173
174
175
176
177 @Override
178 public String toString()
179 {
180 final StringBuilder buf = new StringBuilder();
181 buf.append( "\n DiscoveredService" );
182 buf.append( "\n CacheNames = [" + getCacheNames() + "]" );
183 buf.append( "\n ServiceAddress = [" + getServiceAddress() + "]" );
184 buf.append( "\n ServicePort = [" + getServicePort() + "]" );
185 buf.append( "\n LastHearFromTime = [" + getLastHearFromTime() + "]" );
186 return buf.toString();
187 }
188 }