|
|
|
@ -54,7 +54,7 @@ import java.util.List; |
|
|
|
|
import java.util.logging.Level; |
|
|
|
|
import java.util.logging.Logger; |
|
|
|
|
|
|
|
|
|
public class Client extends ServiceManager implements MessageListener, ConnectionListener { |
|
|
|
|
public class Client extends ServiceManager { |
|
|
|
|
protected Logger log = Logger.getLogger(Client.class.getName()); |
|
|
|
|
|
|
|
|
|
protected static int clientIDCounter = 0; |
|
|
|
@ -79,6 +79,7 @@ public class Client extends ServiceManager implements MessageListener, Connectio |
|
|
|
|
|
|
|
|
|
protected boolean isConnector; |
|
|
|
|
|
|
|
|
|
protected ClientObserver listener = new ClientObserver(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Constructs this client. |
|
|
|
@ -211,10 +212,10 @@ public class Client extends ServiceManager implements MessageListener, Connectio |
|
|
|
|
|
|
|
|
|
private void registerInternalListeners() { |
|
|
|
|
if (tcp != null) { |
|
|
|
|
tcp.addConnectionListener(this); |
|
|
|
|
tcp.addConnectionListener(listener); |
|
|
|
|
tcp.socketChannel.keyFor(tcp.selector).attach(this); |
|
|
|
|
} |
|
|
|
|
addMessageListener(this, DisconnectMessage.class); |
|
|
|
|
addMessageListener(listener, DisconnectMessage.class); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -517,6 +518,23 @@ public class Client extends ServiceManager implements MessageListener, Connectio |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* {@inheritDoc} |
|
|
|
|
*/ |
|
|
|
|
public boolean equals(Object obj) { |
|
|
|
|
if (obj == null || !(obj instanceof Client || obj instanceof Integer)) { |
|
|
|
|
return false; |
|
|
|
|
} else if (obj instanceof Client){ |
|
|
|
|
return ((Client)obj).getClientID() == getClientID(); |
|
|
|
|
} else if (obj instanceof Integer) { |
|
|
|
|
return ((Integer)obj).intValue() == getClientID(); |
|
|
|
|
} else { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected class ClientObserver implements MessageListener, ConnectionListener { |
|
|
|
|
|
|
|
|
|
public void messageReceived(Message message) { |
|
|
|
|
try { |
|
|
|
|
disconnectInternal((DisconnectMessage)message); |
|
|
|
@ -567,20 +585,6 @@ public class Client extends ServiceManager implements MessageListener, Connectio |
|
|
|
|
thread = null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* {@inheritDoc} |
|
|
|
|
*/ |
|
|
|
|
public boolean equals(Object obj) { |
|
|
|
|
if (obj == null || !(obj instanceof Client || obj instanceof Integer)) { |
|
|
|
|
return false; |
|
|
|
|
} else if (obj instanceof Client){ |
|
|
|
|
return ((Client)obj).getClientID() == getClientID(); |
|
|
|
|
} else if (obj instanceof Integer) { |
|
|
|
|
return ((Integer)obj).intValue() == getClientID(); |
|
|
|
|
} else { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|