Unwinding the ouroboros... modified these public API

classes to not expose their internals by implementing
listeners directly.  Moved the listeners inside.


git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7005 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
PSp..om 14 years ago
parent e441958434
commit 212b5e243a
  1. 38
      engine/src/networking/com/jme3/network/connection/Client.java
  2. 11
      engine/src/networking/com/jme3/network/connection/Server.java

@ -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;
}
}
}

@ -56,7 +56,7 @@ import java.util.logging.Logger;
*
* @author Lars Wesselius
*/
public class Server extends ServiceManager implements MessageListener {
public class Server extends ServiceManager {
protected Logger log = Logger.getLogger(Server.class.getName());
protected static int serverIDCounter = 0;
@ -75,6 +75,8 @@ public class Server extends ServiceManager implements MessageListener {
protected ClientManager clientManager = new ClientManager();
protected MessageListener listener = new ServerMessageObserver();
/**
* Default constructor. Sets the label to
* <code>Server#[serverID]</code>
@ -171,12 +173,12 @@ public class Server extends ServiceManager implements MessageListener {
private void registerInternalListeners() {
if (tcp != null) {
tcp.addMessageListener(DisconnectMessage.class, this);
tcp.addMessageListener(DisconnectMessage.class, listener);
tcp.addMessageListener(ClientRegistrationMessage.class, clientManager);
tcp.addConnectionListener(clientManager);
}
if (udp != null) {
udp.addMessageListener(DisconnectMessage.class, this);
udp.addMessageListener(DisconnectMessage.class, listener);
udp.addMessageListener(ClientRegistrationMessage.class, clientManager);
udp.addConnectionListener(clientManager);
}
@ -423,6 +425,8 @@ public class Server extends ServiceManager implements MessageListener {
}
}
protected class ServerMessageObserver implements MessageListener {
public void messageReceived(Message message) {
// Right now, this is definitely a DisconnectMessage.
DisconnectMessage dcMessage = (DisconnectMessage)message;
@ -451,3 +455,4 @@ public class Server extends ServiceManager implements MessageListener {
}
}
}

Loading…
Cancel
Save