@@ -87,15 +87,7 @@ public class Client extends AttributeStore implements IClient {
8787 */
8888 @ ConstructorProperties ({ "id" , "registry" })
8989 public Client (String id , ClientRegistry registry ) {
90- super ();
91- if (id != null ) {
92- this .id = id ;
93- } else {
94- this .id = registry .nextId ();
95- }
96- this .creationTime = System .currentTimeMillis ();
97- // use a weak reference to prevent any hard-links to the registry
98- this .registry = new WeakReference <ClientRegistry >(registry );
90+ this (id , System .currentTimeMillis (), registry );
9991 }
10092
10193 /**
@@ -111,18 +103,25 @@ public Client(String id, ClientRegistry registry) {
111103 @ ConstructorProperties ({ "id" , "creationTime" , "registry" })
112104 public Client (String id , Long creationTime , ClientRegistry registry ) {
113105 super ();
106+ // set the registry as a weak reference to avoid potential memory leaks
107+ this .registry = new WeakReference <ClientRegistry >(registry );
108+ // perform some id sanity checking, don't allow dupes in registry
114109 if (id != null ) {
115- this .id = id ;
110+ if (registry .hasClient (id )) {
111+ log .warn ("Client id: {} already exists in registry, generating new id" , id );
112+ this .id = registry .nextId ();
113+ } else {
114+ this .id = id ;
115+ }
116116 } else {
117117 this .id = registry .nextId ();
118118 }
119+ log .warn ("New Client id: {}" , id );
119120 if (creationTime != null ) {
120- this .creationTime = creationTime ;
121+ this .creationTime = creationTime . longValue () ;
121122 } else {
122123 this .creationTime = System .currentTimeMillis ();
123124 }
124- // use a weak reference to prevent any hard-links to the registry
125- this .registry = new WeakReference <ClientRegistry >(registry );
126125 }
127126
128127 /**
@@ -160,9 +159,11 @@ public Set<IConnection> getConnections() {
160159 }
161160
162161 /**
163- * {@inheritDoc}
164- *
165162 * Return client connections to given scope
163+ *
164+ * @param scope
165+ * Scope
166+ * @return Set of connections for that scope
166167 */
167168 public Set <IConnection > getConnections (IScope scope ) {
168169 if (scope == null ) {
@@ -404,9 +405,11 @@ public int hashCode() {
404405 }
405406
406407 /**
407- * {@inheritDoc}
408- *
409408 * Check clients equality by id
409+ *
410+ * @param obj
411+ * Object to check against
412+ * @return true if clients ids are the same, false otherwise
410413 */
411414 @ Override
412415 public boolean equals (Object obj ) {
@@ -416,7 +419,10 @@ public boolean equals(Object obj) {
416419 return false ;
417420 }
418421
419- /** {@inheritDoc} */
422+ /**
423+ *
424+ * @return string representation of client
425+ */
420426 @ Override
421427 public String toString () {
422428 return "Client: " + id ;
0 commit comments