Code polish, tweaked Listeners to support a 'default' listener to cleanup the verbosity that was necessary for default connections. Tweaked RMI test
This commit is contained in:
parent
7603b96d5e
commit
bcb49807e0
@ -22,8 +22,6 @@ import java.util.List;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import dorkbox.network.connection.Connection;
|
import dorkbox.network.connection.Connection;
|
||||||
import dorkbox.network.connection.ConnectionBridge;
|
|
||||||
import dorkbox.network.connection.ConnectionBridgeFlushAlways;
|
|
||||||
import dorkbox.network.connection.EndPointClient;
|
import dorkbox.network.connection.EndPointClient;
|
||||||
import dorkbox.network.connection.idle.IdleBridge;
|
import dorkbox.network.connection.idle.IdleBridge;
|
||||||
import dorkbox.network.connection.idle.IdleSender;
|
import dorkbox.network.connection.idle.IdleSender;
|
||||||
@ -48,8 +46,6 @@ public class Client extends EndPointClient {
|
|||||||
|
|
||||||
private volatile int connectionTimeout = 5000; // default
|
private volatile int connectionTimeout = 5000; // default
|
||||||
|
|
||||||
private volatile ConnectionBridgeFlushAlways connectionBridgeFlushAlways;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts a LOCAL <b>only</b> client, with the default local channel name and serialization scheme
|
* Starts a LOCAL <b>only</b> client, with the default local channel name and serialization scheme
|
||||||
*/
|
*/
|
||||||
@ -311,22 +307,6 @@ public class Client extends EndPointClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Expose methods to send objects to a destination.
|
|
||||||
* <p>
|
|
||||||
* This returns a bridge that will flush after EVERY send! This is because sending data can occur on the client, outside
|
|
||||||
* of the normal eventloop patterns, and it is confusing to the user to have to manually flush the channel each time.
|
|
||||||
*/
|
|
||||||
public ConnectionBridge send() {
|
|
||||||
ConnectionBridgeFlushAlways connectionBridgeFlushAlways2 = this.connectionBridgeFlushAlways;
|
|
||||||
if (connectionBridgeFlushAlways2 == null) {
|
|
||||||
this.connectionBridgeFlushAlways = new ConnectionBridgeFlushAlways(this.connectionManager.getConnection0().send());
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.connectionBridgeFlushAlways;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expose methods to send objects to a destination when the connection has become idle.
|
* Expose methods to send objects to a destination when the connection has become idle.
|
||||||
*/
|
*/
|
||||||
|
@ -3,6 +3,7 @@ package dorkbox.network.connection;
|
|||||||
|
|
||||||
import org.bouncycastle.crypto.params.ParametersWithIV;
|
import org.bouncycastle.crypto.params.ParametersWithIV;
|
||||||
|
|
||||||
|
import dorkbox.network.connection.bridge.ConnectionBridge;
|
||||||
import dorkbox.network.connection.idle.IdleBridge;
|
import dorkbox.network.connection.idle.IdleBridge;
|
||||||
import dorkbox.network.connection.idle.IdleSender;
|
import dorkbox.network.connection.idle.IdleSender;
|
||||||
|
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
package dorkbox.network.connection;
|
|
||||||
|
|
||||||
|
|
||||||
public interface ConnectionBridgeServer {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends the object all server connections over the network using TCP. (or
|
|
||||||
* via LOCAL when it's a local channel).
|
|
||||||
*/
|
|
||||||
public void TCP(Object message);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends the object all server connections over the network using UDP (or
|
|
||||||
* via LOCAL when it's a local channel).
|
|
||||||
*/
|
|
||||||
public void UDP(Object message);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends the object all server connections over the network using UDT. (or
|
|
||||||
* via LOCAL when it's a local channel).
|
|
||||||
*/
|
|
||||||
public void UDT(Object message);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exposes methods to send the object to all server connections (except the specified one)
|
|
||||||
* over the network. (or via LOCAL when it's a local channel).
|
|
||||||
*/
|
|
||||||
public ConnectionExceptSpecifiedBridgeServer except();
|
|
||||||
}
|
|
@ -19,6 +19,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
import org.bouncycastle.crypto.params.ParametersWithIV;
|
import org.bouncycastle.crypto.params.ParametersWithIV;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import dorkbox.network.connection.bridge.ConnectionBridge;
|
||||||
import dorkbox.network.connection.idle.IdleBridge;
|
import dorkbox.network.connection.idle.IdleBridge;
|
||||||
import dorkbox.network.connection.idle.IdleObjectSender;
|
import dorkbox.network.connection.idle.IdleObjectSender;
|
||||||
import dorkbox.network.connection.idle.IdleSender;
|
import dorkbox.network.connection.idle.IdleSender;
|
||||||
@ -245,7 +246,7 @@ public class ConnectionImpl extends ChannelInboundHandlerAdapter
|
|||||||
if (logger2.isTraceEnabled()) {
|
if (logger2.isTraceEnabled()) {
|
||||||
logger2.trace("Sending TCP {}", message);
|
logger2.trace("Sending TCP {}", message);
|
||||||
}
|
}
|
||||||
ConnectionPoint tcp = this.channelWrapper.tcp();
|
ConnectionPointWriter tcp = this.channelWrapper.tcp();
|
||||||
tcp.write(message);
|
tcp.write(message);
|
||||||
return tcp;
|
return tcp;
|
||||||
} else {
|
} else {
|
||||||
@ -268,7 +269,7 @@ public class ConnectionImpl extends ChannelInboundHandlerAdapter
|
|||||||
if (logger2.isTraceEnabled()) {
|
if (logger2.isTraceEnabled()) {
|
||||||
logger2.trace("Sending UDP {}", message);
|
logger2.trace("Sending UDP {}", message);
|
||||||
}
|
}
|
||||||
ConnectionPoint udp = this.channelWrapper.udp();
|
ConnectionPointWriter udp = this.channelWrapper.udp();
|
||||||
udp.write(message);
|
udp.write(message);
|
||||||
return udp;
|
return udp;
|
||||||
} else {
|
} else {
|
||||||
@ -290,7 +291,7 @@ public class ConnectionImpl extends ChannelInboundHandlerAdapter
|
|||||||
if (logger2.isTraceEnabled()) {
|
if (logger2.isTraceEnabled()) {
|
||||||
logger2.trace("Sending UDT {}", message);
|
logger2.trace("Sending UDT {}", message);
|
||||||
}
|
}
|
||||||
ConnectionPoint udt = this.channelWrapper.udt();
|
ConnectionPointWriter udt = this.channelWrapper.udt();
|
||||||
udt.write(message);
|
udt.write(message);
|
||||||
return udt;
|
return udt;
|
||||||
} else {
|
} else {
|
||||||
@ -513,7 +514,7 @@ public class ConnectionImpl extends ChannelInboundHandlerAdapter
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@Override
|
@Override
|
||||||
public final void add(Listener listener) {
|
public final void add(ListenerRaw listener) {
|
||||||
if (this.endPoint instanceof EndPointServer) {
|
if (this.endPoint instanceof EndPointServer) {
|
||||||
// when we are a server, NORMALLY listeners are added at the GLOBAL level
|
// when we are a server, NORMALLY listeners are added at the GLOBAL level
|
||||||
// meaning --
|
// meaning --
|
||||||
@ -550,7 +551,7 @@ public class ConnectionImpl extends ChannelInboundHandlerAdapter
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@Override
|
@Override
|
||||||
public final void remove(Listener listener) {
|
public final void remove(ListenerRaw listener) {
|
||||||
if (this.endPoint instanceof EndPointServer) {
|
if (this.endPoint instanceof EndPointServer) {
|
||||||
// when we are a server, NORMALLY listeners are added at the GLOBAL level
|
// when we are a server, NORMALLY listeners are added at the GLOBAL level
|
||||||
// meaning --
|
// meaning --
|
||||||
|
@ -21,7 +21,7 @@ import dorkbox.util.ClassHelper;
|
|||||||
public class ConnectionManager implements ListenerBridge, ISessionManager {
|
public class ConnectionManager implements ListenerBridge, ISessionManager {
|
||||||
|
|
||||||
// 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<Listener<Connection, Object>>> listeners;
|
private final ConcurrentHashMapFactory<Type, CopyOnWriteArrayList<ListenerRaw<Connection, Object>>> listeners;
|
||||||
private final ConcurrentHashMapFactory<Connection, ConnectionManager> localManagers;
|
private final ConcurrentHashMapFactory<Connection, ConnectionManager> localManagers;
|
||||||
private final CopyOnWriteArrayList<Connection> connections = new CopyOnWriteArrayList<Connection>();
|
private final CopyOnWriteArrayList<Connection> connections = new CopyOnWriteArrayList<Connection>();
|
||||||
|
|
||||||
@ -37,12 +37,12 @@ public class ConnectionManager implements ListenerBridge, ISessionManager {
|
|||||||
|
|
||||||
this.baseClass = baseClass;
|
this.baseClass = baseClass;
|
||||||
|
|
||||||
this.listeners = new ConcurrentHashMapFactory<Type, CopyOnWriteArrayList<Listener<Connection, Object>>>() {
|
this.listeners = new ConcurrentHashMapFactory<Type, CopyOnWriteArrayList<ListenerRaw<Connection, Object>>>() {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CopyOnWriteArrayList<Listener<Connection, Object>> createNewOject(Object... args) {
|
public CopyOnWriteArrayList<ListenerRaw<Connection, Object>> createNewOject(Object... args) {
|
||||||
return new CopyOnWriteArrayList<Listener<Connection, Object>>();
|
return new CopyOnWriteArrayList<ListenerRaw<Connection, Object>>();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -72,14 +72,14 @@ public class ConnectionManager implements ListenerBridge, ISessionManager {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@Override
|
@Override
|
||||||
public final void add(Listener listener) {
|
public final void add(ListenerRaw listener) {
|
||||||
if (listener == null) {
|
if (listener == null) {
|
||||||
throw new IllegalArgumentException("listener cannot be null.");
|
throw new IllegalArgumentException("listener cannot be null.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// find the class that uses Listener.class.
|
// find the class that uses Listener.class.
|
||||||
Class<?> clazz = listener.getClass();
|
Class<?> clazz = listener.getClass();
|
||||||
while (clazz.getSuperclass() != Listener.class) {
|
while (clazz.getSuperclass() != ListenerRaw.class) {
|
||||||
clazz = clazz.getSuperclass();
|
clazz = clazz.getSuperclass();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,17 +101,17 @@ public class ConnectionManager implements ListenerBridge, ISessionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// didn't successfully add the listener.
|
// didn't successfully add the listener.
|
||||||
throw new RuntimeException("Unable to add incompatible connection types as a listener!");
|
throw new IllegalArgumentException("Unable to add incompatible connection type as a listener! : " + this.baseClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* INTERNAL USE ONLY
|
* INTERNAL USE ONLY
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"unchecked","rawtypes"})
|
@SuppressWarnings({"unchecked","rawtypes"})
|
||||||
private final void addListener0(Listener listener) {
|
private final void addListener0(ListenerRaw listener) {
|
||||||
Class<?> type = listener.getObjectType();
|
Class<?> type = listener.getObjectType();
|
||||||
|
|
||||||
CopyOnWriteArrayList<Listener<Connection, Object>> list = this.listeners.getOrCreate(type);
|
CopyOnWriteArrayList<ListenerRaw<Connection, Object>> list = this.listeners.getOrCreate(type);
|
||||||
list.addIfAbsent(listener);
|
list.addIfAbsent(listener);
|
||||||
|
|
||||||
Logger logger2 = this.logger;
|
Logger logger2 = this.logger;
|
||||||
@ -134,14 +134,14 @@ public class ConnectionManager implements ListenerBridge, ISessionManager {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@Override
|
@Override
|
||||||
public final void remove(Listener listener) {
|
public final void remove(ListenerRaw listener) {
|
||||||
if (listener == null) {
|
if (listener == null) {
|
||||||
throw new IllegalArgumentException("listener cannot be null.");
|
throw new IllegalArgumentException("listener cannot be null.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Class<?> type = listener.getObjectType();
|
Class<?> type = listener.getObjectType();
|
||||||
|
|
||||||
CopyOnWriteArrayList<Listener<Connection, Object>> list = this.listeners.get(type);
|
CopyOnWriteArrayList<ListenerRaw<Connection, Object>> list = this.listeners.get(type);
|
||||||
if (list != null) {
|
if (list != null) {
|
||||||
list.remove(listener);
|
list.remove(listener);
|
||||||
}
|
}
|
||||||
@ -196,18 +196,18 @@ public class ConnectionManager implements ListenerBridge, ISessionManager {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final void notifyOnMessage(Connection connection, Object message) {
|
public final void notifyOnMessage(Connection connection, Object message) {
|
||||||
notifyOnMessage(connection, message, false);
|
notifyOnMessage0(connection, message, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void notifyOnMessage(Connection connection, Object message, boolean foundListener) {
|
private final boolean notifyOnMessage0(Connection connection, Object message, boolean foundListener) {
|
||||||
Class<?> objectType = message.getClass();
|
Class<?> objectType = message.getClass();
|
||||||
|
|
||||||
// this is the GLOBAL version (unless it's the call from below, then it's the connection scoped version)
|
// this is the GLOBAL version (unless it's the call from below, then it's the connection scoped version)
|
||||||
CopyOnWriteArrayList<Listener<Connection, Object>> list = this.listeners.get(objectType);
|
CopyOnWriteArrayList<ListenerRaw<Connection, Object>> list = this.listeners.get(objectType);
|
||||||
if (list != null) {
|
if (list != null) {
|
||||||
for (Listener<Connection, Object> listener : list) {
|
for (ListenerRaw<Connection, Object> listener : list) {
|
||||||
if (this.shutdown) {
|
if (this.shutdown) {
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
listener.received(connection, message);
|
listener.received(connection, message);
|
||||||
@ -239,26 +239,17 @@ public class ConnectionManager implements ListenerBridge, ISessionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (list != null) {
|
if (list != null) {
|
||||||
for (Listener<Connection, Object> listener : list) {
|
for (ListenerRaw<Connection, Object> listener : list) {
|
||||||
if (this.shutdown) {
|
if (this.shutdown) {
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
listener.received(connection, message);
|
listener.received(connection, message);
|
||||||
foundListener = true;
|
foundListener = true;
|
||||||
}
|
}
|
||||||
} else if (!foundListener) {
|
|
||||||
Logger logger2 = this.logger;
|
|
||||||
if (logger2.isDebugEnabled()) {
|
|
||||||
this.logger.debug("----------- LISTENER NOT REGISTERED FOR TYPE: {}", message.getClass().getSimpleName());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// only run a flush once
|
|
||||||
if (foundListener) {
|
|
||||||
connection.send().flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
// now have to account for additional connection listener managers (non-global).
|
// now have to account for additional connection listener managers (non-global).
|
||||||
ConnectionManager localManager = this.localManagers.get(connection);
|
ConnectionManager localManager = this.localManagers.get(connection);
|
||||||
@ -266,8 +257,19 @@ public class ConnectionManager implements ListenerBridge, ISessionManager {
|
|||||||
// if we found a listener during THIS method call, we need to let the NEXT method call know,
|
// if we found a listener during THIS method call, we need to let the NEXT method call know,
|
||||||
// so it doesn't spit out error for not handling a message (since that message MIGHT have
|
// so it doesn't spit out error for not handling a message (since that message MIGHT have
|
||||||
// been found in this method).
|
// been found in this method).
|
||||||
localManager.notifyOnMessage(connection, message, foundListener);
|
foundListener |= localManager.notifyOnMessage0(connection, message, foundListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// only run a flush once
|
||||||
|
if (foundListener) {
|
||||||
|
connection.send().flush();
|
||||||
|
} else {
|
||||||
|
Logger logger2 = this.logger;
|
||||||
|
if (logger2.isDebugEnabled()) {
|
||||||
|
this.logger.debug("----------- LISTENER NOT REGISTERED FOR TYPE: {}", message.getClass().getSimpleName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return foundListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -277,12 +279,12 @@ public class ConnectionManager implements ListenerBridge, ISessionManager {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final void notifyOnIdle(Connection connection) {
|
public final void notifyOnIdle(Connection connection) {
|
||||||
Set<Entry<Type, CopyOnWriteArrayList<Listener<Connection, Object>>>> entrySet = this.listeners.entrySet();
|
Set<Entry<Type, CopyOnWriteArrayList<ListenerRaw<Connection, Object>>>> entrySet = this.listeners.entrySet();
|
||||||
CopyOnWriteArrayList<Listener<Connection,Object>> list;
|
CopyOnWriteArrayList<ListenerRaw<Connection,Object>> list;
|
||||||
for (Entry<Type, CopyOnWriteArrayList<Listener<Connection, Object>>> entry : entrySet) {
|
for (Entry<Type, CopyOnWriteArrayList<ListenerRaw<Connection, Object>>> entry : entrySet) {
|
||||||
list = entry.getValue();
|
list = entry.getValue();
|
||||||
if (list != null) {
|
if (list != null) {
|
||||||
for (Listener<Connection,Object> listener : list) {
|
for (ListenerRaw<Connection,Object> listener : list) {
|
||||||
if (this.shutdown) {
|
if (this.shutdown) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -311,12 +313,12 @@ public class ConnectionManager implements ListenerBridge, ISessionManager {
|
|||||||
this.connections.add(connection);
|
this.connections.add(connection);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Set<Entry<Type, CopyOnWriteArrayList<Listener<Connection, Object>>>> entrySet = this.listeners.entrySet();
|
Set<Entry<Type, CopyOnWriteArrayList<ListenerRaw<Connection, Object>>>> entrySet = this.listeners.entrySet();
|
||||||
CopyOnWriteArrayList<Listener<Connection,Object>> list;
|
CopyOnWriteArrayList<ListenerRaw<Connection,Object>> list;
|
||||||
for (Entry<Type, CopyOnWriteArrayList<Listener<Connection, Object>>> entry : entrySet) {
|
for (Entry<Type, CopyOnWriteArrayList<ListenerRaw<Connection, Object>>> entry : entrySet) {
|
||||||
list = entry.getValue();
|
list = entry.getValue();
|
||||||
if (list != null) {
|
if (list != null) {
|
||||||
for (Listener<Connection,Object> listener : list) {
|
for (ListenerRaw<Connection,Object> listener : list) {
|
||||||
if (this.shutdown) {
|
if (this.shutdown) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -343,12 +345,12 @@ public class ConnectionManager implements ListenerBridge, ISessionManager {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void connectionDisconnected(Connection connection) {
|
public void connectionDisconnected(Connection connection) {
|
||||||
Set<Entry<Type, CopyOnWriteArrayList<Listener<Connection, Object>>>> entrySet = this.listeners.entrySet();
|
Set<Entry<Type, CopyOnWriteArrayList<ListenerRaw<Connection, Object>>>> entrySet = this.listeners.entrySet();
|
||||||
CopyOnWriteArrayList<Listener<Connection,Object>> list;
|
CopyOnWriteArrayList<ListenerRaw<Connection,Object>> list;
|
||||||
for (Entry<Type, CopyOnWriteArrayList<Listener<Connection, Object>>> entry : entrySet) {
|
for (Entry<Type, CopyOnWriteArrayList<ListenerRaw<Connection, Object>>> entry : entrySet) {
|
||||||
list = entry.getValue();
|
list = entry.getValue();
|
||||||
if (list != null) {
|
if (list != null) {
|
||||||
for (Listener<Connection, Object> listener : list) {
|
for (ListenerRaw<Connection, Object> listener : list) {
|
||||||
if (this.shutdown) {
|
if (this.shutdown) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -378,12 +380,12 @@ public class ConnectionManager implements ListenerBridge, ISessionManager {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void connectionError(Connection connection, Throwable throwable) {
|
public void connectionError(Connection connection, Throwable throwable) {
|
||||||
Set<Entry<Type, CopyOnWriteArrayList<Listener<Connection, Object>>>> entrySet = this.listeners.entrySet();
|
Set<Entry<Type, CopyOnWriteArrayList<ListenerRaw<Connection, Object>>>> entrySet = this.listeners.entrySet();
|
||||||
CopyOnWriteArrayList<Listener<Connection,Object>> list;
|
CopyOnWriteArrayList<ListenerRaw<Connection,Object>> list;
|
||||||
for (Entry<Type, CopyOnWriteArrayList<Listener<Connection, Object>>> entry : entrySet) {
|
for (Entry<Type, CopyOnWriteArrayList<ListenerRaw<Connection, Object>>> entry : entrySet) {
|
||||||
list = entry.getValue();
|
list = entry.getValue();
|
||||||
if (list != null) {
|
if (list != null) {
|
||||||
for (Listener<Connection, Object> listener : list) {
|
for (ListenerRaw<Connection, Object> listener : list) {
|
||||||
if (this.shutdown) {
|
if (this.shutdown) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,6 @@ package dorkbox.network.connection;
|
|||||||
|
|
||||||
public interface ConnectionPoint {
|
public interface ConnectionPoint {
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes data to the pipe. <b>DOES NOT FLUSH</b> the pipe to the wire!
|
|
||||||
*/
|
|
||||||
public void write(Object object);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Waits for the last write to complete. Useful when sending large amounts of data at once.
|
* Waits for the last write to complete. Useful when sending large amounts of data at once.
|
||||||
*/
|
*/
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
package dorkbox.network.connection;
|
||||||
|
|
||||||
|
public interface ConnectionPointWriter extends ConnectionPoint {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes data to the pipe. <b>DOES NOT FLUSH</b> the pipe to the wire!
|
||||||
|
*/
|
||||||
|
public void write(Object object);
|
||||||
|
}
|
@ -3,6 +3,8 @@ package dorkbox.network.connection;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import dorkbox.network.ConnectionOptions;
|
import dorkbox.network.ConnectionOptions;
|
||||||
|
import dorkbox.network.connection.bridge.ConnectionBridge;
|
||||||
|
import dorkbox.network.connection.bridge.ConnectionBridgeFlushAlways;
|
||||||
import dorkbox.network.util.exceptions.InitializationException;
|
import dorkbox.network.util.exceptions.InitializationException;
|
||||||
import dorkbox.network.util.exceptions.SecurityException;
|
import dorkbox.network.util.exceptions.SecurityException;
|
||||||
|
|
||||||
@ -16,6 +18,9 @@ public class EndPointClient extends EndPointWithSerialization {
|
|||||||
|
|
||||||
protected volatile boolean registrationComplete = false;
|
protected volatile boolean registrationComplete = false;
|
||||||
|
|
||||||
|
private volatile ConnectionBridgeFlushAlways connectionBridgeFlushAlways;
|
||||||
|
|
||||||
|
|
||||||
public EndPointClient(String name, ConnectionOptions options) throws InitializationException, SecurityException {
|
public EndPointClient(String name, ConnectionOptions options) throws InitializationException, SecurityException {
|
||||||
super(name, options);
|
super(name, options);
|
||||||
}
|
}
|
||||||
@ -68,4 +73,21 @@ public class EndPointClient extends EndPointWithSerialization {
|
|||||||
this.registrationInProgress = false;
|
this.registrationInProgress = false;
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expose methods to send objects to a destination.
|
||||||
|
* <p>
|
||||||
|
* This returns a bridge that will flush after EVERY send! This is because sending data can occur on the client, outside
|
||||||
|
* of the normal eventloop patterns, and it is confusing to the user to have to manually flush the channel each time.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ConnectionBridge send() {
|
||||||
|
ConnectionBridgeFlushAlways connectionBridgeFlushAlways2 = this.connectionBridgeFlushAlways;
|
||||||
|
if (connectionBridgeFlushAlways2 == null) {
|
||||||
|
ConnectionBridge clientBridge = this.connectionManager.getConnection0().send();
|
||||||
|
this.connectionBridgeFlushAlways = new ConnectionBridgeFlushAlways(clientBridge);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.connectionBridgeFlushAlways;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package dorkbox.network.connection;
|
package dorkbox.network.connection;
|
||||||
|
|
||||||
import dorkbox.network.ConnectionOptions;
|
import dorkbox.network.ConnectionOptions;
|
||||||
|
import dorkbox.network.connection.bridge.ConnectionBridgeServer;
|
||||||
import dorkbox.network.util.exceptions.InitializationException;
|
import dorkbox.network.util.exceptions.InitializationException;
|
||||||
import dorkbox.network.util.exceptions.SecurityException;
|
import dorkbox.network.util.exceptions.SecurityException;
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ import org.bouncycastle.crypto.params.IESWithCipherParameters;
|
|||||||
import com.esotericsoftware.kryo.factories.SerializerFactory;
|
import com.esotericsoftware.kryo.factories.SerializerFactory;
|
||||||
|
|
||||||
import dorkbox.network.ConnectionOptions;
|
import dorkbox.network.ConnectionOptions;
|
||||||
|
import dorkbox.network.connection.bridge.ConnectionBridgeBase;
|
||||||
import dorkbox.network.connection.registration.MetaChannel;
|
import dorkbox.network.connection.registration.MetaChannel;
|
||||||
import dorkbox.network.connection.registration.Registration;
|
import dorkbox.network.connection.registration.Registration;
|
||||||
import dorkbox.network.connection.wrapper.ChannelLocalWrapper;
|
import dorkbox.network.connection.wrapper.ChannelLocalWrapper;
|
||||||
@ -33,7 +34,7 @@ import dorkbox.util.crypto.serialization.EccPublicKeySerializer;
|
|||||||
import dorkbox.util.crypto.serialization.IesParametersSerializer;
|
import dorkbox.util.crypto.serialization.IesParametersSerializer;
|
||||||
import dorkbox.util.crypto.serialization.IesWithCipherParametersSerializer;
|
import dorkbox.util.crypto.serialization.IesWithCipherParametersSerializer;
|
||||||
|
|
||||||
public class EndPointWithSerialization extends EndPoint {
|
public abstract class EndPointWithSerialization extends EndPoint {
|
||||||
|
|
||||||
protected final ConnectionManager connectionManager;
|
protected final ConnectionManager connectionManager;
|
||||||
|
|
||||||
@ -219,6 +220,12 @@ public class EndPointWithSerialization extends EndPoint {
|
|||||||
return (Collection<C>) this.connectionManager.getConnections();
|
return (Collection<C>) this.connectionManager.getConnections();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expose methods to send objects to a destination.
|
||||||
|
*/
|
||||||
|
public abstract ConnectionBridgeBase send();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes all connections ONLY (keeps the server/client running)
|
* Closes all connections ONLY (keeps the server/client running)
|
||||||
*/
|
*/
|
||||||
|
@ -1,98 +1,10 @@
|
|||||||
package dorkbox.network.connection;
|
package dorkbox.network.connection;
|
||||||
|
|
||||||
import dorkbox.util.ClassHelper;
|
|
||||||
|
|
||||||
public abstract class Listener<C extends Connection, M extends Object> {
|
|
||||||
|
|
||||||
private final Class<?> objectType;
|
|
||||||
|
|
||||||
// for compile time code. The generic type parameter #2 (index 1) is pulled from type arguments.
|
public abstract class Listener<M extends Object> extends ListenerRaw<Connection, M> {
|
||||||
// generic parameters cannot be primitive types
|
|
||||||
public Listener() {
|
public Listener() {
|
||||||
this(1);
|
super(0);
|
||||||
}
|
|
||||||
|
|
||||||
// for sub-classed listeners, we might have to specify which parameter to use.
|
|
||||||
protected Listener(int lastParameterIndex) {
|
|
||||||
if (lastParameterIndex > -1) {
|
|
||||||
Class<?> objectType = ClassHelper.getGenericParameterAsClassForSuperClass(getClass(), lastParameterIndex);
|
|
||||||
|
|
||||||
if (objectType != null) {
|
|
||||||
this.objectType = objectType;
|
|
||||||
} else {
|
|
||||||
this.objectType = Object.class;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// for when we want to override it
|
|
||||||
this.objectType = Object.class;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the referenced object type.
|
|
||||||
*
|
|
||||||
* non-final so this can be overridden by listeners that aren't able to define their type as a generic parameter
|
|
||||||
*/
|
|
||||||
public Class<?> getObjectType() {
|
|
||||||
return this.objectType;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the remote end has been connected. This will be invoked before any objects are received by the network.
|
|
||||||
* This method should not block for long periods as other network activity will not be processed
|
|
||||||
* until it returns.
|
|
||||||
*/
|
|
||||||
public void connected(C connection) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the remote end is no longer connected. There is no guarantee as to what thread will invoke this method.
|
|
||||||
* <p>
|
|
||||||
* Do not write data in this method! The channel can be closed, resulting in an error if you attempt to do so.
|
|
||||||
*/
|
|
||||||
public void disconnected(C connection) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when an object has been received from the remote end of the connection.
|
|
||||||
* This method should not block for long periods as other network activity will not be processed until it returns.
|
|
||||||
*/
|
|
||||||
public void received(C connection, M message) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the connection is idle for longer than the {@link EndPoint#setIdleTimeout(idle) idle threshold}.
|
|
||||||
*/
|
|
||||||
public void idle(C connection) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when there is an error of some kind during the up/down stream process (to/from the socket or otherwise)
|
|
||||||
*/
|
|
||||||
public void error(C connection, Throwable throwable) {
|
|
||||||
throwable.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
final int prime = 31;
|
|
||||||
int result = 1;
|
|
||||||
result = prime * result + (this.objectType == null ? 0 : this.objectType.hashCode());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// only possible way for it to be equal, is if it is the same object
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Listener [type=" + getObjectType() + "]";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ public interface ListenerBridge {
|
|||||||
* the connection is notified on that event (ie, admin type listeners)
|
* the connection is notified on that event (ie, admin type listeners)
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public void add(Listener listener);
|
public void add(ListenerRaw listener);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a listener from this connection/endpoint to NO LONGER be notified
|
* Removes a listener from this connection/endpoint to NO LONGER be notified
|
||||||
@ -37,7 +37,7 @@ public interface ListenerBridge {
|
|||||||
* the connection is removed
|
* the connection is removed
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public void remove(Listener listener);
|
public void remove(ListenerRaw listener);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all registered listeners from this connection/endpoint to NO
|
* Removes all registered listeners from this connection/endpoint to NO
|
||||||
|
103
Dorkbox-Network/src/dorkbox/network/connection/ListenerRaw.java
Normal file
103
Dorkbox-Network/src/dorkbox/network/connection/ListenerRaw.java
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
package dorkbox.network.connection;
|
||||||
|
|
||||||
|
import dorkbox.util.ClassHelper;
|
||||||
|
|
||||||
|
public abstract class ListenerRaw<C extends Connection, M extends Object> {
|
||||||
|
|
||||||
|
private final Class<?> objectType;
|
||||||
|
|
||||||
|
// for compile time code. The generic type parameter #2 (index 1) is pulled from type arguments.
|
||||||
|
// generic parameters cannot be primitive types
|
||||||
|
public ListenerRaw() {
|
||||||
|
this(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// for sub-classed listeners, we might have to specify which parameter to use.
|
||||||
|
protected ListenerRaw(int lastParameterIndex) {
|
||||||
|
if (lastParameterIndex > -1) {
|
||||||
|
Class<?> objectType = ClassHelper.getGenericParameterAsClassForSuperClass(getClass(), lastParameterIndex);
|
||||||
|
|
||||||
|
if (objectType != null) {
|
||||||
|
// SOMETIMES generics get confused on which parameter we actually mean (when sub-classing)
|
||||||
|
if (objectType.isAssignableFrom(Connection.class)) {
|
||||||
|
objectType = ClassHelper.getGenericParameterAsClassForSuperClass(getClass(), lastParameterIndex+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.objectType = objectType;
|
||||||
|
} else {
|
||||||
|
this.objectType = Object.class;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// for when we want to override it
|
||||||
|
this.objectType = Object.class;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the referenced object type.
|
||||||
|
*
|
||||||
|
* non-final so this can be overridden by listeners that aren't able to define their type as a generic parameter
|
||||||
|
*/
|
||||||
|
public Class<?> getObjectType() {
|
||||||
|
return this.objectType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the remote end has been connected. This will be invoked before any objects are received by the network.
|
||||||
|
* This method should not block for long periods as other network activity will not be processed
|
||||||
|
* until it returns.
|
||||||
|
*/
|
||||||
|
public void connected(C connection) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the remote end is no longer connected. There is no guarantee as to what thread will invoke this method.
|
||||||
|
* <p>
|
||||||
|
* Do not write data in this method! The channel can be closed, resulting in an error if you attempt to do so.
|
||||||
|
*/
|
||||||
|
public void disconnected(C connection) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when an object has been received from the remote end of the connection.
|
||||||
|
* This method should not block for long periods as other network activity will not be processed until it returns.
|
||||||
|
*/
|
||||||
|
public void received(C connection, M message) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the connection is idle for longer than the {@link EndPoint#setIdleTimeout(idle) idle threshold}.
|
||||||
|
*/
|
||||||
|
public void idle(C connection) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when there is an error of some kind during the up/down stream process (to/from the socket or otherwise)
|
||||||
|
*/
|
||||||
|
public void error(C connection, Throwable throwable) {
|
||||||
|
throwable.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + (this.objectType == null ? 0 : this.objectType.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// only possible way for it to be equal, is if it is the same object
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Listener [type=" + getObjectType() + "]";
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package dorkbox.network.connection;
|
package dorkbox.network.connection;
|
||||||
|
|
||||||
|
|
||||||
class PingSystemListener extends Listener<ConnectionImpl, PingMessage> {
|
class PingSystemListener extends ListenerRaw<ConnectionImpl, PingMessage> {
|
||||||
|
|
||||||
PingSystemListener(String name) {
|
PingSystemListener(String name) {
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ public class RegistrationWrapper implements UdpServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void releaseChannelMap() {
|
public void releaseChannelMap() {
|
||||||
// try to unlocal access
|
// try to unlock access
|
||||||
this.channelMapLock.unlock();
|
this.channelMapLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,11 @@ package dorkbox.network.connection;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
public class ServerConnectionBridge implements ConnectionBridgeServer, ConnectionExceptSpecifiedBridgeServer {
|
import dorkbox.network.connection.bridge.ConnectionBridgeServer;
|
||||||
|
import dorkbox.network.connection.bridge.ConnectionExceptSpecifiedBridgeServer;
|
||||||
|
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||||
|
|
||||||
|
public class ServerConnectionBridge implements ConnectionPoint, ConnectionBridgeServer, ConnectionExceptSpecifiedBridgeServer {
|
||||||
|
|
||||||
private final ConnectionManager connectionManager;
|
private final ConnectionManager connectionManager;
|
||||||
|
|
||||||
@ -15,11 +19,13 @@ public class ServerConnectionBridge implements ConnectionBridgeServer, Connectio
|
|||||||
* via LOCAL when it's a local channel).
|
* via LOCAL when it's a local channel).
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void TCP(Object message) {
|
public ConnectionPoint TCP(Object message) {
|
||||||
Collection<Connection> connections0 = connectionManager.getConnections0();
|
Collection<Connection> connections0 = this.connectionManager.getConnections0();
|
||||||
for (Connection c : connections0) {
|
for (Connection c : connections0) {
|
||||||
c.send().TCP(message);
|
c.send().TCP(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,11 +33,13 @@ public class ServerConnectionBridge implements ConnectionBridgeServer, Connectio
|
|||||||
* via LOCAL when it's a local channel).
|
* via LOCAL when it's a local channel).
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void UDP(Object message) {
|
public ConnectionPoint UDP(Object message) {
|
||||||
Collection<Connection> connections0 = connectionManager.getConnections0();
|
Collection<Connection> connections0 = this.connectionManager.getConnections0();
|
||||||
for (Connection c : connections0) {
|
for (Connection c : connections0) {
|
||||||
c.send().UDP(message);
|
c.send().UDP(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,13 +47,39 @@ public class ServerConnectionBridge implements ConnectionBridgeServer, Connectio
|
|||||||
* via LOCAL when it's a local channel).
|
* via LOCAL when it's a local channel).
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void UDT(Object message) {
|
public ConnectionPoint UDT(Object message) {
|
||||||
Collection<Connection> connections0 = connectionManager.getConnections0();
|
Collection<Connection> connections0 = this.connectionManager.getConnections0();
|
||||||
for (Connection c : connections0) {
|
for (Connection c : connections0) {
|
||||||
c.send().UDT(message);
|
c.send().UDT(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Not implemented, since this would cause horrendous problems.
|
||||||
|
*
|
||||||
|
* @see dorkbox.network.connection.ConnectionPoint#waitForWriteToComplete()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void waitForWriteToComplete() {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will flush the data from EVERY connection on this server.
|
||||||
|
* <p>
|
||||||
|
* THIS WILL BE SLOW!
|
||||||
|
*
|
||||||
|
* @see dorkbox.network.connection.ConnectionPoint#flush()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void flush() {
|
||||||
|
Collection<Connection> connections0 = this.connectionManager.getConnections0();
|
||||||
|
for (Connection c : connections0) {
|
||||||
|
c.send().flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exposes methods to send the object to all server connections (except the specified one)
|
* Exposes methods to send the object to all server connections (except the specified one)
|
||||||
@ -62,7 +96,7 @@ public class ServerConnectionBridge implements ConnectionBridgeServer, Connectio
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void TCP(Connection connection, Object message) {
|
public void TCP(Connection connection, Object message) {
|
||||||
Collection<Connection> connections0 = connectionManager.getConnections0();
|
Collection<Connection> connections0 = this.connectionManager.getConnections0();
|
||||||
for (Connection c : connections0) {
|
for (Connection c : connections0) {
|
||||||
if (c != connection) {
|
if (c != connection) {
|
||||||
c.send().TCP(message);
|
c.send().TCP(message);
|
||||||
@ -76,7 +110,7 @@ public class ServerConnectionBridge implements ConnectionBridgeServer, Connectio
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void UDP(Connection connection, Object message) {
|
public void UDP(Connection connection, Object message) {
|
||||||
Collection<Connection> connections0 = connectionManager.getConnections0();
|
Collection<Connection> connections0 = this.connectionManager.getConnections0();
|
||||||
for (Connection c : connections0) {
|
for (Connection c : connections0) {
|
||||||
if (c != connection) {
|
if (c != connection) {
|
||||||
c.send().UDP(message);
|
c.send().UDP(message);
|
||||||
@ -90,11 +124,23 @@ public class ServerConnectionBridge implements ConnectionBridgeServer, Connectio
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void UDT(Connection connection, Object message) {
|
public void UDT(Connection connection, Object message) {
|
||||||
Collection<Connection> connections0 = connectionManager.getConnections0();
|
Collection<Connection> connections0 = this.connectionManager.getConnections0();
|
||||||
for (Connection c : connections0) {
|
for (Connection c : connections0) {
|
||||||
if (c != connection) {
|
if (c != connection) {
|
||||||
c.send().UDT(message);
|
c.send().UDT(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends the message to other listeners INSIDE this endpoint for EVERY connection. It does not
|
||||||
|
* send it to a remote address.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void self(Object message) {
|
||||||
|
Collection<Connection> connections0 = this.connectionManager.getConnections0();
|
||||||
|
for (Connection c : connections0) {
|
||||||
|
this.connectionManager.notifyOnMessage(c, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
package dorkbox.network.connection.bridge;
|
||||||
|
|
||||||
|
import dorkbox.network.connection.Ping;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public interface ConnectionBridge extends ConnectionBridgeBase {
|
||||||
|
/**
|
||||||
|
* Sends a "ping" packet, trying UDP, then UDT, then TCP (in that order) to measure <b>ROUND TRIP</b> time to the remote connection.
|
||||||
|
*
|
||||||
|
* @return Ping can have a listener attached, which will get called when the ping returns.
|
||||||
|
*/
|
||||||
|
public Ping ping();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flushes the contents of the TCP/UDP/UDT/etc pipes to the actual transport.
|
||||||
|
*/
|
||||||
|
public void flush();
|
||||||
|
}
|
@ -1,8 +1,10 @@
|
|||||||
package dorkbox.network.connection;
|
package dorkbox.network.connection.bridge;
|
||||||
|
|
||||||
|
import dorkbox.network.connection.ConnectionPoint;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public interface ConnectionBridge {
|
public interface ConnectionBridgeBase {
|
||||||
/**
|
/**
|
||||||
* Sends the message to other listeners INSIDE this endpoint. It does not
|
* Sends the message to other listeners INSIDE this endpoint. It does not
|
||||||
* send it to a remote address.
|
* send it to a remote address.
|
||||||
@ -26,16 +28,4 @@ public interface ConnectionBridge {
|
|||||||
* local channel).
|
* local channel).
|
||||||
*/
|
*/
|
||||||
public ConnectionPoint UDT(Object message);
|
public ConnectionPoint UDT(Object message);
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends a "ping" packet, trying UDP, then UDT, then TCP (in that order) to measure <b>ROUND TRIP</b> time to the remote connection.
|
|
||||||
*
|
|
||||||
* @return Ping can have a listener attached, which will get called when the ping returns.
|
|
||||||
*/
|
|
||||||
public Ping ping();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Flushes the contents of the TCP/UDP/UDT/etc pipes to the actual transport.
|
|
||||||
*/
|
|
||||||
public void flush();
|
|
||||||
}
|
}
|
@ -1,4 +1,7 @@
|
|||||||
package dorkbox.network.connection;
|
package dorkbox.network.connection.bridge;
|
||||||
|
|
||||||
|
import dorkbox.network.connection.ConnectionPoint;
|
||||||
|
import dorkbox.network.connection.Ping;
|
||||||
|
|
||||||
|
|
||||||
public class ConnectionBridgeFlushAlways implements ConnectionBridge {
|
public class ConnectionBridgeFlushAlways implements ConnectionBridge {
|
@ -0,0 +1,11 @@
|
|||||||
|
package dorkbox.network.connection.bridge;
|
||||||
|
|
||||||
|
|
||||||
|
public interface ConnectionBridgeServer extends ConnectionBridgeBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exposes methods to send the object to all server connections (except the specified one)
|
||||||
|
* over the network. (or via LOCAL when it's a local channel).
|
||||||
|
*/
|
||||||
|
public ConnectionExceptSpecifiedBridgeServer except();
|
||||||
|
}
|
@ -1,4 +1,6 @@
|
|||||||
package dorkbox.network.connection;
|
package dorkbox.network.connection.bridge;
|
||||||
|
|
||||||
|
import dorkbox.network.connection.Connection;
|
||||||
|
|
||||||
|
|
||||||
public interface ConnectionExceptSpecifiedBridgeServer {
|
public interface ConnectionExceptSpecifiedBridgeServer {
|
@ -1,9 +1,9 @@
|
|||||||
package dorkbox.network.connection.idle;
|
package dorkbox.network.connection.idle;
|
||||||
|
|
||||||
import dorkbox.network.connection.Connection;
|
import dorkbox.network.connection.Connection;
|
||||||
import dorkbox.network.connection.Listener;
|
import dorkbox.network.connection.ListenerRaw;
|
||||||
|
|
||||||
abstract class IdleListener<C extends Connection, M> extends Listener<C, M> {
|
abstract class IdleListener<C extends Connection, M> extends ListenerRaw<C, M> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* used by the Idle Sender
|
* used by the Idle Sender
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
package dorkbox.network.connection.idle;
|
package dorkbox.network.connection.idle;
|
||||||
|
|
||||||
import dorkbox.network.connection.Connection;
|
import dorkbox.network.connection.Connection;
|
||||||
import dorkbox.network.connection.Listener;
|
import dorkbox.network.connection.ListenerRaw;
|
||||||
|
|
||||||
|
|
||||||
abstract public class IdleSender<C extends Connection, M> extends Listener<C, M> implements IdleBridge {
|
abstract public class IdleSender<C extends Connection, M> extends ListenerRaw<C, M> implements IdleBridge {
|
||||||
volatile boolean started;
|
volatile boolean started;
|
||||||
IdleListener<C, M> idleListener;
|
IdleListener<C, M> idleListener;
|
||||||
|
|
||||||
|
@ -8,13 +8,13 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
|
|
||||||
import org.bouncycastle.crypto.params.ParametersWithIV;
|
import org.bouncycastle.crypto.params.ParametersWithIV;
|
||||||
|
|
||||||
|
import dorkbox.network.connection.ConnectionPointWriter;
|
||||||
import dorkbox.network.connection.Connection;
|
import dorkbox.network.connection.Connection;
|
||||||
import dorkbox.network.connection.ConnectionPoint;
|
|
||||||
import dorkbox.network.connection.EndPoint;
|
import dorkbox.network.connection.EndPoint;
|
||||||
import dorkbox.network.connection.ISessionManager;
|
import dorkbox.network.connection.ISessionManager;
|
||||||
import dorkbox.network.connection.registration.MetaChannel;
|
import dorkbox.network.connection.registration.MetaChannel;
|
||||||
|
|
||||||
public class ChannelLocalWrapper implements ChannelWrapper, ConnectionPoint {
|
public class ChannelLocalWrapper implements ChannelWrapper, ConnectionPointWriter {
|
||||||
|
|
||||||
private final Channel channel;
|
private final Channel channel;
|
||||||
private String remoteAddress;
|
private String remoteAddress;
|
||||||
@ -68,17 +68,17 @@ public class ChannelLocalWrapper implements ChannelWrapper, ConnectionPoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConnectionPoint tcp() {
|
public ConnectionPointWriter tcp() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConnectionPoint udp() {
|
public ConnectionPointWriter udp() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConnectionPoint udt() {
|
public ConnectionPointWriter udt() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,9 +5,9 @@ import io.netty.channel.ChannelFuture;
|
|||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import dorkbox.network.connection.ConnectionPoint;
|
import dorkbox.network.connection.ConnectionPointWriter;
|
||||||
|
|
||||||
public class ChannelNetwork implements ConnectionPoint {
|
public class ChannelNetwork implements ConnectionPointWriter {
|
||||||
|
|
||||||
private volatile ChannelFuture lastWriteFuture;
|
private volatile ChannelFuture lastWriteFuture;
|
||||||
private final Channel channel;
|
private final Channel channel;
|
||||||
|
@ -8,8 +8,8 @@ import java.net.InetSocketAddress;
|
|||||||
import org.bouncycastle.crypto.params.KeyParameter;
|
import org.bouncycastle.crypto.params.KeyParameter;
|
||||||
import org.bouncycastle.crypto.params.ParametersWithIV;
|
import org.bouncycastle.crypto.params.ParametersWithIV;
|
||||||
|
|
||||||
|
import dorkbox.network.connection.ConnectionPointWriter;
|
||||||
import dorkbox.network.connection.Connection;
|
import dorkbox.network.connection.Connection;
|
||||||
import dorkbox.network.connection.ConnectionPoint;
|
|
||||||
import dorkbox.network.connection.EndPoint;
|
import dorkbox.network.connection.EndPoint;
|
||||||
import dorkbox.network.connection.ISessionManager;
|
import dorkbox.network.connection.ISessionManager;
|
||||||
import dorkbox.network.connection.UdpServer;
|
import dorkbox.network.connection.UdpServer;
|
||||||
@ -104,17 +104,17 @@ public class ChannelNetworkWrapper implements ChannelWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConnectionPoint tcp() {
|
public ConnectionPointWriter tcp() {
|
||||||
return this.tcp;
|
return this.tcp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConnectionPoint udp() {
|
public ConnectionPointWriter udp() {
|
||||||
return this.udp;
|
return this.udp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConnectionPoint udt() {
|
public ConnectionPointWriter udt() {
|
||||||
return this.udt;
|
return this.udt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
package dorkbox.network.connection.wrapper;
|
package dorkbox.network.connection.wrapper;
|
||||||
|
|
||||||
import dorkbox.network.connection.ConnectionPoint;
|
import dorkbox.network.connection.ConnectionPoint;
|
||||||
|
import dorkbox.network.connection.ConnectionPointWriter;
|
||||||
|
|
||||||
public class ChannelNull implements ConnectionPoint {
|
public class ChannelNull implements ConnectionPointWriter {
|
||||||
|
|
||||||
private static final ConnectionPoint INSTANCE = new ChannelNull();
|
private static final ConnectionPoint INSTANCE = new ChannelNull();
|
||||||
public static ConnectionPoint get() {
|
public static ConnectionPoint get() {
|
||||||
|
@ -5,15 +5,15 @@ import io.netty.channel.EventLoop;
|
|||||||
|
|
||||||
import org.bouncycastle.crypto.params.ParametersWithIV;
|
import org.bouncycastle.crypto.params.ParametersWithIV;
|
||||||
|
|
||||||
|
import dorkbox.network.connection.ConnectionPointWriter;
|
||||||
import dorkbox.network.connection.Connection;
|
import dorkbox.network.connection.Connection;
|
||||||
import dorkbox.network.connection.ConnectionPoint;
|
|
||||||
import dorkbox.network.connection.ISessionManager;
|
import dorkbox.network.connection.ISessionManager;
|
||||||
|
|
||||||
public interface ChannelWrapper {
|
public interface ChannelWrapper {
|
||||||
|
|
||||||
public ConnectionPoint tcp();
|
public ConnectionPointWriter tcp();
|
||||||
public ConnectionPoint udp();
|
public ConnectionPointWriter udp();
|
||||||
public ConnectionPoint udt();
|
public ConnectionPointWriter udt();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the connection with any extra info that is needed but was unavailable at the channel construction.
|
* Initialize the connection with any extra info that is needed but was unavailable at the channel construction.
|
||||||
|
@ -10,7 +10,7 @@ import java.util.concurrent.locks.Condition;
|
|||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
import dorkbox.network.connection.Connection;
|
import dorkbox.network.connection.Connection;
|
||||||
import dorkbox.network.connection.Listener;
|
import dorkbox.network.connection.ListenerRaw;
|
||||||
|
|
||||||
/** Handles network communication when methods are invoked on a proxy. */
|
/** Handles network communication when methods are invoked on a proxy. */
|
||||||
class RemoteInvocationHandler implements InvocationHandler {
|
class RemoteInvocationHandler implements InvocationHandler {
|
||||||
@ -27,7 +27,7 @@ class RemoteInvocationHandler implements InvocationHandler {
|
|||||||
private Byte lastResponseID;
|
private Byte lastResponseID;
|
||||||
private byte nextResponseNum = 1;
|
private byte nextResponseNum = 1;
|
||||||
|
|
||||||
private Listener<Connection, InvokeMethodResult> responseListener;
|
private ListenerRaw<Connection, InvokeMethodResult> responseListener;
|
||||||
|
|
||||||
final ReentrantLock lock = new ReentrantLock();
|
final ReentrantLock lock = new ReentrantLock();
|
||||||
final Condition responseCondition = lock.newCondition();
|
final Condition responseCondition = lock.newCondition();
|
||||||
@ -40,7 +40,7 @@ class RemoteInvocationHandler implements InvocationHandler {
|
|||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
this.objectID = objectID;
|
this.objectID = objectID;
|
||||||
|
|
||||||
responseListener = new Listener<Connection, InvokeMethodResult>() {
|
responseListener = new ListenerRaw<Connection, InvokeMethodResult>() {
|
||||||
@Override
|
@Override
|
||||||
public void received (Connection connection, InvokeMethodResult invokeMethodResult) {
|
public void received (Connection connection, InvokeMethodResult invokeMethodResult) {
|
||||||
byte responseID = invokeMethodResult.responseID;
|
byte responseID = invokeMethodResult.responseID;
|
||||||
|
@ -5,7 +5,7 @@ import dorkbox.network.connection.Connection;
|
|||||||
|
|
||||||
|
|
||||||
/** Provides access to various settings on a remote object.
|
/** Provides access to various settings on a remote object.
|
||||||
* @see RmiBridge#getRemoteObject(dorkbox.networking.connection.interfaces.IConnection.Connection, int, Class...)
|
* @see RmiBridge#getRemoteObject(dorkbox.Connection.connection.interfaces.IConnection.Connection, int, Class...)
|
||||||
* @author Nathan Sweet <misc@n4te.com> */
|
* @author Nathan Sweet <misc@n4te.com> */
|
||||||
public interface RemoteObject {
|
public interface RemoteObject {
|
||||||
/** Sets the milliseconds to wait for a method to return value. Default is 3000. */
|
/** Sets the milliseconds to wait for a method to return value. Default is 3000. */
|
||||||
@ -38,7 +38,7 @@ public interface RemoteObject {
|
|||||||
|
|
||||||
/** Waits for the response to the last method invocation to be received or the response timeout to be reached. Must not be
|
/** Waits for the response to the last method invocation to be received or the response timeout to be reached. Must not be
|
||||||
* called from the connection's update thread.
|
* called from the connection's update thread.
|
||||||
* @see RmiBridge#getRemoteObject(dorkbox.networking.connection.interfaces.IConnection.Connection, int, Class...) */
|
* @see RmiBridge#getRemoteObject(dorkbox.Connection.connection.interfaces.IConnection.Connection, int, Class...) */
|
||||||
public Object waitForLastResponse ();
|
public Object waitForLastResponse ();
|
||||||
|
|
||||||
/** Gets the ID of response for the last method invocation. */
|
/** Gets the ID of response for the last method invocation. */
|
||||||
@ -48,7 +48,7 @@ public interface RemoteObject {
|
|||||||
* from the connection's update thread. Response IDs use a six bit identifier, with one identifier reserved for "no response".
|
* from the connection's update thread. Response IDs use a six bit identifier, with one identifier reserved for "no response".
|
||||||
* This means that this method should be called to get the result for a non-blocking call before an additional 63 non-blocking
|
* This means that this method should be called to get the result for a non-blocking call before an additional 63 non-blocking
|
||||||
* calls are made, or risk undefined behavior due to identical IDs.
|
* calls are made, or risk undefined behavior due to identical IDs.
|
||||||
* @see RmiBridge#getRemoteObject(dorkbox.networking.connection.interfaces.IConnection.Connection, int, Class...) */
|
* @see RmiBridge#getRemoteObject(dorkbox.Connection.connection.interfaces.IConnection.Connection, int, Class...) */
|
||||||
public Object waitForResponse (byte responseID);
|
public Object waitForResponse (byte responseID);
|
||||||
|
|
||||||
/** Causes this RemoteObject to stop listening to the connection for method invocation response messages. */
|
/** Causes this RemoteObject to stop listening to the connection for method invocation response messages. */
|
||||||
|
@ -29,7 +29,7 @@ import com.esotericsoftware.kryo.util.IntMap;
|
|||||||
|
|
||||||
import dorkbox.network.connection.Connection;
|
import dorkbox.network.connection.Connection;
|
||||||
import dorkbox.network.connection.EndPoint;
|
import dorkbox.network.connection.EndPoint;
|
||||||
import dorkbox.network.connection.Listener;
|
import dorkbox.network.connection.ListenerRaw;
|
||||||
import dorkbox.network.util.SerializationManager;
|
import dorkbox.network.util.SerializationManager;
|
||||||
import dorkbox.util.primativeCollections.ObjectIntMap;
|
import dorkbox.util.primativeCollections.ObjectIntMap;
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ public class RmiBridge {
|
|||||||
// the name of who created this object space.
|
// the name of who created this object space.
|
||||||
private final org.slf4j.Logger logger;
|
private final org.slf4j.Logger logger;
|
||||||
|
|
||||||
private final Listener<Connection, InvokeMethod> invokeListener= new Listener<Connection, InvokeMethod>() {
|
private final ListenerRaw<Connection, InvokeMethod> invokeListener= new ListenerRaw<Connection, InvokeMethod>() {
|
||||||
@Override
|
@Override
|
||||||
public void received(final Connection connection, final InvokeMethod invokeMethod) {
|
public void received(final Connection connection, final InvokeMethod invokeMethod) {
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
|
@ -14,6 +14,7 @@ import dorkbox.util.storage.Storage;
|
|||||||
* <p>
|
* <p>
|
||||||
* A static "create" method, with any number of parameters, is required to create this class (which is done via reflection)
|
* A static "create" method, with any number of parameters, is required to create this class (which is done via reflection)
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public abstract class SettingsStore {
|
public abstract class SettingsStore {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,7 +60,7 @@ public class ChunkedDataTest extends BaseTest {
|
|||||||
addEndPoint(server);
|
addEndPoint(server);
|
||||||
server.setIdleTimeout(100);
|
server.setIdleTimeout(100);
|
||||||
server.bind(false);
|
server.bind(false);
|
||||||
server.listeners().add(new Listener<Connection, Data>() {
|
server.listeners().add(new Listener<Data>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connected (Connection connection) {
|
public void connected (Connection connection) {
|
||||||
@ -82,7 +82,7 @@ public class ChunkedDataTest extends BaseTest {
|
|||||||
Client client = new Client(connectionOptions);
|
Client client = new Client(connectionOptions);
|
||||||
register(client.getSerialization());
|
register(client.getSerialization());
|
||||||
addEndPoint(client);
|
addEndPoint(client);
|
||||||
client.listeners().add(new Listener<Connection, Data>() {
|
client.listeners().add(new Listener<Data>() {
|
||||||
@Override
|
@Override
|
||||||
public void received(Connection connection, Data object) {
|
public void received(Connection connection, Data object) {
|
||||||
if (mainData.equals(object)) {
|
if (mainData.equals(object)) {
|
||||||
|
@ -3,6 +3,7 @@ package dorkbox.network;
|
|||||||
|
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
import hive.common.Listener;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
@ -10,7 +11,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import dorkbox.network.connection.Connection;
|
import dorkbox.network.connection.Connection;
|
||||||
import dorkbox.network.connection.Listener;
|
|
||||||
import dorkbox.network.util.SerializationManager;
|
import dorkbox.network.util.SerializationManager;
|
||||||
import dorkbox.network.util.exceptions.InitializationException;
|
import dorkbox.network.util.exceptions.InitializationException;
|
||||||
import dorkbox.network.util.exceptions.SecurityException;
|
import dorkbox.network.util.exceptions.SecurityException;
|
||||||
@ -30,7 +30,7 @@ public class ClientSendTest extends BaseTest {
|
|||||||
server.bind(false);
|
server.bind(false);
|
||||||
register(server.getSerialization());
|
register(server.getSerialization());
|
||||||
|
|
||||||
server.listeners().add(new Listener<Connection, AMessage>() {
|
server.listeners().add(new Listener<AMessage>() {
|
||||||
@Override
|
@Override
|
||||||
public void received (Connection connection, AMessage object) {
|
public void received (Connection connection, AMessage object) {
|
||||||
System.err.println("Server received message from client. Bouncing back.");
|
System.err.println("Server received message from client. Bouncing back.");
|
||||||
@ -43,7 +43,7 @@ public class ClientSendTest extends BaseTest {
|
|||||||
register(client.getSerialization());
|
register(client.getSerialization());
|
||||||
client.connect(5000);
|
client.connect(5000);
|
||||||
|
|
||||||
client.listeners().add(new Listener<Connection, AMessage>() {
|
client.listeners().add(new Listener<AMessage>() {
|
||||||
@Override
|
@Override
|
||||||
public void received (Connection connection, AMessage object) {
|
public void received (Connection connection, AMessage object) {
|
||||||
ClientSendTest.this.checkPassed.set(true);
|
ClientSendTest.this.checkPassed.set(true);
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
package dorkbox.network;
|
package dorkbox.network;
|
||||||
|
|
||||||
|
|
||||||
|
import hive.common.Listener;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
@ -9,7 +11,6 @@ import java.util.TimerTask;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import dorkbox.network.connection.Connection;
|
import dorkbox.network.connection.Connection;
|
||||||
import dorkbox.network.connection.Listener;
|
|
||||||
import dorkbox.network.util.exceptions.InitializationException;
|
import dorkbox.network.util.exceptions.InitializationException;
|
||||||
import dorkbox.network.util.exceptions.SecurityException;
|
import dorkbox.network.util.exceptions.SecurityException;
|
||||||
|
|
||||||
@ -119,12 +120,12 @@ public class ConnectionTest extends BaseTest {
|
|||||||
|
|
||||||
addEndPoint(server);
|
addEndPoint(server);
|
||||||
server.bind(false);
|
server.bind(false);
|
||||||
server.listeners().add(new Listener<Connection, Object>() {
|
server.listeners().add(new Listener<Object>() {
|
||||||
Timer timer = new Timer();
|
Timer timer = new Timer();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connected (final Connection connection) {
|
public void connected (final Connection connection) {
|
||||||
timer.schedule(new TimerTask() {
|
this.timer.schedule(new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run () {
|
public void run () {
|
||||||
System.out.println("Disconnecting after 1 second.");
|
System.out.println("Disconnecting after 1 second.");
|
||||||
@ -146,7 +147,7 @@ public class ConnectionTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
addEndPoint(client);
|
addEndPoint(client);
|
||||||
|
|
||||||
client.listeners().add(new Listener<Connection, Object>() {
|
client.listeners().add(new Listener<Object>() {
|
||||||
@Override
|
@Override
|
||||||
public void disconnected(Connection connection) {
|
public void disconnected(Connection connection) {
|
||||||
stopEndPoints();
|
stopEndPoints();
|
||||||
|
@ -3,13 +3,13 @@ package dorkbox.network;
|
|||||||
|
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
import hive.common.Listener;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import dorkbox.network.connection.Connection;
|
import dorkbox.network.connection.Connection;
|
||||||
import dorkbox.network.connection.Listener;
|
|
||||||
import dorkbox.network.util.exceptions.InitializationException;
|
import dorkbox.network.util.exceptions.InitializationException;
|
||||||
import dorkbox.network.util.exceptions.SecurityException;
|
import dorkbox.network.util.exceptions.SecurityException;
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ public class DiscoverHostTest extends BaseTest {
|
|||||||
|
|
||||||
Client client = new Client(connectionOptions);
|
Client client = new Client(connectionOptions);
|
||||||
addEndPoint(client);
|
addEndPoint(client);
|
||||||
client.listeners().add(new Listener<Connection, Object>() {
|
client.listeners().add(new Listener<Object>() {
|
||||||
@Override
|
@Override
|
||||||
public void connected(Connection connection) {
|
public void connected(Connection connection) {
|
||||||
DiscoverHostTest.this.connected = true;
|
DiscoverHostTest.this.connected = true;
|
||||||
|
@ -3,6 +3,7 @@ package dorkbox.network;
|
|||||||
|
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
import hive.common.Listener;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
@ -13,7 +14,6 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import dorkbox.network.PingPongTest.TYPE;
|
import dorkbox.network.PingPongTest.TYPE;
|
||||||
import dorkbox.network.connection.Connection;
|
import dorkbox.network.connection.Connection;
|
||||||
import dorkbox.network.connection.Listener;
|
|
||||||
import dorkbox.network.connection.idle.IdleBridge;
|
import dorkbox.network.connection.idle.IdleBridge;
|
||||||
import dorkbox.network.connection.idle.InputStreamSender;
|
import dorkbox.network.connection.idle.InputStreamSender;
|
||||||
import dorkbox.network.util.SerializationManager;
|
import dorkbox.network.util.SerializationManager;
|
||||||
@ -97,7 +97,7 @@ public class IdleTest extends BaseTest {
|
|||||||
addEndPoint(server);
|
addEndPoint(server);
|
||||||
server.setIdleTimeout(100);
|
server.setIdleTimeout(100);
|
||||||
server.bind(false);
|
server.bind(false);
|
||||||
server.listeners().add(new Listener<Connection, Data>() {
|
server.listeners().add(new Listener<Data>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connected (Connection connection) {
|
public void connected (Connection connection) {
|
||||||
@ -116,7 +116,7 @@ public class IdleTest extends BaseTest {
|
|||||||
Client client = new Client(connectionOptions);
|
Client client = new Client(connectionOptions);
|
||||||
register(client.getSerialization());
|
register(client.getSerialization());
|
||||||
addEndPoint(client);
|
addEndPoint(client);
|
||||||
client.listeners().add(new Listener<Connection, Data>() {
|
client.listeners().add(new Listener<Data>() {
|
||||||
@Override
|
@Override
|
||||||
public void received(Connection connection, Data object) {
|
public void received(Connection connection, Data object) {
|
||||||
if (mainData.equals(object)) {
|
if (mainData.equals(object)) {
|
||||||
@ -144,7 +144,7 @@ public class IdleTest extends BaseTest {
|
|||||||
addEndPoint(server);
|
addEndPoint(server);
|
||||||
server.setIdleTimeout(100);
|
server.setIdleTimeout(100);
|
||||||
server.bind(false);
|
server.bind(false);
|
||||||
server.listeners().add(new Listener<Connection, byte[]>() {
|
server.listeners().add(new Listener<byte[]>() {
|
||||||
@Override
|
@Override
|
||||||
public void connected (Connection connection) {
|
public void connected (Connection connection) {
|
||||||
ByteArrayOutputStream output = new ByteArrayOutputStream(largeDataSize);
|
ByteArrayOutputStream output = new ByteArrayOutputStream(largeDataSize);
|
||||||
@ -182,7 +182,7 @@ public class IdleTest extends BaseTest {
|
|||||||
Client client = new Client(connectionOptions);
|
Client client = new Client(connectionOptions);
|
||||||
client.getSerialization().setRegistrationRequired(false);
|
client.getSerialization().setRegistrationRequired(false);
|
||||||
addEndPoint(client);
|
addEndPoint(client);
|
||||||
client.listeners().add(new Listener<Connection, byte[]>() {
|
client.listeners().add(new Listener<byte[]>() {
|
||||||
int total;
|
int total;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,6 +3,7 @@ package dorkbox.network;
|
|||||||
|
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
import hive.common.Listener;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
@ -11,7 +12,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import dorkbox.network.connection.Connection;
|
import dorkbox.network.connection.Connection;
|
||||||
import dorkbox.network.connection.Listener;
|
|
||||||
import dorkbox.network.util.SerializationManager;
|
import dorkbox.network.util.SerializationManager;
|
||||||
import dorkbox.network.util.exceptions.InitializationException;
|
import dorkbox.network.util.exceptions.InitializationException;
|
||||||
import dorkbox.network.util.exceptions.SecurityException;
|
import dorkbox.network.util.exceptions.SecurityException;
|
||||||
@ -37,7 +37,7 @@ public class LargeBufferTest extends BaseTest {
|
|||||||
server.bind(false);
|
server.bind(false);
|
||||||
register(server.getSerialization());
|
register(server.getSerialization());
|
||||||
|
|
||||||
server.listeners().add(new Listener<Connection, LargeMessage>() {
|
server.listeners().add(new Listener<LargeMessage>() {
|
||||||
AtomicInteger received = new AtomicInteger();
|
AtomicInteger received = new AtomicInteger();
|
||||||
AtomicInteger receivedBytes = new AtomicInteger();
|
AtomicInteger receivedBytes = new AtomicInteger();
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ public class LargeBufferTest extends BaseTest {
|
|||||||
register(client.getSerialization());
|
register(client.getSerialization());
|
||||||
client.connect(5000);
|
client.connect(5000);
|
||||||
|
|
||||||
client.listeners().add(new Listener<Connection, LargeMessage>() {
|
client.listeners().add(new Listener<LargeMessage>() {
|
||||||
AtomicInteger received = new AtomicInteger();
|
AtomicInteger received = new AtomicInteger();
|
||||||
AtomicInteger receivedBytes = new AtomicInteger();
|
AtomicInteger receivedBytes = new AtomicInteger();
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ import org.junit.Test;
|
|||||||
import dorkbox.network.connection.Connection;
|
import dorkbox.network.connection.Connection;
|
||||||
import dorkbox.network.connection.ConnectionImpl;
|
import dorkbox.network.connection.ConnectionImpl;
|
||||||
import dorkbox.network.connection.Listener;
|
import dorkbox.network.connection.Listener;
|
||||||
|
import dorkbox.network.connection.ListenerRaw;
|
||||||
import dorkbox.network.util.exceptions.InitializationException;
|
import dorkbox.network.util.exceptions.InitializationException;
|
||||||
import dorkbox.network.util.exceptions.SecurityException;
|
import dorkbox.network.util.exceptions.SecurityException;
|
||||||
|
|
||||||
@ -28,6 +29,7 @@ public class ListenerTest extends BaseTest {
|
|||||||
AtomicBoolean subClassWorkedOK = new AtomicBoolean(false);
|
AtomicBoolean subClassWorkedOK = new AtomicBoolean(false);
|
||||||
AtomicBoolean subClassWorkedOK2 = new AtomicBoolean(false);
|
AtomicBoolean subClassWorkedOK2 = new AtomicBoolean(false);
|
||||||
AtomicBoolean superClassWorkedOK = new AtomicBoolean(false);
|
AtomicBoolean superClassWorkedOK = new AtomicBoolean(false);
|
||||||
|
AtomicBoolean superClass2WorkedOK = new AtomicBoolean(false);
|
||||||
AtomicBoolean disconnectWorkedOK = new AtomicBoolean(false);
|
AtomicBoolean disconnectWorkedOK = new AtomicBoolean(false);
|
||||||
|
|
||||||
// quick and dirty test to also test connection sub-classing
|
// quick and dirty test to also test connection sub-classing
|
||||||
@ -37,7 +39,7 @@ public class ListenerTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void check() {
|
public void check() {
|
||||||
subClassWorkedOK.set(true);
|
ListenerTest.this.subClassWorkedOK.set(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +50,7 @@ public class ListenerTest extends BaseTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void check() {
|
public void check() {
|
||||||
subClassWorkedOK.set(true);
|
ListenerTest.this.subClassWorkedOK.set(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +73,7 @@ public class ListenerTest extends BaseTest {
|
|||||||
addEndPoint(server);
|
addEndPoint(server);
|
||||||
server.bind(false);
|
server.bind(false);
|
||||||
|
|
||||||
server.listeners().add(new Listener<TestConnectionA, String>() {
|
server.listeners().add(new ListenerRaw<TestConnectionA, String>() {
|
||||||
@Override
|
@Override
|
||||||
public void received (TestConnectionA connection, String string) {
|
public void received (TestConnectionA connection, String string) {
|
||||||
connection.check();
|
connection.check();
|
||||||
@ -80,11 +82,11 @@ public class ListenerTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
server.listeners().add(new Listener<Connection, String>() {
|
server.listeners().add(new Listener<String>() {
|
||||||
@Override
|
@Override
|
||||||
public void received (Connection connection, String string) {
|
public void received (Connection connection, String string) {
|
||||||
// System.err.println("subclass check");
|
// System.err.println("subclass check");
|
||||||
subClassWorkedOK2.set(true);
|
ListenerTest.this.subClassWorkedOK2.set(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -93,7 +95,17 @@ public class ListenerTest extends BaseTest {
|
|||||||
@Override
|
@Override
|
||||||
public void received(Connection connection, Object string) {
|
public void received(Connection connection, Object string) {
|
||||||
// System.err.println("generic class check");
|
// System.err.println("generic class check");
|
||||||
superClassWorkedOK.set(true);
|
ListenerTest.this.superClassWorkedOK.set(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// should be able to happen!
|
||||||
|
server.listeners().add(new ListenerRaw() {
|
||||||
|
@Override
|
||||||
|
public void received(Connection connection, Object string) {
|
||||||
|
// System.err.println("generic class check");
|
||||||
|
ListenerTest.this.superClass2WorkedOK.set(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -101,13 +113,13 @@ public class ListenerTest extends BaseTest {
|
|||||||
@Override
|
@Override
|
||||||
public void disconnected(Connection connection) {
|
public void disconnected(Connection connection) {
|
||||||
// System.err.println("disconnect check");
|
// System.err.println("disconnect check");
|
||||||
disconnectWorkedOK.set(true);
|
ListenerTest.this.disconnectWorkedOK.set(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// should not let this happen!
|
// should not let this happen!
|
||||||
try {
|
try {
|
||||||
server.listeners().add(new Listener<TestConnectionB, String>() {
|
server.listeners().add(new ListenerRaw<TestConnectionB, String>() {
|
||||||
@Override
|
@Override
|
||||||
public void received (TestConnectionB connection, String string) {
|
public void received (TestConnectionB connection, String string) {
|
||||||
connection.check();
|
connection.check();
|
||||||
@ -115,7 +127,7 @@ public class ListenerTest extends BaseTest {
|
|||||||
connection.send().TCP(string);
|
connection.send().TCP(string);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
fail = "Should not be able to ADD listeners that are NOT the basetype or the interface";
|
this.fail = "Should not be able to ADD listeners that are NOT the basetype or the interface";
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("Successfully did NOT add listener that was not the base class");
|
System.err.println("Successfully did NOT add listener that was not the base class");
|
||||||
}
|
}
|
||||||
@ -126,20 +138,20 @@ public class ListenerTest extends BaseTest {
|
|||||||
Client client = new Client(connectionOptions);
|
Client client = new Client(connectionOptions);
|
||||||
|
|
||||||
addEndPoint(client);
|
addEndPoint(client);
|
||||||
client.listeners().add(new Listener<Connection, String>() {
|
client.listeners().add(new Listener<String>() {
|
||||||
@Override
|
@Override
|
||||||
public void connected (Connection connection) {
|
public void connected (Connection connection) {
|
||||||
connection.send().TCP(origString); // 20 a's
|
connection.send().TCP(ListenerTest.this.origString); // 20 a's
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received (Connection connection, String string) {
|
public void received (Connection connection, String string) {
|
||||||
if (count.get() < limit) {
|
if (ListenerTest.this.count.get() < ListenerTest.this.limit) {
|
||||||
count.getAndIncrement();
|
ListenerTest.this.count.getAndIncrement();
|
||||||
connection.send().TCP(string);
|
connection.send().TCP(string);
|
||||||
} else {
|
} else {
|
||||||
if (!origString.equals(string)) {
|
if (!ListenerTest.this.origString.equals(string)) {
|
||||||
fail = "original string not equal to the string received";
|
ListenerTest.this.fail = "original string not equal to the string received";
|
||||||
}
|
}
|
||||||
stopEndPoints();
|
stopEndPoints();
|
||||||
}
|
}
|
||||||
@ -150,14 +162,15 @@ public class ListenerTest extends BaseTest {
|
|||||||
client.connect(5000);
|
client.connect(5000);
|
||||||
|
|
||||||
waitForThreads();
|
waitForThreads();
|
||||||
assertEquals(limit, count.get());
|
assertEquals(this.limit, this.count.get());
|
||||||
assertTrue(subClassWorkedOK.get());
|
assertTrue(this.subClassWorkedOK.get());
|
||||||
assertTrue(subClassWorkedOK2.get());
|
assertTrue(this.subClassWorkedOK2.get());
|
||||||
assertTrue(superClassWorkedOK.get());
|
assertTrue(this.superClassWorkedOK.get());
|
||||||
assertTrue(disconnectWorkedOK.get());
|
assertTrue(this.superClass2WorkedOK.get());
|
||||||
|
assertTrue(this.disconnectWorkedOK.get());
|
||||||
|
|
||||||
if (fail != null) {
|
if (this.fail != null) {
|
||||||
fail(fail);
|
fail(this.fail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
package dorkbox.network;
|
package dorkbox.network;
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
import hive.common.Listener;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
@ -9,7 +10,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import dorkbox.network.connection.Connection;
|
import dorkbox.network.connection.Connection;
|
||||||
import dorkbox.network.connection.Listener;
|
|
||||||
import dorkbox.network.util.exceptions.InitializationException;
|
import dorkbox.network.util.exceptions.InitializationException;
|
||||||
import dorkbox.network.util.exceptions.SecurityException;
|
import dorkbox.network.util.exceptions.SecurityException;
|
||||||
|
|
||||||
@ -30,13 +30,13 @@ public class MultipleServerTest extends BaseTest {
|
|||||||
addEndPoint(server1);
|
addEndPoint(server1);
|
||||||
|
|
||||||
server1.bind(false);
|
server1.bind(false);
|
||||||
server1.listeners().add(new Listener<Connection, String>() {
|
server1.listeners().add(new Listener<String>() {
|
||||||
@Override
|
@Override
|
||||||
public void received (Connection connection, String object) {
|
public void received (Connection connection, String object) {
|
||||||
if (!object.equals("client1")) {
|
if (!object.equals("client1")) {
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
if (received.incrementAndGet() == 2) {
|
if (MultipleServerTest.this.received.incrementAndGet() == 2) {
|
||||||
stopEndPoints();
|
stopEndPoints();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -52,13 +52,13 @@ public class MultipleServerTest extends BaseTest {
|
|||||||
server2.getSerialization().register(String[].class);
|
server2.getSerialization().register(String[].class);
|
||||||
addEndPoint(server2);
|
addEndPoint(server2);
|
||||||
server2.bind(false);
|
server2.bind(false);
|
||||||
server2.listeners().add(new Listener<Connection, String>() {
|
server2.listeners().add(new Listener<String>() {
|
||||||
@Override
|
@Override
|
||||||
public void received (Connection connection, String object) {
|
public void received (Connection connection, String object) {
|
||||||
if (!object.equals("client2")) {
|
if (!object.equals("client2")) {
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
if (received.incrementAndGet() == 2) {
|
if (MultipleServerTest.this.received.incrementAndGet() == 2) {
|
||||||
stopEndPoints();
|
stopEndPoints();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ public class MultipleServerTest extends BaseTest {
|
|||||||
Client client1 = new Client(connectionOptions1);
|
Client client1 = new Client(connectionOptions1);
|
||||||
client1.getSerialization().register(String[].class);
|
client1.getSerialization().register(String[].class);
|
||||||
addEndPoint(client1);
|
addEndPoint(client1);
|
||||||
client1.listeners().add(new Listener<Connection, String>() {
|
client1.listeners().add(new Listener<String>() {
|
||||||
@Override
|
@Override
|
||||||
public void connected (Connection connection) {
|
public void connected (Connection connection) {
|
||||||
connection.send().TCP("client1");
|
connection.send().TCP("client1");
|
||||||
@ -85,7 +85,7 @@ public class MultipleServerTest extends BaseTest {
|
|||||||
Client client2 = new Client(connectionOptions2);
|
Client client2 = new Client(connectionOptions2);
|
||||||
client2.getSerialization().register(String[].class);
|
client2.getSerialization().register(String[].class);
|
||||||
addEndPoint(client2);
|
addEndPoint(client2);
|
||||||
client2.listeners().add(new Listener<Connection, String>() {
|
client2.listeners().add(new Listener<String>() {
|
||||||
@Override
|
@Override
|
||||||
public void connected (Connection connection) {
|
public void connected (Connection connection) {
|
||||||
connection.send().TCP("client2");
|
connection.send().TCP("client2");
|
||||||
|
@ -3,6 +3,7 @@ package dorkbox.network;
|
|||||||
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import hive.common.Listener;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -14,7 +15,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import dorkbox.network.connection.Connection;
|
import dorkbox.network.connection.Connection;
|
||||||
import dorkbox.network.connection.Listener;
|
import dorkbox.network.connection.ListenerRaw;
|
||||||
import dorkbox.network.util.exceptions.InitializationException;
|
import dorkbox.network.util.exceptions.InitializationException;
|
||||||
import dorkbox.network.util.exceptions.SecurityException;
|
import dorkbox.network.util.exceptions.SecurityException;
|
||||||
|
|
||||||
@ -45,7 +46,7 @@ public class MultipleThreadTest extends BaseTest {
|
|||||||
server.getSerialization().register(DataClass.class);
|
server.getSerialization().register(DataClass.class);
|
||||||
addEndPoint(server);
|
addEndPoint(server);
|
||||||
server.bind(false);
|
server.bind(false);
|
||||||
server.listeners().add(new Listener<Connection, DataClass>() {
|
server.listeners().add(new Listener<DataClass>() {
|
||||||
@Override
|
@Override
|
||||||
public void connected(final Connection connection) {
|
public void connected(final Connection connection) {
|
||||||
System.err.println("Client connected to server.");
|
System.err.println("Client connected to server.");
|
||||||
@ -94,7 +95,7 @@ public class MultipleThreadTest extends BaseTest {
|
|||||||
client.getSerialization().register(String[].class);
|
client.getSerialization().register(String[].class);
|
||||||
client.getSerialization().register(DataClass.class);
|
client.getSerialization().register(DataClass.class);
|
||||||
addEndPoint(client);
|
addEndPoint(client);
|
||||||
client.listeners().add(new Listener<Connection, DataClass>() {
|
client.listeners().add(new ListenerRaw<Connection, DataClass>() {
|
||||||
AtomicInteger received = new AtomicInteger(1);
|
AtomicInteger received = new AtomicInteger(1);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,6 +2,7 @@ package dorkbox.network;
|
|||||||
|
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
import hive.common.Listener;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -10,7 +11,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import dorkbox.network.connection.Connection;
|
import dorkbox.network.connection.Connection;
|
||||||
import dorkbox.network.connection.Listener;
|
|
||||||
import dorkbox.network.util.SerializationManager;
|
import dorkbox.network.util.SerializationManager;
|
||||||
import dorkbox.network.util.exceptions.InitializationException;
|
import dorkbox.network.util.exceptions.InitializationException;
|
||||||
import dorkbox.network.util.exceptions.SecurityException;
|
import dorkbox.network.util.exceptions.SecurityException;
|
||||||
@ -21,7 +21,7 @@ public class PingPongLocalTest extends BaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pingPongLocal() throws IOException, InitializationException, SecurityException {
|
public void pingPongLocal() throws IOException, InitializationException, SecurityException {
|
||||||
fail = "Data not received.";
|
this.fail = "Data not received.";
|
||||||
|
|
||||||
final Data dataLOCAL = new Data();
|
final Data dataLOCAL = new Data();
|
||||||
populateData(dataLOCAL);
|
populateData(dataLOCAL);
|
||||||
@ -30,18 +30,18 @@ public class PingPongLocalTest extends BaseTest {
|
|||||||
addEndPoint(server);
|
addEndPoint(server);
|
||||||
register(server.getSerialization());
|
register(server.getSerialization());
|
||||||
server.bind(false);
|
server.bind(false);
|
||||||
server.listeners().add(new Listener<Connection, Data>() {
|
server.listeners().add(new Listener<Data>() {
|
||||||
@Override
|
@Override
|
||||||
public void error(Connection connection, Throwable throwable) {
|
public void error(Connection connection, Throwable throwable) {
|
||||||
fail = "Error during processing. " + throwable;
|
PingPongLocalTest.this.fail = "Error during processing. " + throwable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received(Connection connection, Data data) {
|
public void received(Connection connection, Data data) {
|
||||||
connection.id();
|
connection.id();
|
||||||
if (!data.equals(dataLOCAL)) {
|
if (!data.equals(dataLOCAL)) {
|
||||||
fail = "data is not equal on server.";
|
PingPongLocalTest.this.fail = "data is not equal on server.";
|
||||||
throw new RuntimeException("Fail! " + fail);
|
throw new RuntimeException("Fail! " + PingPongLocalTest.this.fail);
|
||||||
}
|
}
|
||||||
connection.send().TCP(data);
|
connection.send().TCP(data);
|
||||||
}
|
}
|
||||||
@ -52,33 +52,33 @@ public class PingPongLocalTest extends BaseTest {
|
|||||||
Client client = new Client();
|
Client client = new Client();
|
||||||
addEndPoint(client);
|
addEndPoint(client);
|
||||||
register(client.getSerialization());
|
register(client.getSerialization());
|
||||||
client.listeners().add(new Listener<Connection, Data>() {
|
client.listeners().add(new Listener<Data>() {
|
||||||
AtomicInteger check = new AtomicInteger(0);
|
AtomicInteger check = new AtomicInteger(0);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connected(Connection connection) {
|
public void connected(Connection connection) {
|
||||||
fail = null;
|
PingPongLocalTest.this.fail = null;
|
||||||
connection.send().TCP(dataLOCAL);
|
connection.send().TCP(dataLOCAL);
|
||||||
// connection.sendUDP(dataUDP); // TCP and UDP are the same for a local channel.
|
// connection.sendUDP(dataUDP); // TCP and UDP are the same for a local channel.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void error(Connection connection, Throwable throwable) {
|
public void error(Connection connection, Throwable throwable) {
|
||||||
fail = "Error during processing. " + throwable;
|
PingPongLocalTest.this.fail = "Error during processing. " + throwable;
|
||||||
System.err.println(fail);
|
System.err.println(PingPongLocalTest.this.fail);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received(Connection connection, Data data) {
|
public void received(Connection connection, Data data) {
|
||||||
if (!data.equals(dataLOCAL)) {
|
if (!data.equals(dataLOCAL)) {
|
||||||
fail = "data is not equal on client.";
|
PingPongLocalTest.this.fail = "data is not equal on client.";
|
||||||
throw new RuntimeException("Fail! " + fail);
|
throw new RuntimeException("Fail! " + PingPongLocalTest.this.fail);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (check.getAndIncrement() <= tries) {
|
if (this.check.getAndIncrement() <= PingPongLocalTest.this.tries) {
|
||||||
connection.send().TCP(data);
|
connection.send().TCP(data);
|
||||||
} else {
|
} else {
|
||||||
System.err.println("Ran LOCAL " + tries + " times");
|
System.err.println("Ran LOCAL " + PingPongLocalTest.this.tries + " times");
|
||||||
stopEndPoints();
|
stopEndPoints();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,8 +88,8 @@ public class PingPongLocalTest extends BaseTest {
|
|||||||
|
|
||||||
waitForThreads();
|
waitForThreads();
|
||||||
|
|
||||||
if (fail != null) {
|
if (this.fail != null) {
|
||||||
fail(fail);
|
fail(this.fail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,24 +187,24 @@ public class PingPongLocalTest extends BaseTest {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
result = prime * result + Arrays.hashCode(Booleans);
|
result = prime * result + Arrays.hashCode(this.Booleans);
|
||||||
result = prime * result + Arrays.hashCode(Bytes);
|
result = prime * result + Arrays.hashCode(this.Bytes);
|
||||||
result = prime * result + Arrays.hashCode(Chars);
|
result = prime * result + Arrays.hashCode(this.Chars);
|
||||||
result = prime * result + Arrays.hashCode(Doubles);
|
result = prime * result + Arrays.hashCode(this.Doubles);
|
||||||
result = prime * result + Arrays.hashCode(Floats);
|
result = prime * result + Arrays.hashCode(this.Floats);
|
||||||
result = prime * result + Arrays.hashCode(Ints);
|
result = prime * result + Arrays.hashCode(this.Ints);
|
||||||
result = prime * result + Arrays.hashCode(Longs);
|
result = prime * result + Arrays.hashCode(this.Longs);
|
||||||
result = prime * result + Arrays.hashCode(Shorts);
|
result = prime * result + Arrays.hashCode(this.Shorts);
|
||||||
result = prime * result + Arrays.hashCode(booleans);
|
result = prime * result + Arrays.hashCode(this.booleans);
|
||||||
result = prime * result + Arrays.hashCode(bytes);
|
result = prime * result + Arrays.hashCode(this.bytes);
|
||||||
result = prime * result + Arrays.hashCode(chars);
|
result = prime * result + Arrays.hashCode(this.chars);
|
||||||
result = prime * result + Arrays.hashCode(doubles);
|
result = prime * result + Arrays.hashCode(this.doubles);
|
||||||
result = prime * result + Arrays.hashCode(floats);
|
result = prime * result + Arrays.hashCode(this.floats);
|
||||||
result = prime * result + Arrays.hashCode(ints);
|
result = prime * result + Arrays.hashCode(this.ints);
|
||||||
result = prime * result + Arrays.hashCode(longs);
|
result = prime * result + Arrays.hashCode(this.longs);
|
||||||
result = prime * result + Arrays.hashCode(shorts);
|
result = prime * result + Arrays.hashCode(this.shorts);
|
||||||
result = prime * result + (string == null ? 0 : string.hashCode());
|
result = prime * result + (this.string == null ? 0 : this.string.hashCode());
|
||||||
result = prime * result + Arrays.hashCode(strings);
|
result = prime * result + Arrays.hashCode(this.strings);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,62 +220,62 @@ public class PingPongLocalTest extends BaseTest {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Data other = (Data) obj;
|
Data other = (Data) obj;
|
||||||
if (!Arrays.equals(Booleans, other.Booleans)) {
|
if (!Arrays.equals(this.Booleans, other.Booleans)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(Bytes, other.Bytes)) {
|
if (!Arrays.equals(this.Bytes, other.Bytes)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(Chars, other.Chars)) {
|
if (!Arrays.equals(this.Chars, other.Chars)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(Doubles, other.Doubles)) {
|
if (!Arrays.equals(this.Doubles, other.Doubles)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(Floats, other.Floats)) {
|
if (!Arrays.equals(this.Floats, other.Floats)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(Ints, other.Ints)) {
|
if (!Arrays.equals(this.Ints, other.Ints)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(Longs, other.Longs)) {
|
if (!Arrays.equals(this.Longs, other.Longs)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(Shorts, other.Shorts)) {
|
if (!Arrays.equals(this.Shorts, other.Shorts)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(booleans, other.booleans)) {
|
if (!Arrays.equals(this.booleans, other.booleans)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(bytes, other.bytes)) {
|
if (!Arrays.equals(this.bytes, other.bytes)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(chars, other.chars)) {
|
if (!Arrays.equals(this.chars, other.chars)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(doubles, other.doubles)) {
|
if (!Arrays.equals(this.doubles, other.doubles)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(floats, other.floats)) {
|
if (!Arrays.equals(this.floats, other.floats)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(ints, other.ints)) {
|
if (!Arrays.equals(this.ints, other.ints)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(longs, other.longs)) {
|
if (!Arrays.equals(this.longs, other.longs)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(shorts, other.shorts)) {
|
if (!Arrays.equals(this.shorts, other.shorts)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (string == null) {
|
if (this.string == null) {
|
||||||
if (other.string != null) {
|
if (other.string != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (!string.equals(other.string)) {
|
} else if (!this.string.equals(other.string)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(strings, other.strings)) {
|
if (!Arrays.equals(this.strings, other.strings)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -3,6 +3,7 @@ package dorkbox.network;
|
|||||||
|
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
import hive.common.Listener;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -13,7 +14,6 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import dorkbox.network.connection.Connection;
|
import dorkbox.network.connection.Connection;
|
||||||
import dorkbox.network.connection.EndPoint;
|
import dorkbox.network.connection.EndPoint;
|
||||||
import dorkbox.network.connection.Listener;
|
|
||||||
import dorkbox.network.util.SerializationManager;
|
import dorkbox.network.util.SerializationManager;
|
||||||
import dorkbox.network.util.exceptions.InitializationException;
|
import dorkbox.network.util.exceptions.InitializationException;
|
||||||
import dorkbox.network.util.exceptions.SecurityException;
|
import dorkbox.network.util.exceptions.SecurityException;
|
||||||
@ -33,7 +33,7 @@ public class PingPongTest extends BaseTest {
|
|||||||
int origSize = EndPoint.udpMaxSize;
|
int origSize = EndPoint.udpMaxSize;
|
||||||
EndPoint.udpMaxSize = 2048;
|
EndPoint.udpMaxSize = 2048;
|
||||||
|
|
||||||
fail = "Data not received.";
|
this.fail = "Data not received.";
|
||||||
|
|
||||||
ConnectionOptions connectionOptions = new ConnectionOptions();
|
ConnectionOptions connectionOptions = new ConnectionOptions();
|
||||||
connectionOptions.tcpPort = tcpPort;
|
connectionOptions.tcpPort = tcpPort;
|
||||||
@ -52,38 +52,38 @@ public class PingPongTest extends BaseTest {
|
|||||||
addEndPoint(server);
|
addEndPoint(server);
|
||||||
register(server.getSerialization());
|
register(server.getSerialization());
|
||||||
server.bind(false);
|
server.bind(false);
|
||||||
server.listeners().add(new Listener<Connection, Data>() {
|
server.listeners().add(new Listener<Data>() {
|
||||||
@Override
|
@Override
|
||||||
public void error(Connection connection, Throwable throwable) {
|
public void error(Connection connection, Throwable throwable) {
|
||||||
fail = "Error during processing. " + throwable;
|
PingPongTest.this.fail = "Error during processing. " + throwable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received (Connection connection, Data data) {
|
public void received (Connection connection, Data data) {
|
||||||
if (data.type == TYPE.TCP) {
|
if (data.type == TYPE.TCP) {
|
||||||
if (!data.equals(dataTCP)) {
|
if (!data.equals(dataTCP)) {
|
||||||
fail = "TCP data is not equal on server.";
|
PingPongTest.this.fail = "TCP data is not equal on server.";
|
||||||
throw new RuntimeException("Fail! " + fail);
|
throw new RuntimeException("Fail! " + PingPongTest.this.fail);
|
||||||
}
|
}
|
||||||
connection.send().TCP(data);
|
connection.send().TCP(data);
|
||||||
}
|
}
|
||||||
else if (data.type == TYPE.UDP) {
|
else if (data.type == TYPE.UDP) {
|
||||||
if (!data.equals(dataUDP)) {
|
if (!data.equals(dataUDP)) {
|
||||||
fail = "UDP data is not equal on server.";
|
PingPongTest.this.fail = "UDP data is not equal on server.";
|
||||||
throw new RuntimeException("Fail! " + fail);
|
throw new RuntimeException("Fail! " + PingPongTest.this.fail);
|
||||||
}
|
}
|
||||||
connection.send().UDP(data);
|
connection.send().UDP(data);
|
||||||
}
|
}
|
||||||
else if (data.type == TYPE.UDT) {
|
else if (data.type == TYPE.UDT) {
|
||||||
if (!data.equals(dataUDT)) {
|
if (!data.equals(dataUDT)) {
|
||||||
fail = "UDT data is not equal on server.";
|
PingPongTest.this.fail = "UDT data is not equal on server.";
|
||||||
throw new RuntimeException("Fail! " + fail);
|
throw new RuntimeException("Fail! " + PingPongTest.this.fail);
|
||||||
}
|
}
|
||||||
connection.send().UDT(data);
|
connection.send().UDT(data);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fail = "Unknown data type on server.";
|
PingPongTest.this.fail = "Unknown data type on server.";
|
||||||
throw new RuntimeException("Fail! " + fail);
|
throw new RuntimeException("Fail! " + PingPongTest.this.fail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -93,7 +93,7 @@ public class PingPongTest extends BaseTest {
|
|||||||
Client client = new Client(connectionOptions);
|
Client client = new Client(connectionOptions);
|
||||||
addEndPoint(client);
|
addEndPoint(client);
|
||||||
register(client.getSerialization());
|
register(client.getSerialization());
|
||||||
client.listeners().add(new Listener<Connection, Data>() {
|
client.listeners().add(new Listener<Data>() {
|
||||||
AtomicInteger checkTCP = new AtomicInteger(0);
|
AtomicInteger checkTCP = new AtomicInteger(0);
|
||||||
AtomicInteger checkUDP = new AtomicInteger(0);
|
AtomicInteger checkUDP = new AtomicInteger(0);
|
||||||
AtomicInteger checkUDT = new AtomicInteger(0);
|
AtomicInteger checkUDT = new AtomicInteger(0);
|
||||||
@ -103,7 +103,7 @@ public class PingPongTest extends BaseTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connected (Connection connection) {
|
public void connected (Connection connection) {
|
||||||
fail = null;
|
PingPongTest.this.fail = null;
|
||||||
connection.send().TCP(dataTCP);
|
connection.send().TCP(dataTCP);
|
||||||
connection.send().UDP(dataUDP); // UDP ping pong stops if a UDP packet is lost.
|
connection.send().UDP(dataUDP); // UDP ping pong stops if a UDP packet is lost.
|
||||||
connection.send().UDT(dataUDT);
|
connection.send().UDT(dataUDT);
|
||||||
@ -111,7 +111,7 @@ public class PingPongTest extends BaseTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void error(Connection connection, Throwable throwable) {
|
public void error(Connection connection, Throwable throwable) {
|
||||||
fail = "Error during processing. " + throwable;
|
PingPongTest.this.fail = "Error during processing. " + throwable;
|
||||||
throwable.printStackTrace();
|
throwable.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,44 +119,44 @@ public class PingPongTest extends BaseTest {
|
|||||||
public void received (Connection connection, Data data) {
|
public void received (Connection connection, Data data) {
|
||||||
if (data.type == TYPE.TCP) {
|
if (data.type == TYPE.TCP) {
|
||||||
if (!data.equals(dataTCP)) {
|
if (!data.equals(dataTCP)) {
|
||||||
fail = "TCP data is not equal on client.";
|
PingPongTest.this.fail = "TCP data is not equal on client.";
|
||||||
throw new RuntimeException("Fail! " + fail);
|
throw new RuntimeException("Fail! " + PingPongTest.this.fail);
|
||||||
}
|
}
|
||||||
if (checkTCP.getAndIncrement() <= tries) {
|
if (this.checkTCP.getAndIncrement() <= PingPongTest.this.tries) {
|
||||||
connection.send().TCP(data);
|
connection.send().TCP(data);
|
||||||
} else {
|
} else {
|
||||||
System.err.println("TCP done.");
|
System.err.println("TCP done.");
|
||||||
doneTCP.set(true);
|
this.doneTCP.set(true);
|
||||||
}
|
}
|
||||||
} else if (data.type == TYPE.UDP) {
|
} else if (data.type == TYPE.UDP) {
|
||||||
if (!data.equals(dataUDP)) {
|
if (!data.equals(dataUDP)) {
|
||||||
fail = "UDP data is not equal on client.";
|
PingPongTest.this.fail = "UDP data is not equal on client.";
|
||||||
throw new RuntimeException("Fail! " + fail);
|
throw new RuntimeException("Fail! " + PingPongTest.this.fail);
|
||||||
}
|
}
|
||||||
if (checkUDP.getAndIncrement() <= tries) {
|
if (this.checkUDP.getAndIncrement() <= PingPongTest.this.tries) {
|
||||||
connection.send().UDP(data);
|
connection.send().UDP(data);
|
||||||
} else {
|
} else {
|
||||||
System.err.println("UDP done.");
|
System.err.println("UDP done.");
|
||||||
doneUDP.set(true);
|
this.doneUDP.set(true);
|
||||||
}
|
}
|
||||||
} else if (data.type == TYPE.UDT) {
|
} else if (data.type == TYPE.UDT) {
|
||||||
if (!data.equals(dataUDT)) {
|
if (!data.equals(dataUDT)) {
|
||||||
fail = "UDT data is not equal on client.";
|
PingPongTest.this.fail = "UDT data is not equal on client.";
|
||||||
throw new RuntimeException("Fail! " + fail);
|
throw new RuntimeException("Fail! " + PingPongTest.this.fail);
|
||||||
}
|
}
|
||||||
if (checkUDT.getAndIncrement() <= tries) {
|
if (this.checkUDT.getAndIncrement() <= PingPongTest.this.tries) {
|
||||||
connection.send().UDT(data);
|
connection.send().UDT(data);
|
||||||
} else {
|
} else {
|
||||||
System.err.println("UDT done.");
|
System.err.println("UDT done.");
|
||||||
doneUDT.set(true);
|
this.doneUDT.set(true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fail = "Unknown data type on client.";
|
PingPongTest.this.fail = "Unknown data type on client.";
|
||||||
throw new RuntimeException("Fail! " + fail);
|
throw new RuntimeException("Fail! " + PingPongTest.this.fail);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doneTCP.get() && doneUDP.get() && doneUDT.get()) {
|
if (this.doneTCP.get() && this.doneUDP.get() && this.doneUDT.get()) {
|
||||||
System.err.println("Ran TCP, UDP, UDT " + tries + " times each");
|
System.err.println("Ran TCP, UDP, UDT " + PingPongTest.this.tries + " times each");
|
||||||
stopEndPoints();
|
stopEndPoints();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -166,8 +166,8 @@ public class PingPongTest extends BaseTest {
|
|||||||
|
|
||||||
waitForThreads();
|
waitForThreads();
|
||||||
|
|
||||||
if (fail != null) {
|
if (this.fail != null) {
|
||||||
fail(fail);
|
fail(this.fail);
|
||||||
}
|
}
|
||||||
|
|
||||||
EndPoint.udpMaxSize = origSize;
|
EndPoint.udpMaxSize = origSize;
|
||||||
@ -251,25 +251,25 @@ public class PingPongTest extends BaseTest {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
result = prime * result + Arrays.hashCode(Booleans);
|
result = prime * result + Arrays.hashCode(this.Booleans);
|
||||||
result = prime * result + Arrays.hashCode(Bytes);
|
result = prime * result + Arrays.hashCode(this.Bytes);
|
||||||
result = prime * result + Arrays.hashCode(Chars);
|
result = prime * result + Arrays.hashCode(this.Chars);
|
||||||
result = prime * result + Arrays.hashCode(Doubles);
|
result = prime * result + Arrays.hashCode(this.Doubles);
|
||||||
result = prime * result + Arrays.hashCode(Floats);
|
result = prime * result + Arrays.hashCode(this.Floats);
|
||||||
result = prime * result + Arrays.hashCode(Ints);
|
result = prime * result + Arrays.hashCode(this.Ints);
|
||||||
result = prime * result + Arrays.hashCode(Longs);
|
result = prime * result + Arrays.hashCode(this.Longs);
|
||||||
result = prime * result + Arrays.hashCode(Shorts);
|
result = prime * result + Arrays.hashCode(this.Shorts);
|
||||||
result = prime * result + Arrays.hashCode(booleans);
|
result = prime * result + Arrays.hashCode(this.booleans);
|
||||||
result = prime * result + Arrays.hashCode(bytes);
|
result = prime * result + Arrays.hashCode(this.bytes);
|
||||||
result = prime * result + Arrays.hashCode(chars);
|
result = prime * result + Arrays.hashCode(this.chars);
|
||||||
result = prime * result + Arrays.hashCode(doubles);
|
result = prime * result + Arrays.hashCode(this.doubles);
|
||||||
result = prime * result + Arrays.hashCode(floats);
|
result = prime * result + Arrays.hashCode(this.floats);
|
||||||
result = prime * result + Arrays.hashCode(ints);
|
result = prime * result + Arrays.hashCode(this.ints);
|
||||||
result = prime * result + Arrays.hashCode(longs);
|
result = prime * result + Arrays.hashCode(this.longs);
|
||||||
result = prime * result + Arrays.hashCode(shorts);
|
result = prime * result + Arrays.hashCode(this.shorts);
|
||||||
result = prime * result + (string == null ? 0 : string.hashCode());
|
result = prime * result + (this.string == null ? 0 : this.string.hashCode());
|
||||||
result = prime * result + Arrays.hashCode(strings);
|
result = prime * result + Arrays.hashCode(this.strings);
|
||||||
result = prime * result + (type == null ? 0 : type.hashCode());
|
result = prime * result + (this.type == null ? 0 : this.type.hashCode());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -285,65 +285,65 @@ public class PingPongTest extends BaseTest {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Data other = (Data) obj;
|
Data other = (Data) obj;
|
||||||
if (!Arrays.equals(Booleans, other.Booleans)) {
|
if (!Arrays.equals(this.Booleans, other.Booleans)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(Bytes, other.Bytes)) {
|
if (!Arrays.equals(this.Bytes, other.Bytes)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(Chars, other.Chars)) {
|
if (!Arrays.equals(this.Chars, other.Chars)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(Doubles, other.Doubles)) {
|
if (!Arrays.equals(this.Doubles, other.Doubles)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(Floats, other.Floats)) {
|
if (!Arrays.equals(this.Floats, other.Floats)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(Ints, other.Ints)) {
|
if (!Arrays.equals(this.Ints, other.Ints)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(Longs, other.Longs)) {
|
if (!Arrays.equals(this.Longs, other.Longs)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(Shorts, other.Shorts)) {
|
if (!Arrays.equals(this.Shorts, other.Shorts)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(booleans, other.booleans)) {
|
if (!Arrays.equals(this.booleans, other.booleans)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(bytes, other.bytes)) {
|
if (!Arrays.equals(this.bytes, other.bytes)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(chars, other.chars)) {
|
if (!Arrays.equals(this.chars, other.chars)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(doubles, other.doubles)) {
|
if (!Arrays.equals(this.doubles, other.doubles)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(floats, other.floats)) {
|
if (!Arrays.equals(this.floats, other.floats)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(ints, other.ints)) {
|
if (!Arrays.equals(this.ints, other.ints)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(longs, other.longs)) {
|
if (!Arrays.equals(this.longs, other.longs)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(shorts, other.shorts)) {
|
if (!Arrays.equals(this.shorts, other.shorts)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (string == null) {
|
if (this.string == null) {
|
||||||
if (other.string != null) {
|
if (other.string != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (!string.equals(other.string)) {
|
} else if (!this.string.equals(other.string)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(strings, other.strings)) {
|
if (!Arrays.equals(this.strings, other.strings)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (type != other.type) {
|
if (this.type != other.type) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -3,6 +3,7 @@ package dorkbox.network;
|
|||||||
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import hive.common.Listener;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
@ -12,7 +13,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import dorkbox.network.connection.Connection;
|
import dorkbox.network.connection.Connection;
|
||||||
import dorkbox.network.connection.Listener;
|
|
||||||
import dorkbox.network.util.exceptions.InitializationException;
|
import dorkbox.network.util.exceptions.InitializationException;
|
||||||
import dorkbox.network.util.exceptions.SecurityException;
|
import dorkbox.network.util.exceptions.SecurityException;
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ public class ReconnectTest extends BaseTest {
|
|||||||
final Server server = new Server(connectionOptions);
|
final Server server = new Server(connectionOptions);
|
||||||
addEndPoint(server);
|
addEndPoint(server);
|
||||||
server.bind(false);
|
server.bind(false);
|
||||||
server.listeners().add(new Listener<Connection, Object>() {
|
server.listeners().add(new Listener<Object>() {
|
||||||
@Override
|
@Override
|
||||||
public void connected(final Connection connection) {
|
public void connected(final Connection connection) {
|
||||||
timer.schedule(new TimerTask() {
|
timer.schedule(new TimerTask() {
|
||||||
@ -48,7 +48,7 @@ public class ReconnectTest extends BaseTest {
|
|||||||
final AtomicInteger reconnectCount = new AtomicInteger();
|
final AtomicInteger reconnectCount = new AtomicInteger();
|
||||||
final Client client = new Client(connectionOptions);
|
final Client client = new Client(connectionOptions);
|
||||||
addEndPoint(client);
|
addEndPoint(client);
|
||||||
client.listeners().add(new Listener<Connection, Object>() {
|
client.listeners().add(new Listener<Object>() {
|
||||||
@Override
|
@Override
|
||||||
public void disconnected (Connection connection) {
|
public void disconnected (Connection connection) {
|
||||||
if (reconnectCount.getAndIncrement() == 2) {
|
if (reconnectCount.getAndIncrement() == 2) {
|
||||||
|
@ -3,6 +3,7 @@ package dorkbox.network;
|
|||||||
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import hive.common.Listener;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
@ -10,7 +11,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import dorkbox.network.connection.Connection;
|
import dorkbox.network.connection.Connection;
|
||||||
import dorkbox.network.connection.Listener;
|
|
||||||
import dorkbox.network.util.exceptions.InitializationException;
|
import dorkbox.network.util.exceptions.InitializationException;
|
||||||
import dorkbox.network.util.exceptions.SecurityException;
|
import dorkbox.network.util.exceptions.SecurityException;
|
||||||
|
|
||||||
@ -20,8 +20,8 @@ public class ReuseTest extends BaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void socketReuse() throws IOException, InitializationException, SecurityException {
|
public void socketReuse() throws IOException, InitializationException, SecurityException {
|
||||||
serverCount = new AtomicInteger(0);
|
this.serverCount = new AtomicInteger(0);
|
||||||
clientCount = new AtomicInteger(0);
|
this.clientCount = new AtomicInteger(0);
|
||||||
|
|
||||||
ConnectionOptions connectionOptions = new ConnectionOptions();
|
ConnectionOptions connectionOptions = new ConnectionOptions();
|
||||||
connectionOptions.tcpPort = tcpPort;
|
connectionOptions.tcpPort = tcpPort;
|
||||||
@ -30,7 +30,7 @@ public class ReuseTest extends BaseTest {
|
|||||||
|
|
||||||
Server server = new Server(connectionOptions);
|
Server server = new Server(connectionOptions);
|
||||||
addEndPoint(server);
|
addEndPoint(server);
|
||||||
server.listeners().add(new Listener<Connection, String>() {
|
server.listeners().add(new Listener<String>() {
|
||||||
@Override
|
@Override
|
||||||
public void connected (Connection connection) {
|
public void connected (Connection connection) {
|
||||||
connection.send().TCP("-- TCP from server");
|
connection.send().TCP("-- TCP from server");
|
||||||
@ -39,7 +39,7 @@ public class ReuseTest extends BaseTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received (Connection connection, String object) {
|
public void received (Connection connection, String object) {
|
||||||
int incrementAndGet = serverCount.incrementAndGet();
|
int incrementAndGet = ReuseTest.this.serverCount.incrementAndGet();
|
||||||
System.err.println("<S " + connection + "> " + incrementAndGet + " : " + object);
|
System.err.println("<S " + connection + "> " + incrementAndGet + " : " + object);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -48,7 +48,7 @@ public class ReuseTest extends BaseTest {
|
|||||||
|
|
||||||
Client client = new Client(connectionOptions);
|
Client client = new Client(connectionOptions);
|
||||||
addEndPoint(client);
|
addEndPoint(client);
|
||||||
client.listeners().add(new Listener<Connection, String>() {
|
client.listeners().add(new Listener<String>() {
|
||||||
@Override
|
@Override
|
||||||
public void connected (Connection connection) {
|
public void connected (Connection connection) {
|
||||||
connection.send().TCP("-- TCP from client");
|
connection.send().TCP("-- TCP from client");
|
||||||
@ -57,7 +57,7 @@ public class ReuseTest extends BaseTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received (Connection connection, String object) {
|
public void received (Connection connection, String object) {
|
||||||
int incrementAndGet = clientCount.incrementAndGet();
|
int incrementAndGet = ReuseTest.this.clientCount.incrementAndGet();
|
||||||
System.err.println("<C " + connection + "> " + incrementAndGet + " : " + object);
|
System.err.println("<C " + connection + "> " + incrementAndGet + " : " + object);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -68,7 +68,7 @@ public class ReuseTest extends BaseTest {
|
|||||||
client.connect(5000);
|
client.connect(5000);
|
||||||
|
|
||||||
int target = i*2;
|
int target = i*2;
|
||||||
while (serverCount.get() != target || clientCount.get() != target) {
|
while (this.serverCount.get() != target || this.clientCount.get() != target) {
|
||||||
System.err.println("Waiting...");
|
System.err.println("Waiting...");
|
||||||
try {
|
try {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
@ -79,7 +79,7 @@ public class ReuseTest extends BaseTest {
|
|||||||
client.close();
|
client.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(count * 2 * 2, clientCount.get() + serverCount.get());
|
assertEquals(count * 2 * 2, this.clientCount.get() + this.serverCount.get());
|
||||||
|
|
||||||
stopEndPoints();
|
stopEndPoints();
|
||||||
waitForThreads(10);
|
waitForThreads(10);
|
||||||
@ -87,12 +87,12 @@ public class ReuseTest extends BaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void localReuse() throws IOException, InitializationException, SecurityException {
|
public void localReuse() throws IOException, InitializationException, SecurityException {
|
||||||
serverCount = new AtomicInteger(0);
|
this.serverCount = new AtomicInteger(0);
|
||||||
clientCount = new AtomicInteger(0);
|
this.clientCount = new AtomicInteger(0);
|
||||||
|
|
||||||
Server server = new Server();
|
Server server = new Server();
|
||||||
addEndPoint(server);
|
addEndPoint(server);
|
||||||
server.listeners().add(new Listener<Connection, String>() {
|
server.listeners().add(new Listener<String>() {
|
||||||
@Override
|
@Override
|
||||||
public void connected (Connection connection) {
|
public void connected (Connection connection) {
|
||||||
connection.send().TCP("-- LOCAL from server");
|
connection.send().TCP("-- LOCAL from server");
|
||||||
@ -100,7 +100,7 @@ public class ReuseTest extends BaseTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received (Connection connection, String object) {
|
public void received (Connection connection, String object) {
|
||||||
int incrementAndGet = serverCount.incrementAndGet();
|
int incrementAndGet = ReuseTest.this.serverCount.incrementAndGet();
|
||||||
System.err.println("<S " + connection + "> " + incrementAndGet + " : " + object);
|
System.err.println("<S " + connection + "> " + incrementAndGet + " : " + object);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -109,7 +109,7 @@ public class ReuseTest extends BaseTest {
|
|||||||
|
|
||||||
Client client = new Client();
|
Client client = new Client();
|
||||||
addEndPoint(client);
|
addEndPoint(client);
|
||||||
client.listeners().add(new Listener<Connection, String>() {
|
client.listeners().add(new Listener<String>() {
|
||||||
@Override
|
@Override
|
||||||
public void connected (Connection connection) {
|
public void connected (Connection connection) {
|
||||||
connection.send().TCP("-- LOCAL from client");
|
connection.send().TCP("-- LOCAL from client");
|
||||||
@ -117,7 +117,7 @@ public class ReuseTest extends BaseTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received (Connection connection, String object) {
|
public void received (Connection connection, String object) {
|
||||||
int incrementAndGet = clientCount.incrementAndGet();
|
int incrementAndGet = ReuseTest.this.clientCount.incrementAndGet();
|
||||||
System.err.println("<C " + connection + "> " + incrementAndGet + " : " + object);
|
System.err.println("<C " + connection + "> " + incrementAndGet + " : " + object);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -128,7 +128,7 @@ public class ReuseTest extends BaseTest {
|
|||||||
client.connect(5000);
|
client.connect(5000);
|
||||||
|
|
||||||
int target = i;
|
int target = i;
|
||||||
while (serverCount.get() != target || clientCount.get() != target) {
|
while (this.serverCount.get() != target || this.clientCount.get() != target) {
|
||||||
System.err.println("Waiting...");
|
System.err.println("Waiting...");
|
||||||
try {
|
try {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
@ -139,7 +139,7 @@ public class ReuseTest extends BaseTest {
|
|||||||
client.close();
|
client.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(count * 2, clientCount.get() + serverCount.get());
|
assertEquals(count * 2, this.clientCount.get() + this.serverCount.get());
|
||||||
|
|
||||||
stopEndPoints();
|
stopEndPoints();
|
||||||
waitForThreads(10);
|
waitForThreads(10);
|
||||||
|
@ -3,6 +3,7 @@ package dorkbox.network;
|
|||||||
|
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
import hive.common.Listener;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -13,7 +14,6 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import dorkbox.network.connection.Connection;
|
import dorkbox.network.connection.Connection;
|
||||||
import dorkbox.network.connection.EndPoint;
|
import dorkbox.network.connection.EndPoint;
|
||||||
import dorkbox.network.connection.Listener;
|
|
||||||
import dorkbox.network.util.exceptions.InitializationException;
|
import dorkbox.network.util.exceptions.InitializationException;
|
||||||
import dorkbox.network.util.exceptions.SecurityException;
|
import dorkbox.network.util.exceptions.SecurityException;
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ public class UnregisteredClassTest extends BaseTest {
|
|||||||
connectionOptions.udpPort = udpPort;
|
connectionOptions.udpPort = udpPort;
|
||||||
connectionOptions.host = host;
|
connectionOptions.host = host;
|
||||||
|
|
||||||
System.err.println("Running test " + tries + " times, please wait for it to finish.");
|
System.err.println("Running test " + this.tries + " times, please wait for it to finish.");
|
||||||
|
|
||||||
final Data dataTCP = new Data();
|
final Data dataTCP = new Data();
|
||||||
populateData(dataTCP, true);
|
populateData(dataTCP, true);
|
||||||
@ -45,28 +45,28 @@ public class UnregisteredClassTest extends BaseTest {
|
|||||||
server.getSerialization().setRegistrationRequired(false);
|
server.getSerialization().setRegistrationRequired(false);
|
||||||
addEndPoint(server);
|
addEndPoint(server);
|
||||||
server.bind(false);
|
server.bind(false);
|
||||||
server.listeners().add(new Listener<Connection, Data>() {
|
server.listeners().add(new Listener<Data>() {
|
||||||
@Override
|
@Override
|
||||||
public void error(Connection connection, Throwable throwable) {
|
public void error(Connection connection, Throwable throwable) {
|
||||||
fail = "Error during processing. " + throwable;
|
UnregisteredClassTest.this.fail = "Error during processing. " + throwable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received (Connection connection, Data data) {
|
public void received (Connection connection, Data data) {
|
||||||
if (data.isTCP) {
|
if (data.isTCP) {
|
||||||
if (!data.equals(dataTCP)) {
|
if (!data.equals(dataTCP)) {
|
||||||
fail = "TCP data is not equal on server.";
|
UnregisteredClassTest.this.fail = "TCP data is not equal on server.";
|
||||||
throw new RuntimeException("Fail! " + fail);
|
throw new RuntimeException("Fail! " + UnregisteredClassTest.this.fail);
|
||||||
}
|
}
|
||||||
connection.send().TCP(data);
|
connection.send().TCP(data);
|
||||||
receivedTCP.incrementAndGet();
|
UnregisteredClassTest.this.receivedTCP.incrementAndGet();
|
||||||
} else {
|
} else {
|
||||||
if (!data.equals(dataUDP)) {
|
if (!data.equals(dataUDP)) {
|
||||||
fail = "UDP data is not equal on server.";
|
UnregisteredClassTest.this.fail = "UDP data is not equal on server.";
|
||||||
throw new RuntimeException("Fail! " + fail);
|
throw new RuntimeException("Fail! " + UnregisteredClassTest.this.fail);
|
||||||
}
|
}
|
||||||
connection.send().UDP(data);
|
connection.send().UDP(data);
|
||||||
receivedUDP.incrementAndGet();
|
UnregisteredClassTest.this.receivedUDP.incrementAndGet();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -76,7 +76,7 @@ public class UnregisteredClassTest extends BaseTest {
|
|||||||
Client client = new Client(connectionOptions);
|
Client client = new Client(connectionOptions);
|
||||||
client.getSerialization().setRegistrationRequired(false);
|
client.getSerialization().setRegistrationRequired(false);
|
||||||
addEndPoint(client);
|
addEndPoint(client);
|
||||||
client.listeners().add(new Listener<Connection, Data>() {
|
client.listeners().add(new Listener<Data>() {
|
||||||
AtomicInteger checkTCP = new AtomicInteger(0);
|
AtomicInteger checkTCP = new AtomicInteger(0);
|
||||||
AtomicInteger checkUDP = new AtomicInteger(0);
|
AtomicInteger checkUDP = new AtomicInteger(0);
|
||||||
AtomicBoolean doneTCP = new AtomicBoolean(false);
|
AtomicBoolean doneTCP = new AtomicBoolean(false);
|
||||||
@ -84,47 +84,47 @@ public class UnregisteredClassTest extends BaseTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connected (Connection connection) {
|
public void connected (Connection connection) {
|
||||||
fail = null;
|
UnregisteredClassTest.this.fail = null;
|
||||||
connection.send().TCP(dataTCP);
|
connection.send().TCP(dataTCP);
|
||||||
connection.send().UDP(dataUDP); // UDP ping pong stops if a UDP packet is lost.
|
connection.send().UDP(dataUDP); // UDP ping pong stops if a UDP packet is lost.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void error(Connection connection, Throwable throwable) {
|
public void error(Connection connection, Throwable throwable) {
|
||||||
fail = "Error during processing. " + throwable;
|
UnregisteredClassTest.this.fail = "Error during processing. " + throwable;
|
||||||
System.err.println(fail);
|
System.err.println(UnregisteredClassTest.this.fail);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received (Connection connection, Data data) {
|
public void received (Connection connection, Data data) {
|
||||||
if (data.isTCP) {
|
if (data.isTCP) {
|
||||||
if (!data.equals(dataTCP)) {
|
if (!data.equals(dataTCP)) {
|
||||||
fail = "TCP data is not equal on client.";
|
UnregisteredClassTest.this.fail = "TCP data is not equal on client.";
|
||||||
throw new RuntimeException("Fail! " + fail);
|
throw new RuntimeException("Fail! " + UnregisteredClassTest.this.fail);
|
||||||
}
|
}
|
||||||
if (checkTCP.getAndIncrement() <= tries) {
|
if (this.checkTCP.getAndIncrement() <= UnregisteredClassTest.this.tries) {
|
||||||
connection.send().TCP(data);
|
connection.send().TCP(data);
|
||||||
receivedTCP.incrementAndGet();
|
UnregisteredClassTest.this.receivedTCP.incrementAndGet();
|
||||||
} else {
|
} else {
|
||||||
System.err.println("TCP done.");
|
System.err.println("TCP done.");
|
||||||
doneTCP.set(true);
|
this.doneTCP.set(true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!data.equals(dataUDP)) {
|
if (!data.equals(dataUDP)) {
|
||||||
fail = "UDP data is not equal on client.";
|
UnregisteredClassTest.this.fail = "UDP data is not equal on client.";
|
||||||
throw new RuntimeException("Fail! " + fail);
|
throw new RuntimeException("Fail! " + UnregisteredClassTest.this.fail);
|
||||||
}
|
}
|
||||||
if (checkUDP.getAndIncrement() <= tries) {
|
if (this.checkUDP.getAndIncrement() <= UnregisteredClassTest.this.tries) {
|
||||||
connection.send().UDP(data);
|
connection.send().UDP(data);
|
||||||
receivedUDP.incrementAndGet();
|
UnregisteredClassTest.this.receivedUDP.incrementAndGet();
|
||||||
} else {
|
} else {
|
||||||
System.err.println("UDP done.");
|
System.err.println("UDP done.");
|
||||||
doneUDP.set(true);
|
this.doneUDP.set(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doneTCP.get() && doneUDP.get()) {
|
if (this.doneTCP.get() && this.doneUDP.get()) {
|
||||||
System.err.println("Ran TCP & UDP " + tries + " times each");
|
System.err.println("Ran TCP & UDP " + UnregisteredClassTest.this.tries + " times each");
|
||||||
stopEndPoints();
|
stopEndPoints();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,8 +133,8 @@ public class UnregisteredClassTest extends BaseTest {
|
|||||||
client.connect(5000);
|
client.connect(5000);
|
||||||
waitForThreads();
|
waitForThreads();
|
||||||
|
|
||||||
if (fail != null) {
|
if (this.fail != null) {
|
||||||
fail(fail);
|
fail(this.fail);
|
||||||
}
|
}
|
||||||
|
|
||||||
EndPoint.udpMaxSize = origSize;
|
EndPoint.udpMaxSize = origSize;
|
||||||
@ -196,25 +196,25 @@ public class UnregisteredClassTest extends BaseTest {
|
|||||||
public int hashCode () {
|
public int hashCode () {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
result = prime * result + Arrays.hashCode(Booleans);
|
result = prime * result + Arrays.hashCode(this.Booleans);
|
||||||
result = prime * result + Arrays.hashCode(Bytes);
|
result = prime * result + Arrays.hashCode(this.Bytes);
|
||||||
result = prime * result + Arrays.hashCode(Chars);
|
result = prime * result + Arrays.hashCode(this.Chars);
|
||||||
result = prime * result + Arrays.hashCode(Doubles);
|
result = prime * result + Arrays.hashCode(this.Doubles);
|
||||||
result = prime * result + Arrays.hashCode(Floats);
|
result = prime * result + Arrays.hashCode(this.Floats);
|
||||||
result = prime * result + Arrays.hashCode(Ints);
|
result = prime * result + Arrays.hashCode(this.Ints);
|
||||||
result = prime * result + Arrays.hashCode(Longs);
|
result = prime * result + Arrays.hashCode(this.Longs);
|
||||||
result = prime * result + Arrays.hashCode(Shorts);
|
result = prime * result + Arrays.hashCode(this.Shorts);
|
||||||
result = prime * result + Arrays.hashCode(booleans);
|
result = prime * result + Arrays.hashCode(this.booleans);
|
||||||
result = prime * result + Arrays.hashCode(bytes);
|
result = prime * result + Arrays.hashCode(this.bytes);
|
||||||
result = prime * result + Arrays.hashCode(chars);
|
result = prime * result + Arrays.hashCode(this.chars);
|
||||||
result = prime * result + Arrays.hashCode(doubles);
|
result = prime * result + Arrays.hashCode(this.doubles);
|
||||||
result = prime * result + Arrays.hashCode(floats);
|
result = prime * result + Arrays.hashCode(this.floats);
|
||||||
result = prime * result + Arrays.hashCode(ints);
|
result = prime * result + Arrays.hashCode(this.ints);
|
||||||
result = prime * result + (isTCP ? 1231 : 1237);
|
result = prime * result + (this.isTCP ? 1231 : 1237);
|
||||||
result = prime * result + Arrays.hashCode(longs);
|
result = prime * result + Arrays.hashCode(this.longs);
|
||||||
result = prime * result + Arrays.hashCode(shorts);
|
result = prime * result + Arrays.hashCode(this.shorts);
|
||||||
result = prime * result + (string == null ? 0 : string.hashCode());
|
result = prime * result + (this.string == null ? 0 : this.string.hashCode());
|
||||||
result = prime * result + Arrays.hashCode(strings);
|
result = prime * result + Arrays.hashCode(this.strings);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,65 +230,65 @@ public class UnregisteredClassTest extends BaseTest {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Data other = (Data)obj;
|
Data other = (Data)obj;
|
||||||
if (!Arrays.equals(Booleans, other.Booleans)) {
|
if (!Arrays.equals(this.Booleans, other.Booleans)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(Bytes, other.Bytes)) {
|
if (!Arrays.equals(this.Bytes, other.Bytes)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(Chars, other.Chars)) {
|
if (!Arrays.equals(this.Chars, other.Chars)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(Doubles, other.Doubles)) {
|
if (!Arrays.equals(this.Doubles, other.Doubles)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(Floats, other.Floats)) {
|
if (!Arrays.equals(this.Floats, other.Floats)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(Ints, other.Ints)) {
|
if (!Arrays.equals(this.Ints, other.Ints)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(Longs, other.Longs)) {
|
if (!Arrays.equals(this.Longs, other.Longs)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(Shorts, other.Shorts)) {
|
if (!Arrays.equals(this.Shorts, other.Shorts)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(booleans, other.booleans)) {
|
if (!Arrays.equals(this.booleans, other.booleans)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(bytes, other.bytes)) {
|
if (!Arrays.equals(this.bytes, other.bytes)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(chars, other.chars)) {
|
if (!Arrays.equals(this.chars, other.chars)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(doubles, other.doubles)) {
|
if (!Arrays.equals(this.doubles, other.doubles)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(floats, other.floats)) {
|
if (!Arrays.equals(this.floats, other.floats)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(ints, other.ints)) {
|
if (!Arrays.equals(this.ints, other.ints)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (isTCP != other.isTCP) {
|
if (this.isTCP != other.isTCP) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(longs, other.longs)) {
|
if (!Arrays.equals(this.longs, other.longs)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(shorts, other.shorts)) {
|
if (!Arrays.equals(this.shorts, other.shorts)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (string == null) {
|
if (this.string == null) {
|
||||||
if (other.string != null) {
|
if (other.string != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (!string.equals(other.string)) {
|
} else if (!this.string.equals(other.string)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(strings, other.strings)) {
|
if (!Arrays.equals(this.strings, other.strings)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -12,7 +12,7 @@ import dorkbox.network.ConnectionOptions;
|
|||||||
import dorkbox.network.BaseTest;
|
import dorkbox.network.BaseTest;
|
||||||
import dorkbox.network.Server;
|
import dorkbox.network.Server;
|
||||||
import dorkbox.network.connection.Connection;
|
import dorkbox.network.connection.Connection;
|
||||||
import dorkbox.network.connection.Listener;
|
import dorkbox.network.connection.ListenerRaw;
|
||||||
import dorkbox.network.util.SerializationManager;
|
import dorkbox.network.util.SerializationManager;
|
||||||
import dorkbox.network.util.exceptions.InitializationException;
|
import dorkbox.network.util.exceptions.InitializationException;
|
||||||
import dorkbox.network.util.exceptions.SecurityException;
|
import dorkbox.network.util.exceptions.SecurityException;
|
||||||
@ -52,7 +52,7 @@ public class RmiSendObjectTest extends BaseTest {
|
|||||||
serverRMI.register(42, serverTestObject);
|
serverRMI.register(42, serverTestObject);
|
||||||
serverRMI.register(777, serverTestObject.getOtherObject());
|
serverRMI.register(777, serverTestObject.getOtherObject());
|
||||||
|
|
||||||
server.listeners().add(new Listener<Connection, OtherObjectImpl>() {
|
server.listeners().add(new ListenerRaw<Connection, OtherObjectImpl>() {
|
||||||
@Override
|
@Override
|
||||||
public void connected(final Connection connection) {
|
public void connected(final Connection connection) {
|
||||||
// Allow the connection to access objects in the ObjectSpace.
|
// Allow the connection to access objects in the ObjectSpace.
|
||||||
@ -74,7 +74,7 @@ public class RmiSendObjectTest extends BaseTest {
|
|||||||
register(client.getSerialization());
|
register(client.getSerialization());
|
||||||
|
|
||||||
addEndPoint(client);
|
addEndPoint(client);
|
||||||
client.listeners().add(new Listener<Connection, Object>() {
|
client.listeners().add(new ListenerRaw<Connection, Object>() {
|
||||||
@Override
|
@Override
|
||||||
public void connected(final Connection connection) {
|
public void connected(final Connection connection) {
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
|
@ -4,17 +4,17 @@ package dorkbox.network.rmi;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import hive.common.Listener;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import dorkbox.network.BaseTest;
|
||||||
import dorkbox.network.Client;
|
import dorkbox.network.Client;
|
||||||
import dorkbox.network.ConnectionOptions;
|
import dorkbox.network.ConnectionOptions;
|
||||||
import dorkbox.network.BaseTest;
|
|
||||||
import dorkbox.network.Server;
|
import dorkbox.network.Server;
|
||||||
import dorkbox.network.connection.Connection;
|
import dorkbox.network.connection.Connection;
|
||||||
import dorkbox.network.connection.Listener;
|
|
||||||
import dorkbox.network.util.SerializationManager;
|
import dorkbox.network.util.SerializationManager;
|
||||||
import dorkbox.network.util.exceptions.InitializationException;
|
import dorkbox.network.util.exceptions.InitializationException;
|
||||||
import dorkbox.network.util.exceptions.SecurityException;
|
import dorkbox.network.util.exceptions.SecurityException;
|
||||||
@ -38,10 +38,10 @@ public class RmiTest extends BaseTest {
|
|||||||
addEndPoint(server);
|
addEndPoint(server);
|
||||||
server.bind(false);
|
server.bind(false);
|
||||||
|
|
||||||
server.listeners().add(new Listener<Connection, MessageWithTestObject>() {
|
server.listeners().add(new Listener<MessageWithTestObject>() {
|
||||||
@Override
|
@Override
|
||||||
public void received (Connection connection, MessageWithTestObject m) {
|
public void received (Connection connection, MessageWithTestObject m) {
|
||||||
assertEquals(SERVER_ID, m.testObject.other());
|
assertEquals(SERVER_ID, m.testObject.id());
|
||||||
System.err.println("Client Finished!");
|
System.err.println("Client Finished!");
|
||||||
|
|
||||||
runTest(connection, REMOTE_ID_ON_CLIENT, CLIENT_ID);
|
runTest(connection, REMOTE_ID_ON_CLIENT, CLIENT_ID);
|
||||||
@ -54,7 +54,7 @@ public class RmiTest extends BaseTest {
|
|||||||
register(client.getSerialization());
|
register(client.getSerialization());
|
||||||
|
|
||||||
addEndPoint(client);
|
addEndPoint(client);
|
||||||
client.listeners().add(new Listener<Connection, MessageWithTestObject>() {
|
client.listeners().add(new Listener<MessageWithTestObject>() {
|
||||||
@Override
|
@Override
|
||||||
public void connected (final Connection connection) {
|
public void connected (final Connection connection) {
|
||||||
RmiTest.runTest(connection, REMOTE_ID_ON_SERVER, SERVER_ID);
|
RmiTest.runTest(connection, REMOTE_ID_ON_SERVER, SERVER_ID);
|
||||||
@ -62,7 +62,7 @@ public class RmiTest extends BaseTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received (Connection connection, MessageWithTestObject m) {
|
public void received (Connection connection, MessageWithTestObject m) {
|
||||||
assertEquals(CLIENT_ID, m.testObject.other());
|
assertEquals(CLIENT_ID, m.testObject.id());
|
||||||
System.err.println("Server Finished!");
|
System.err.println("Server Finished!");
|
||||||
|
|
||||||
stopEndPoints(2000);
|
stopEndPoints(2000);
|
||||||
@ -96,7 +96,7 @@ public class RmiTest extends BaseTest {
|
|||||||
// (return values and exceptions are returned, call is synchronous)
|
// (return values and exceptions are returned, call is synchronous)
|
||||||
test.moo();
|
test.moo();
|
||||||
test.moo("Cow");
|
test.moo("Cow");
|
||||||
assertEquals(otherID, test.other());
|
assertEquals(otherID, test.id());
|
||||||
|
|
||||||
// Test that RMI correctly waits for the remotely invoked method to exit
|
// Test that RMI correctly waits for the remotely invoked method to exit
|
||||||
remoteObject.setResponseTimeout(5000);
|
remoteObject.setResponseTimeout(5000);
|
||||||
@ -118,7 +118,7 @@ public class RmiTest extends BaseTest {
|
|||||||
|
|
||||||
remoteObject.setTransmitReturnValue(false);
|
remoteObject.setTransmitReturnValue(false);
|
||||||
test.moo("Baa");
|
test.moo("Baa");
|
||||||
test.other();
|
test.id();
|
||||||
caught = false;
|
caught = false;
|
||||||
try {
|
try {
|
||||||
test.throwException();
|
test.throwException();
|
||||||
@ -131,16 +131,16 @@ public class RmiTest extends BaseTest {
|
|||||||
remoteObject.setNonBlocking(true);
|
remoteObject.setNonBlocking(true);
|
||||||
remoteObject.setTransmitReturnValue(false);
|
remoteObject.setTransmitReturnValue(false);
|
||||||
test.moo("Meow");
|
test.moo("Meow");
|
||||||
assertEquals(0, test.other());
|
assertEquals(0, test.id());
|
||||||
|
|
||||||
// Non-blocking call that returns the return value
|
// Non-blocking call that returns the return value
|
||||||
remoteObject.setTransmitReturnValue(true);
|
remoteObject.setTransmitReturnValue(true);
|
||||||
test.moo("Foo");
|
test.moo("Foo");
|
||||||
|
|
||||||
assertEquals(0, test.other());
|
assertEquals(0, test.id());
|
||||||
assertEquals(otherID, remoteObject.waitForLastResponse());
|
assertEquals(otherID, remoteObject.waitForLastResponse());
|
||||||
|
|
||||||
assertEquals(0, test.other());
|
assertEquals(0, test.id());
|
||||||
byte responseID = remoteObject.getLastResponseID();
|
byte responseID = remoteObject.getLastResponseID();
|
||||||
assertEquals(otherID, remoteObject.waitForResponse(responseID));
|
assertEquals(otherID, remoteObject.waitForResponse(responseID));
|
||||||
|
|
||||||
@ -184,15 +184,15 @@ public class RmiTest extends BaseTest {
|
|||||||
|
|
||||||
public void moo (String value, long delay);
|
public void moo (String value, long delay);
|
||||||
|
|
||||||
public int other ();
|
public int id ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static public class TestObjectImpl implements TestObject {
|
static public class TestObjectImpl implements TestObject {
|
||||||
public long value = System.currentTimeMillis();
|
public long value = System.currentTimeMillis();
|
||||||
private final int other;
|
private final int id;
|
||||||
|
|
||||||
public TestObjectImpl (int other) {
|
public TestObjectImpl (int id) {
|
||||||
this.other = other;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -222,8 +222,8 @@ public class RmiTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int other () {
|
public int id () {
|
||||||
return other;
|
return this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user