From d0ffd01d5e221a6ae57d772eb6bb50f2913d0061 Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 13 Oct 2017 19:38:24 +0200 Subject: [PATCH] ListenerBridge -> Listeners (plural). add/removeListener -> add/remove --- .../network/connection/Connection.java | 2 +- .../network/connection/ConnectionImpl.java | 12 ++++++------ .../network/connection/ConnectionManager.java | 10 +++++----- src/dorkbox/network/connection/EndPoint.java | 2 +- .../{ListenerBridge.java => Listeners.java} | 10 +++++----- src/dorkbox/network/connection/Ping.java | 15 ++++++--------- .../network/connection/ping/PingFuture.java | 10 +++++----- test/dorkbox/network/ListenerTest.java | 4 ++-- test/dorkbox/network/MultipleThreadTest.java | 4 ++-- test/dorkbox/network/PingPongLocalTest.java | 6 +++--- test/dorkbox/network/PingPongTest.java | 6 +++--- test/dorkbox/network/PingTest.java | 6 +++--- test/dorkbox/network/ReuseTest.java | 19 ++++++++++--------- .../network/UnregisteredClassTest.java | 4 ++-- test/dorkbox/network/rmi/RmiTest.java | 4 ++-- 15 files changed, 56 insertions(+), 58 deletions(-) rename src/dorkbox/network/connection/{ListenerBridge.java => Listeners.java} (92%) diff --git a/src/dorkbox/network/connection/Connection.java b/src/dorkbox/network/connection/Connection.java index 939b5822..fb9679db 100644 --- a/src/dorkbox/network/connection/Connection.java +++ b/src/dorkbox/network/connection/Connection.java @@ -83,7 +83,7 @@ interface Connection { /** * Expose methods to modify the connection listeners. */ - ListenerBridge listeners(); + Listeners listeners(); /** * Closes the connection diff --git a/src/dorkbox/network/connection/ConnectionImpl.java b/src/dorkbox/network/connection/ConnectionImpl.java index e9ea1d76..3586bb2b 100644 --- a/src/dorkbox/network/connection/ConnectionImpl.java +++ b/src/dorkbox/network/connection/ConnectionImpl.java @@ -66,7 +66,7 @@ import io.netty.util.concurrent.Promise; @SuppressWarnings("unused") @Sharable public -class ConnectionImpl extends ChannelInboundHandlerAdapter implements ICryptoConnection, Connection, ListenerBridge, ConnectionBridge { +class ConnectionImpl extends ChannelInboundHandlerAdapter implements ICryptoConnection, Connection, Listeners, ConnectionBridge { private final org.slf4j.Logger logger; @@ -692,7 +692,7 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements ICryptoConn */ @Override public final - ListenerBridge listeners() { + Listeners listeners() { return this; } @@ -713,7 +713,7 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements ICryptoConn @SuppressWarnings("rawtypes") @Override public final - ListenerBridge add(Listener listener) { + Listeners add(Listener listener) { if (this.endPoint instanceof EndPointServer) { // when we are a server, NORMALLY listeners are added at the GLOBAL level // meaning -- @@ -755,7 +755,7 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements ICryptoConn @SuppressWarnings("rawtypes") @Override public final - ListenerBridge remove(Listener listener) { + Listeners remove(Listener listener) { if (this.endPoint instanceof EndPointServer) { // when we are a server, NORMALLY listeners are added at the GLOBAL level // meaning -- @@ -790,7 +790,7 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements ICryptoConn */ @Override public final - ListenerBridge removeAll() { + Listeners removeAll() { if (this.endPoint instanceof EndPointServer) { // when we are a server, NORMALLY listeners are added at the GLOBAL level // meaning -- @@ -825,7 +825,7 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements ICryptoConn */ @Override public final - ListenerBridge removeAll(Class classType) { + Listeners removeAll(Class classType) { if (this.endPoint instanceof EndPointServer) { // when we are a server, NORMALLY listeners are added at the GLOBAL level // meaning -- diff --git a/src/dorkbox/network/connection/ConnectionManager.java b/src/dorkbox/network/connection/ConnectionManager.java index fcf880a3..f56f3eda 100644 --- a/src/dorkbox/network/connection/ConnectionManager.java +++ b/src/dorkbox/network/connection/ConnectionManager.java @@ -37,7 +37,7 @@ import dorkbox.util.collections.ConcurrentEntry; // .equals() compares the identity on purpose,this because we cannot create two separate objects that are somehow equal to each other. @SuppressWarnings("unchecked") public -class ConnectionManager implements ListenerBridge, ISessionManager, ConnectionPoint, ConnectionBridgeServer, +class ConnectionManager implements Listeners, ISessionManager, ConnectionPoint, ConnectionBridgeServer, ConnectionExceptSpecifiedBridgeServer { /** * Specifies the load-factor for the IdentityMap used to manage keeping track of the number of connections + listeners @@ -119,7 +119,7 @@ class ConnectionManager implements ListenerBridge, ISessio @SuppressWarnings("rawtypes") @Override public final - ListenerBridge add(final Listener listener) { + Listeners add(final Listener listener) { if (listener == null) { throw new IllegalArgumentException("listener cannot be null."); } @@ -209,7 +209,7 @@ class ConnectionManager implements ListenerBridge, ISessio @SuppressWarnings("rawtypes") @Override public final - ListenerBridge remove(final Listener listener) { + Listeners remove(final Listener listener) { if (listener == null) { throw new IllegalArgumentException("listener cannot be null."); } @@ -250,7 +250,7 @@ class ConnectionManager implements ListenerBridge, ISessio */ @Override public final - ListenerBridge removeAll() { + Listeners removeAll() { onMessageReceivedManager.removeAll(); Logger logger2 = this.logger; @@ -268,7 +268,7 @@ class ConnectionManager implements ListenerBridge, ISessio */ @Override public final - ListenerBridge removeAll(final Class classType) { + Listeners removeAll(final Class classType) { if (classType == null) { throw new IllegalArgumentException("classType cannot be null."); } diff --git a/src/dorkbox/network/connection/EndPoint.java b/src/dorkbox/network/connection/EndPoint.java index 54f4be00..7a9c6ecb 100644 --- a/src/dorkbox/network/connection/EndPoint.java +++ b/src/dorkbox/network/connection/EndPoint.java @@ -513,7 +513,7 @@ class EndPoint { * Expose methods to modify the listeners (connect/disconnect/idle/receive events). */ public final - ListenerBridge listeners() { + Listeners listeners() { return this.connectionManager; } diff --git a/src/dorkbox/network/connection/ListenerBridge.java b/src/dorkbox/network/connection/Listeners.java similarity index 92% rename from src/dorkbox/network/connection/ListenerBridge.java rename to src/dorkbox/network/connection/Listeners.java index d6f371a2..587f91ae 100644 --- a/src/dorkbox/network/connection/ListenerBridge.java +++ b/src/dorkbox/network/connection/Listeners.java @@ -22,7 +22,7 @@ package dorkbox.network.connection; * There should always be just a SINGLE connection type for the client or server */ public -interface ListenerBridge { +interface Listeners { /** * Adds a listener to this connection/endpoint to be notified of * connect/disconnect/idle/receive(object) events. @@ -38,7 +38,7 @@ interface ListenerBridge { * the connection is notified on that event (ie, admin type listeners) */ @SuppressWarnings("rawtypes") - ListenerBridge add(Listener listener); + Listeners 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") - ListenerBridge remove(Listener listener); + Listeners remove(Listener listener); /** * Removes all registered listeners from this connection/endpoint to NO * LONGER be notified of connect/disconnect/idle/receive(object) events. */ - ListenerBridge removeAll(); + Listeners 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. */ - ListenerBridge removeAll(Class classType); + Listeners removeAll(Class classType); } diff --git a/src/dorkbox/network/connection/Ping.java b/src/dorkbox/network/connection/Ping.java index f03531a2..a0c030eb 100644 --- a/src/dorkbox/network/connection/Ping.java +++ b/src/dorkbox/network/connection/Ping.java @@ -23,19 +23,16 @@ interface Ping { int getResponse(); /** - * Adds the specified listener to this future. The specified listener is - * notified when this future is done. If this future is already completed, - * the specified listener is notified immediately. + * Adds a ping listener to this future. The listener is notified when this future is done. If this future is already completed, + * then the listener is notified immediately. */ - void addListener(PingListener listener); + void add(PingListener listener); /** - * Removes the specified listener from this future. The specified listener - * is no longer notified when this future is done. If the specified listener - * is not associated with this future, this method does nothing and returns - * silently. + * Removes a ping listener from this future. The listener is no longer notified when this future is done. If the listener + * was not previously associated with this future, this method does nothing and returns silently. */ - void removeListener(PingListener listener); + void remove(PingListener listener); /** * Cancel this Ping. diff --git a/src/dorkbox/network/connection/ping/PingFuture.java b/src/dorkbox/network/connection/ping/PingFuture.java index f14a3c98..ad6ef1f6 100644 --- a/src/dorkbox/network/connection/ping/PingFuture.java +++ b/src/dorkbox/network/connection/ping/PingFuture.java @@ -15,15 +15,15 @@ */ package dorkbox.network.connection.ping; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.atomic.AtomicInteger; + import dorkbox.network.connection.Connection; import dorkbox.network.connection.Ping; import dorkbox.network.connection.PingListener; import io.netty.util.concurrent.GenericFutureListener; import io.netty.util.concurrent.Promise; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.atomic.AtomicInteger; - public class PingFuture implements Ping { @@ -78,7 +78,7 @@ class PingFuture implements Ping { @Override @SuppressWarnings({"unchecked", "rawtypes"}) public - void addListener(PingListener listener) { + void add(PingListener listener) { this.promise.addListener((GenericFutureListener) listener); } @@ -89,7 +89,7 @@ class PingFuture implements Ping { @Override @SuppressWarnings({"unchecked", "rawtypes"}) public - void removeListener(PingListener listener) { + void remove(PingListener listener) { this.promise.removeListener((GenericFutureListener) listener); } diff --git a/test/dorkbox/network/ListenerTest.java b/test/dorkbox/network/ListenerTest.java index 3c3dd6e7..4a5934e6 100644 --- a/test/dorkbox/network/ListenerTest.java +++ b/test/dorkbox/network/ListenerTest.java @@ -35,7 +35,7 @@ import dorkbox.network.connection.Connection; import dorkbox.network.connection.ConnectionImpl; import dorkbox.network.connection.EndPoint; import dorkbox.network.connection.Listener; -import dorkbox.network.connection.ListenerBridge; +import dorkbox.network.connection.Listeners; import dorkbox.network.rmi.RmiBridge; import dorkbox.util.exceptions.InitializationException; import dorkbox.util.exceptions.SecurityException; @@ -116,7 +116,7 @@ class ListenerTest extends BaseTest { addEndPoint(server); server.bind(false); - final ListenerBridge listeners = server.listeners(); + final Listeners listeners = server.listeners(); // standard listener listeners.add(new Listener.OnMessageReceived() { diff --git a/test/dorkbox/network/MultipleThreadTest.java b/test/dorkbox/network/MultipleThreadTest.java index ead4eeb2..73fb8092 100644 --- a/test/dorkbox/network/MultipleThreadTest.java +++ b/test/dorkbox/network/MultipleThreadTest.java @@ -33,7 +33,7 @@ import org.junit.Test; import dorkbox.network.connection.Connection; import dorkbox.network.connection.CryptoSerializationManager; import dorkbox.network.connection.Listener; -import dorkbox.network.connection.ListenerBridge; +import dorkbox.network.connection.Listeners; import dorkbox.util.exceptions.InitializationException; import dorkbox.util.exceptions.SecurityException; @@ -72,7 +72,7 @@ class MultipleThreadTest extends BaseTest { server.bind(false); - final ListenerBridge listeners = server.listeners(); + final Listeners listeners = server.listeners(); listeners.add(new Listener.OnConnected() { @Override diff --git a/test/dorkbox/network/PingPongLocalTest.java b/test/dorkbox/network/PingPongLocalTest.java index c87fb6f4..d6f054af 100644 --- a/test/dorkbox/network/PingPongLocalTest.java +++ b/test/dorkbox/network/PingPongLocalTest.java @@ -30,7 +30,7 @@ import org.junit.Test; import dorkbox.network.connection.Connection; import dorkbox.network.connection.CryptoSerializationManager; import dorkbox.network.connection.Listener; -import dorkbox.network.connection.ListenerBridge; +import dorkbox.network.connection.Listeners; import dorkbox.util.SerializationManager; import dorkbox.util.exceptions.InitializationException; import dorkbox.util.exceptions.SecurityException; @@ -55,7 +55,7 @@ class PingPongLocalTest extends BaseTest { Server server = new Server(configuration); addEndPoint(server); server.bind(false); - final ListenerBridge listeners = server.listeners(); + final Listeners listeners = server.listeners(); listeners.add(new Listener.OnError() { @Override public @@ -81,7 +81,7 @@ class PingPongLocalTest extends BaseTest { Client client = new Client(); addEndPoint(client); - final ListenerBridge listeners1 = client.listeners(); + final Listeners listeners1 = client.listeners(); listeners1.add(new Listener.OnConnected() { AtomicInteger check = new AtomicInteger(0); diff --git a/test/dorkbox/network/PingPongTest.java b/test/dorkbox/network/PingPongTest.java index 54a9c973..c6568d49 100644 --- a/test/dorkbox/network/PingPongTest.java +++ b/test/dorkbox/network/PingPongTest.java @@ -32,7 +32,7 @@ import dorkbox.network.connection.Connection; import dorkbox.network.connection.CryptoSerializationManager; import dorkbox.network.connection.EndPoint; import dorkbox.network.connection.Listener; -import dorkbox.network.connection.ListenerBridge; +import dorkbox.network.connection.Listeners; import dorkbox.util.SerializationManager; import dorkbox.util.exceptions.InitializationException; import dorkbox.util.exceptions.SecurityException; @@ -73,7 +73,7 @@ class PingPongTest extends BaseTest { Server server = new Server(configuration); addEndPoint(server); server.bind(false); - final ListenerBridge listeners1 = server.listeners(); + final Listeners listeners1 = server.listeners(); listeners1.add(new Listener.OnError() { @Override public @@ -113,7 +113,7 @@ class PingPongTest extends BaseTest { Client client = new Client(configuration); addEndPoint(client); - final ListenerBridge listeners = client.listeners(); + final Listeners listeners = client.listeners(); listeners.add(new Listener.OnConnected() { @Override public diff --git a/test/dorkbox/network/PingTest.java b/test/dorkbox/network/PingTest.java index a125ea8a..7887f9cc 100644 --- a/test/dorkbox/network/PingTest.java +++ b/test/dorkbox/network/PingTest.java @@ -100,7 +100,7 @@ class PingTest extends BaseTest { if (this.count++ < 10) { connection.send() .ping() - .addListener(this); + .add(this); } else { PingTest.this.response = pingResponseTime; @@ -113,7 +113,7 @@ class PingTest extends BaseTest { // doesn't matter how many times this is called. If there is a PING waiting, then it's overwritten Ping ping = client.send() .ping(); - ping.addListener(pingListener); + ping.add(pingListener); waitForThreads(); @@ -159,7 +159,7 @@ class PingTest extends BaseTest { // doesn't matter how many times this is called. If there is a PING waiting, then it's overwritten Ping ping = client.send() .ping(); - ping.addListener(pingListener); + ping.add(pingListener); waitForThreads(); if (this.response == -1) { diff --git a/test/dorkbox/network/ReuseTest.java b/test/dorkbox/network/ReuseTest.java index 3f550703..3f6ca1d6 100644 --- a/test/dorkbox/network/ReuseTest.java +++ b/test/dorkbox/network/ReuseTest.java @@ -19,17 +19,18 @@ */ package dorkbox.network; -import dorkbox.network.connection.Connection; -import dorkbox.network.connection.Listener; -import dorkbox.network.connection.ListenerBridge; -import dorkbox.util.exceptions.InitializationException; -import dorkbox.util.exceptions.SecurityException; -import org.junit.Test; +import static org.junit.Assert.assertEquals; import java.io.IOException; import java.util.concurrent.atomic.AtomicInteger; -import static org.junit.Assert.assertEquals; +import org.junit.Test; + +import dorkbox.network.connection.Connection; +import dorkbox.network.connection.Listener; +import dorkbox.network.connection.Listeners; +import dorkbox.util.exceptions.InitializationException; +import dorkbox.util.exceptions.SecurityException; public class ReuseTest extends BaseTest { @@ -49,7 +50,7 @@ class ReuseTest extends BaseTest { Server server = new Server(configuration); addEndPoint(server); - final ListenerBridge listeners = server.listeners(); + final Listeners listeners = server.listeners(); listeners.add(new Listener.OnConnected() { @Override public @@ -73,7 +74,7 @@ class ReuseTest extends BaseTest { Client client = new Client(configuration); addEndPoint(client); - final ListenerBridge listeners1 = client.listeners(); + final Listeners listeners1 = client.listeners(); listeners1.add(new Listener.OnConnected() { @Override public diff --git a/test/dorkbox/network/UnregisteredClassTest.java b/test/dorkbox/network/UnregisteredClassTest.java index 8bfc6ddb..3772de44 100644 --- a/test/dorkbox/network/UnregisteredClassTest.java +++ b/test/dorkbox/network/UnregisteredClassTest.java @@ -32,7 +32,7 @@ import dorkbox.network.connection.Connection; import dorkbox.network.connection.CryptoSerializationManager; import dorkbox.network.connection.EndPoint; import dorkbox.network.connection.Listener; -import dorkbox.network.connection.ListenerBridge; +import dorkbox.network.connection.Listeners; import dorkbox.util.exceptions.InitializationException; import dorkbox.util.exceptions.SecurityException; @@ -105,7 +105,7 @@ class UnregisteredClassTest extends BaseTest { Client client = new Client(configuration); addEndPoint(client); - final ListenerBridge listeners = client.listeners(); + final Listeners listeners = client.listeners(); listeners.add(new Listener.OnConnected() { @Override public diff --git a/test/dorkbox/network/rmi/RmiTest.java b/test/dorkbox/network/rmi/RmiTest.java index 1dd32f91..16eb3a5b 100644 --- a/test/dorkbox/network/rmi/RmiTest.java +++ b/test/dorkbox/network/rmi/RmiTest.java @@ -50,7 +50,7 @@ import dorkbox.network.Server; import dorkbox.network.connection.Connection; import dorkbox.network.connection.CryptoSerializationManager; import dorkbox.network.connection.Listener; -import dorkbox.network.connection.ListenerBridge; +import dorkbox.network.connection.Listeners; import dorkbox.util.exceptions.InitializationException; import dorkbox.util.exceptions.SecurityException; @@ -200,7 +200,7 @@ class RmiTest extends BaseTest { addEndPoint(server); server.bind(false); - final ListenerBridge listeners = server.listeners(); + final Listeners listeners = server.listeners(); listeners.add(new Listener.OnMessageReceived() { @Override public