Listeners can now be chained

This commit is contained in:
nathan 2017-10-13 16:58:33 +02:00
parent 7237d03407
commit f8a33377d6
3 changed files with 28 additions and 14 deletions

View File

@ -713,7 +713,7 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements ICryptoConn
@SuppressWarnings("rawtypes")
@Override
public final
void add(Listener listener) {
ListenerBridge add(Listener listener) {
if (this.endPoint instanceof EndPointServer) {
// when we are a server, NORMALLY listeners are added at the GLOBAL level
// meaning --
@ -736,6 +736,8 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements ICryptoConn
this.endPoint.listeners()
.add(listener);
}
return this;
}
/**
@ -753,7 +755,7 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements ICryptoConn
@SuppressWarnings("rawtypes")
@Override
public final
void remove(Listener listener) {
ListenerBridge remove(Listener listener) {
if (this.endPoint instanceof EndPointServer) {
// when we are a server, NORMALLY listeners are added at the GLOBAL level
// meaning --
@ -778,6 +780,8 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements ICryptoConn
this.endPoint.listeners()
.remove(listener);
}
return this;
}
/**
@ -786,7 +790,7 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements ICryptoConn
*/
@Override
public final
void removeAll() {
ListenerBridge removeAll() {
if (this.endPoint instanceof EndPointServer) {
// when we are a server, NORMALLY listeners are added at the GLOBAL level
// meaning --
@ -810,6 +814,8 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements ICryptoConn
this.endPoint.listeners()
.removeAll();
}
return this;
}
/**
@ -819,7 +825,7 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements ICryptoConn
*/
@Override
public final
void removeAll(Class<?> classType) {
ListenerBridge removeAll(Class<?> classType) {
if (this.endPoint instanceof EndPointServer) {
// when we are a server, NORMALLY listeners are added at the GLOBAL level
// meaning --
@ -845,6 +851,8 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements ICryptoConn
this.endPoint.listeners()
.removeAll(classType);
}
return this;
}
@Override

View File

@ -119,7 +119,7 @@ class ConnectionManager<C extends Connection> implements ListenerBridge, ISessio
@SuppressWarnings("rawtypes")
@Override
public final
void add(final Listener listener) {
ListenerBridge add(final Listener listener) {
if (listener == null) {
throw new IllegalArgumentException("listener cannot be null.");
}
@ -143,13 +143,13 @@ class ConnectionManager<C extends Connection> implements ListenerBridge, ISessio
if (genericClass == this.baseClass || genericClass == null) {
// we are the base class, so we are fine.
addListener0(listener);
return;
return this;
}
else if (ClassHelper.hasInterface(Connection.class, genericClass) && !ClassHelper.hasParentClass(this.baseClass, genericClass)) {
// now we must make sure that the PARENT class is NOT the base class. ONLY the base class is allowed!
addListener0(listener);
return;
return this;
}
// didn't successfully add the listener.
@ -209,7 +209,7 @@ class ConnectionManager<C extends Connection> implements ListenerBridge, ISessio
@SuppressWarnings("rawtypes")
@Override
public final
void remove(final Listener listener) {
ListenerBridge remove(final Listener listener) {
if (listener == null) {
throw new IllegalArgumentException("listener cannot be null.");
}
@ -240,6 +240,8 @@ class ConnectionManager<C extends Connection> implements ListenerBridge, ISessio
listener.getClass()
.getName());
}
return this;
}
/**
@ -248,13 +250,15 @@ class ConnectionManager<C extends Connection> implements ListenerBridge, ISessio
*/
@Override
public final
void removeAll() {
ListenerBridge removeAll() {
onMessageReceivedManager.removeAll();
Logger logger2 = this.logger;
if (logger2.isTraceEnabled()) {
logger2.trace("ALL listeners removed !!");
}
return this;
}
/**
@ -264,7 +268,7 @@ class ConnectionManager<C extends Connection> implements ListenerBridge, ISessio
*/
@Override
public final
void removeAll(final Class<?> classType) {
ListenerBridge removeAll(final Class<?> classType) {
if (classType == null) {
throw new IllegalArgumentException("classType cannot be null.");
}
@ -281,6 +285,8 @@ class ConnectionManager<C extends Connection> implements ListenerBridge, ISessio
classType.getClass()
.getName());
}
return this;
}

View File

@ -38,7 +38,7 @@ interface ListenerBridge {
* the connection is notified on that event (ie, admin type listeners)
*/
@SuppressWarnings("rawtypes")
void add(Listener listener);
ListenerBridge add(Listener listener);
/**
* Removes a listener from this connection/endpoint to NO LONGER be notified
@ -53,19 +53,19 @@ interface ListenerBridge {
* the connection is removed
*/
@SuppressWarnings("rawtypes")
void remove(Listener listener);
ListenerBridge remove(Listener listener);
/**
* Removes all registered listeners from this connection/endpoint to NO
* LONGER be notified of connect/disconnect/idle/receive(object) events.
*/
void removeAll();
ListenerBridge removeAll();
/**
* Removes all registered listeners (of the object type) from this
* connection/endpoint to NO LONGER be notified of
* connect/disconnect/idle/receive(object) events.
*/
void removeAll(Class<?> classType);
ListenerBridge removeAll(Class<?> classType);
}