1
2
3
4 package org.sourceforge.jemmrpc.server;
5
6 import java.util.concurrent.atomic.AtomicInteger;
7
8
9
10
11
12
13 public class ClientId
14 {
15
16 protected static final AtomicInteger nextClientId = new AtomicInteger(1);
17
18
19 protected final String clientIdString;
20
21
22
23
24 public ClientId()
25 {
26 this.clientIdString = "CL:" + nextClientId.getAndIncrement();
27 }
28
29
30
31
32
33
34 public ClientId(String internalId)
35 {
36 if(internalId == null)
37 throw new IllegalArgumentException("internal id cannot be null");
38 this.clientIdString = internalId;
39 }
40
41
42
43
44
45
46 public String getInternalId()
47 {
48 return clientIdString;
49 }
50
51
52
53
54
55
56 @Override
57 public boolean equals(Object obj)
58 {
59 if (this == obj)
60 return true;
61 if (obj == null)
62 return false;
63 if (getClass() != obj.getClass())
64 return false;
65
66
67 final ClientId other = (ClientId) obj;
68 return clientIdString.equals(other.clientIdString);
69 }
70
71
72
73
74
75
76 @Override
77 public int hashCode()
78 {
79 return clientIdString.hashCode();
80 }
81
82 @Override
83 public String toString()
84 {
85 return "ClientId(" + clientIdString + ")";
86 }
87 }