View Javadoc

1   package org.sourceforge.jemm.comm.server;
2   
3   import java.util.concurrent.atomic.AtomicInteger;
4   
5   /**
6    * A client identifier.
7    * 
8    * <i><P>Released under the <a href="http://www.apache.org/licenses/LICENSE-2.0.html">Apache License V2.0 license</a> 
9    * by the <a href="http://jemm.sourceforge.net">JEMM Project</a></i>
10   *
11   * @author Rory Graves
12   */
13  public class RPCClientId {
14      /** Internal counter for client ids */
15      protected static final AtomicInteger ID_SOURCE = new AtomicInteger(1);
16  
17      /** The internal id of this client. */
18      protected final String clientIdString;
19  
20      /**
21       * Create a unique ClientId.
22       */
23      public RPCClientId() {
24          this("CL:" + ID_SOURCE.getAndIncrement());
25      }
26  
27      /**
28       * Create a stored client id.
29       * @param internalId The internal id of the client.
30       */
31      public RPCClientId(String internalId) {
32      	if(internalId == null)
33      		throw new IllegalArgumentException("rpc client id cannot be null");
34      	
35          this.clientIdString = internalId;
36      }
37  
38      /**
39       * Returns the internal representation if this id for storage.
40       * @return The internal representation of this id.
41       */
42      public String getInternalId() {
43          return clientIdString;
44      }
45      
46      @Override
47      public boolean equals(Object obj) {
48          if (this == obj)
49              return true;
50          if (obj == null)
51              return false;
52          if (getClass() != obj.getClass())
53              return false;
54          final RPCClientId other = (RPCClientId) obj;
55          return clientIdString.equals(other.clientIdString);
56      }
57  
58      @Override
59      public int hashCode() {
60          return clientIdString.hashCode();
61      }
62  
63      @Override
64      public String toString() {
65          return "ClientId(" + clientIdString + ")";
66      }
67  }