Added an 'unRegisteredType Listener' method to the ConnectionManager, for callbacks when an unrecognized/unregistered message class type is encountered

This commit is contained in:
nathan 2015-01-31 10:59:10 +01:00
parent 8c434191df
commit 55632ee386

View File

@ -21,6 +21,8 @@ import dorkbox.util.ClassHelper;
// objects that are somehow equal to each other. // objects that are somehow equal to each other.
public class ConnectionManager implements ListenerBridge, ISessionManager { public class ConnectionManager implements ListenerBridge, ISessionManager {
public static Listener<?> unRegisteredType_Listener = null;
// these are final, because the REFERENCE to these will never change. They ARE NOT immutable objects (meaning their content can change) // these are final, because the REFERENCE to these will never change. They ARE NOT immutable objects (meaning their content can change)
private final ConcurrentHashMapFactory<Type, CopyOnWriteArrayList<ListenerRaw<Connection, Object>>> listeners; private final ConcurrentHashMapFactory<Type, CopyOnWriteArrayList<ListenerRaw<Connection, Object>>> listeners;
private final ConcurrentHashMapFactory<Connection, ConnectionManager> localManagers; private final ConcurrentHashMapFactory<Connection, ConnectionManager> localManagers;
@ -264,15 +266,21 @@ public class ConnectionManager implements ListenerBridge, ISessionManager {
// only run a flush once // only run a flush once
if (foundListener) { if (foundListener) {
connection.send().flush(); connection.send().flush();
} else if (unRegisteredType_Listener != null) {
unRegisteredType_Listener.received(connection, null);
} else { } else {
Logger logger2 = this.logger; Logger logger2 = this.logger;
if (logger2.isDebugEnabled()) { if (logger2.isErrorEnabled()) {
this.logger.debug("----------- LISTENER NOT REGISTERED FOR TYPE: {}", message.getClass().getSimpleName()); this.logger.error("----------- LISTENER NOT REGISTERED FOR TYPE: {}", message.getClass().getSimpleName());
} }
} }
return foundListener; return foundListener;
} }
public static void setUnregisteredTypeListener(Listener<?> listener) {
unRegisteredType_Listener = listener;
}
/** /**
* Invoked when a Connection has been idle for a while. * Invoked when a Connection has been idle for a while.
* *