diff --git a/.classpath b/.classpath index e411d423..1c1b2603 100644 --- a/.classpath +++ b/.classpath @@ -1,11 +1,27 @@ - + + + + + + - - - - - - + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore index a30a0043..5a68b4a3 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ bin/ target/ .idea/ *.iml +/dependency-reduced-pom.xml \ No newline at end of file diff --git a/.project b/.project index fdaa1ae5..9ba7aa44 100644 --- a/.project +++ b/.project @@ -10,8 +10,14 @@ + + org.eclipse.m2e.core.maven2Builder + + + + org.eclipse.m2e.core.maven2Nature org.eclipse.jdt.core.javanature - + \ No newline at end of file diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000..b2bfc6e6 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 +encoding/src=UTF-8 +encoding/test=UTF-8 \ No newline at end of file diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 184ea2a4..7b8c1002 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,7 +1,12 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 -org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.doc.comment.support=enabled org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning org.eclipse.jdt.core.compiler.problem.assertIdentifier=error @@ -79,4 +84,4 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=enab org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=ignore org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.7 +org.eclipse.jdt.core.compiler.source=1.8 \ No newline at end of file diff --git a/build/junit-4.12.jar b/build/junit-4.12.jar new file mode 100644 index 00000000..3a7fc266 Binary files /dev/null and b/build/junit-4.12.jar differ diff --git a/build/junit-4.6.jar b/build/junit-4.6.jar deleted file mode 100644 index 00770a4f..00000000 Binary files a/build/junit-4.6.jar and /dev/null differ diff --git a/build/minlog-1.3.0.jar b/build/minlog-1.3.0.jar new file mode 100644 index 00000000..ec67b63e Binary files /dev/null and b/build/minlog-1.3.0.jar differ diff --git a/build/minlog-none-1.2.jar b/build/minlog-none-1.2.jar deleted file mode 100644 index 50bd8d2c..00000000 Binary files a/build/minlog-none-1.2.jar and /dev/null differ diff --git a/build/objenesis-2.1.jar b/build/objenesis-2.1.jar new file mode 100644 index 00000000..7c1e9837 Binary files /dev/null and b/build/objenesis-2.1.jar differ diff --git a/build/reflectasm-1.10.1-shaded.jar b/build/reflectasm-1.10.1-shaded.jar new file mode 100644 index 00000000..7476612b Binary files /dev/null and b/build/reflectasm-1.10.1-shaded.jar differ diff --git a/lib/jsonbeans-0.5.jar b/lib/jsonbeans-0.5.jar deleted file mode 100644 index 1dcd9d85..00000000 Binary files a/lib/jsonbeans-0.5.jar and /dev/null differ diff --git a/lib/jsonbeans-0.7.jar b/lib/jsonbeans-0.7.jar new file mode 100644 index 00000000..523b4b57 Binary files /dev/null and b/lib/jsonbeans-0.7.jar differ diff --git a/lib/kryo-2.23.1-SNAPSHOT-all-debug.jar b/lib/kryo-2.23.1-SNAPSHOT-all-debug.jar deleted file mode 100644 index 30112ce3..00000000 Binary files a/lib/kryo-2.23.1-SNAPSHOT-all-debug.jar and /dev/null differ diff --git a/lib/kryo-4.0.2.jar b/lib/kryo-4.0.2.jar new file mode 100644 index 00000000..85bb0507 Binary files /dev/null and b/lib/kryo-4.0.2.jar differ diff --git a/pom.xml b/pom.xml index 29fffde8..c075a31b 100644 --- a/pom.xml +++ b/pom.xml @@ -1,68 +1,110 @@ - - - org.sonatype.oss - oss-parent - 7 - - 4.0.0 + + + org.sonatype.oss + oss-parent + 9 + + 4.0.0 - com.esotericsoftware - kryonet - 2.22.0-RC1 - jar + com.esotericsoftware + kryonet + 3.0.0 + jar - kryonet - TCP and UDP client/server library for Java - https://github.com/EsotericSoftware/kryonet + kryonet + TCP and UDP client/server library for Java + https://github.com/EsotericSoftware/kryonet - - - New BSD License - http://www.opensource.org/licenses/bsd-license.php - repo - - + + + New BSD License + http://www.opensource.org/licenses/bsd-license.php + repo + + - - - nathan.sweet - Nathan Sweet - nathan.sweet@gmail.com - - + + + nathan.sweet + Nathan Sweet + nathan.sweet@gmail.com + + - - https://github.com/EsotericSoftware/kryonet - scm:git:https://github.com/EsotericSoftware/kryonet.git - scm:git:https://github.com/EsotericSoftware/kryonet.git - HEAD - + + https://github.com/EsotericSoftware/kryonet + scm:git:https://github.com/EsotericSoftware/kryonet.git + scm:git:https://github.com/EsotericSoftware/kryonet.git + HEAD + - - - src - test + + + src + test - + + + ${basedir}/src + + **/*.java + + + - - - com.esotericsoftware.kryo - kryo - 2.24.0 - - - com.esotericsoftware - jsonbeans - 0.7 - - - junit - junit - 4.11 - test - + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 12 + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.1 + + + + + + package + + shade + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + + + + + + + com.esotericsoftware + kryo + 4.0.2 + + + com.esotericsoftware + jsonbeans + 0.7 + + + junit + junit + 4.12 + test + - + \ No newline at end of file diff --git a/src/com/esotericsoftware/kryonet/Client.java b/src/com/esotericsoftware/kryonet/Client.java index ef0bd55a..948b8080 100644 --- a/src/com/esotericsoftware/kryonet/Client.java +++ b/src/com/esotericsoftware/kryonet/Client.java @@ -1,15 +1,15 @@ /* Copyright (c) 2008, Nathan Sweet * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following * conditions are met: - * + * * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided with the distribution. * - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL @@ -100,7 +100,8 @@ public Client (int writeBufferSize, int objectBufferSize, Serialization serializ this.serialization = serialization; - this.discoveryHandler = ClientDiscoveryHandler.DEFAULT; + this.discoveryHandler = new ClientDiscoveryHandler() { + }; initialize(serialization, writeBufferSize, objectBufferSize); @@ -120,7 +121,7 @@ public Serialization getSerialization () { } public Kryo getKryo () { - return serialization instanceof KryoSerialization ? ((KryoSerialization)serialization).getKryo() : null; + return ((KryoSerialization)serialization).getKryo(); } /** Opens a TCP only client. @@ -472,8 +473,7 @@ private void broadcast (int udpPort, DatagramSocket socket) throws IOException { if (DEBUG) debug("kryonet", "Broadcasted host discovery on port: " + udpPort); } - /** Broadcasts a UDP message on the LAN to discover any running servers. The address of the first server to respond is - * returned. + /** Broadcasts a UDP message on the LAN to discover any running servers. The address of the first server to respond is returned. * @param udpPort The UDP port of the server. * @param timeoutMillis The number of milliseconds to wait for a response. * @return the first server found, or null if no server responded. */ @@ -532,4 +532,4 @@ public List discoverHosts (int udpPort, int timeoutMillis) { discoveryHandler.onFinally(); } } -} +} \ No newline at end of file diff --git a/src/com/esotericsoftware/kryonet/ClientDiscoveryHandler.java b/src/com/esotericsoftware/kryonet/ClientDiscoveryHandler.java index 75d1472b..22ed34e4 100644 --- a/src/com/esotericsoftware/kryonet/ClientDiscoveryHandler.java +++ b/src/com/esotericsoftware/kryonet/ClientDiscoveryHandler.java @@ -1,15 +1,15 @@ /* Copyright (c) 2008, Nathan Sweet * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following * conditions are met: - * + * * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided with the distribution. * - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL @@ -25,32 +25,37 @@ import com.esotericsoftware.kryo.io.Input; public interface ClientDiscoveryHandler { - /** This implementation of the {@link ClientDiscoveryHandler} is responsible for providing the {@link Client} with it's default - * behavior. */ - public static final ClientDiscoveryHandler DEFAULT = new ClientDiscoveryHandler() { - public DatagramPacket onRequestNewDatagramPacket () { - return new DatagramPacket(new byte[0], 0); - } - - public void onDiscoveredHost (DatagramPacket datagramPacket, Kryo kryo) { - } - - public void onFinally () { - } + + /** + * Implementations of this method should return a new {@link DatagramPacket} + * that the {@link Client} will use to fill with the incoming packet data + * sent by the {@link ServerDiscoveryHandler}. + * + * @return a new {@link DatagramPacket} + */ + public default DatagramPacket onRequestNewDatagramPacket() { + return new DatagramPacket(new byte[0], 0); + }; + + /** + * Called when the {@link Client} discovers a host. + * + * @param datagramPacket + * the same {@link DatagramPacket} from + * {@link #onRequestNewDatagramPacket()}, after being filled with + * the incoming packet data. + * @param kryo + * the {@link Kryo} instance + */ + public default void onDiscoveredHost(DatagramPacket datagramPacket, Kryo kryo) { + }; + + /** + * Called right before the {@link Client#discoverHost(int, int)} or + * {@link Client#discoverHosts(int, int)} method exits. This allows the + * implementation to clean up any resources used, i.e. an {@link Input}. + */ + public default void onFinally() { }; - /** Implementations of this method should return a new {@link DatagramPacket} that the {@link Client} will use to fill with the - * incoming packet data sent by the {@link ServerDiscoveryHandler}. - * @return a new {@link DatagramPacket} */ - public DatagramPacket onRequestNewDatagramPacket (); - - /** Called when the {@link Client} discovers a host. - * @param datagramPacket the same {@link DatagramPacket} from {@link #onRequestNewDatagramPacket()}, after being filled with - * the incoming packet data. - * @param kryo the {@link Kryo} instance, or null. */ - public void onDiscoveredHost (DatagramPacket datagramPacket, Kryo kryo); - - /** Called right before the {@link Client#discoverHost(int, int)} or {@link Client#discoverHosts(int, int)} method exits. This - * allows the implementation to clean up any resources used, i.e. an {@link Input}. */ - public void onFinally (); -} +} \ No newline at end of file diff --git a/src/com/esotericsoftware/kryonet/Connection.java b/src/com/esotericsoftware/kryonet/Connection.java index 13934ed5..1501aad6 100644 --- a/src/com/esotericsoftware/kryonet/Connection.java +++ b/src/com/esotericsoftware/kryonet/Connection.java @@ -1,15 +1,15 @@ /* Copyright (c) 2008, Nathan Sweet * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following * conditions are met: - * + * * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided with the distribution. * - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL @@ -68,10 +68,10 @@ public int getID () { public boolean isConnected () { return isConnected; } - + /** * Returns the last protocol error that occured on the connection. - * + * * @return The last protocol error or null if none error occured. */ public KryoNetException getLastProtocolError() { @@ -337,4 +337,30 @@ void setConnected (boolean isConnected) { this.isConnected = isConnected; if (isConnected && name == null) name = "Connection " + id; } -} + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + id; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Connection other = (Connection) obj; + if (id != other.id) { + return false; + } + return true; + } +} \ No newline at end of file diff --git a/src/com/esotericsoftware/kryonet/Listener.java b/src/com/esotericsoftware/kryonet/Listener.java index bd9ab148..ab7e7095 100644 --- a/src/com/esotericsoftware/kryonet/Listener.java +++ b/src/com/esotericsoftware/kryonet/Listener.java @@ -1,15 +1,15 @@ /* Copyright (c) 2008, Nathan Sweet * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following * conditions are met: - * + * * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided with the distribution. * - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL @@ -31,31 +31,31 @@ import static com.esotericsoftware.minlog.Log.*; /** Used to be notified about connection events. */ -public class Listener { +public interface Listener { /** Called when the remote end has been connected. This will be invoked before any objects are received by * {@link #received(Connection, Object)}. This will be invoked on the same thread as {@link Client#update(int)} and * {@link Server#update(int)}. This method should not block for long periods as other network activity will not be processed * until it returns. */ - public void connected (Connection connection) { - } + public default void connected (Connection connection) { + }; /** Called when the remote end is no longer connected. There is no guarantee as to what thread will invoke this method. */ - public void disconnected (Connection connection) { - } + public default void disconnected (Connection connection) { + }; /** Called when an object has been received from the remote end of the connection. This will be invoked on the same thread as * {@link Client#update(int)} and {@link Server#update(int)}. This method should not block for long periods as other network * activity will not be processed until it returns. */ - public void received (Connection connection, Object object) { - } + public default void received (Connection connection, Object object) { + }; /** Called when the connection is below the {@link Connection#setIdleThreshold(float) idle threshold}. */ - public void idle (Connection connection) { - } + public default void idle (Connection connection) { + }; /** Uses reflection to called "received(Connection, XXX)" on the listener, where XXX is the received object type. Note this * class uses a HashMap lookup and (cached) reflection, so is not as efficient as writing a series of "instanceof" statements. */ - static public class ReflectionListener extends Listener { + static public class ReflectionListener implements Listener { private final HashMap classToMethod = new HashMap(); public void received (Connection connection, Object object) { @@ -91,7 +91,7 @@ public void received (Connection connection, Object object) { /** Wraps a listener and queues notifications as {@link Runnable runnables}. This allows the runnables to be processed on a * different thread, preventing the connection's update thread from being blocked. */ - static public abstract class QueuedListener extends Listener { + static public abstract class QueuedListener implements Listener { final Listener listener; public QueuedListener (Listener listener) { @@ -186,4 +186,4 @@ public void run () { }, lag, TimeUnit.MILLISECONDS); } } -} +} \ No newline at end of file diff --git a/src/com/esotericsoftware/kryonet/Server.java b/src/com/esotericsoftware/kryonet/Server.java index f5cabd3e..9c617900 100644 --- a/src/com/esotericsoftware/kryonet/Server.java +++ b/src/com/esotericsoftware/kryonet/Server.java @@ -1,15 +1,15 @@ /* Copyright (c) 2008, Nathan Sweet * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following * conditions are met: - * + * * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided with the distribution. * - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL @@ -115,7 +115,8 @@ public Server (int writeBufferSize, int objectBufferSize, Serialization serializ this.serialization = serialization; - this.discoveryHandler = ServerDiscoveryHandler.DEFAULT; + this.discoveryHandler = new ServerDiscoveryHandler() { + }; try { selector = Selector.open(); @@ -133,7 +134,7 @@ public Serialization getSerialization () { } public Kryo getKryo () { - return serialization instanceof KryoSerialization ? ((KryoSerialization)serialization).getKryo() : null; + return ((KryoSerialization)serialization).getKryo(); } /** Opens a TCP only server. @@ -317,8 +318,9 @@ public void update (int timeout) throws IOException { connection.udpRemoteAddress = fromAddress; addConnection(connection); connection.sendTCP(new RegisterUDP()); - if (DEBUG) debug("kryonet", - "Port " + udp.datagramChannel.socket().getLocalPort() + "/UDP connected to: " + fromAddress); + if (DEBUG) + debug("kryonet", "Port " + udp.datagramChannel.socket().getLocalPort() + "/UDP connected to: " + + fromAddress); connection.notifyConnected(); continue; } @@ -328,8 +330,8 @@ public void update (int timeout) throws IOException { } if (object instanceof DiscoverHost) { try { - boolean responseSent = discoveryHandler.onDiscoverHost(udp.datagramChannel, fromAddress, - serialization); + boolean responseSent = discoveryHandler + .onDiscoverHost(udp.datagramChannel, fromAddress, serialization); if (DEBUG && responseSent) debug("kryonet", "Responded to host discovery from: " + fromAddress); } catch (IOException ex) { if (WARN) warn("kryonet", "Error replying to host discovery from: " + fromAddress, ex); @@ -597,4 +599,4 @@ public Thread getUpdateThread () { public Connection[] getConnections () { return connections; } -} +} \ No newline at end of file diff --git a/src/com/esotericsoftware/kryonet/ServerDiscoveryHandler.java b/src/com/esotericsoftware/kryonet/ServerDiscoveryHandler.java index 42fa6864..7d7278bc 100644 --- a/src/com/esotericsoftware/kryonet/ServerDiscoveryHandler.java +++ b/src/com/esotericsoftware/kryonet/ServerDiscoveryHandler.java @@ -1,15 +1,15 @@ /* Copyright (c) 2008, Nathan Sweet * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following * conditions are met: - * + * * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided with the distribution. * - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL @@ -27,24 +27,15 @@ import com.esotericsoftware.kryonet.FrameworkMessage.DiscoverHost; public interface ServerDiscoveryHandler { - /** This implementation of {@link ServerDiscoveryHandler} is responsible for providing the {@link Server} with it's default - * behavior. */ - public static final ServerDiscoveryHandler DEFAULT = new ServerDiscoveryHandler() { - private ByteBuffer emptyBuffer = ByteBuffer.allocate(0); - - @Override - public boolean onDiscoverHost (DatagramChannel datagramChannel, InetSocketAddress fromAddress, Serialization serialization) - throws IOException { - datagramChannel.send(emptyBuffer, fromAddress); - return true; - } - }; /** Called when the {@link Server} receives a {@link DiscoverHost} packet. * @param fromAddress {@link InetSocketAddress} the {@link DiscoverHost} came from * @param serialization the {@link Server}'s {@link Serialization} instance * @return true if a response was sent to {@code fromAddress}, false otherwise * @throws IOException from the use of {@link DatagramChannel#send(ByteBuffer, java.net.SocketAddress)} */ - public boolean onDiscoverHost (DatagramChannel datagramChannel, InetSocketAddress fromAddress, Serialization serialization) - throws IOException; -} + public default boolean onDiscoverHost (DatagramChannel datagramChannel, InetSocketAddress fromAddress, Serialization serialization) + throws IOException { + datagramChannel.send(ByteBuffer.allocate(0), fromAddress); + return true; + }; +} \ No newline at end of file diff --git a/src/com/esotericsoftware/kryonet/UdpConnection.java b/src/com/esotericsoftware/kryonet/UdpConnection.java index 64a423d7..a1cf8ca8 100644 --- a/src/com/esotericsoftware/kryonet/UdpConnection.java +++ b/src/com/esotericsoftware/kryonet/UdpConnection.java @@ -155,4 +155,4 @@ public void close () { public boolean needsKeepAlive (long time) { return connectedAddress != null && keepAliveMillis > 0 && time - lastCommunicationTime > keepAliveMillis; } -} +} \ No newline at end of file diff --git a/src/com/esotericsoftware/kryonet/util/TcpIdleSender.java b/src/com/esotericsoftware/kryonet/util/TcpIdleSender.java index fc43cb31..06bc4a45 100644 --- a/src/com/esotericsoftware/kryonet/util/TcpIdleSender.java +++ b/src/com/esotericsoftware/kryonet/util/TcpIdleSender.java @@ -1,15 +1,15 @@ /* Copyright (c) 2008, Nathan Sweet * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following * conditions are met: - * + * * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided with the distribution. * - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL @@ -22,7 +22,7 @@ import com.esotericsoftware.kryonet.Connection; import com.esotericsoftware.kryonet.Listener; -abstract public class TcpIdleSender extends Listener { +abstract public class TcpIdleSender implements Listener { boolean started; public void idle (Connection connection) { @@ -44,4 +44,4 @@ protected void start () { /** Returns the next object to send, or null if no more objects will be sent. */ abstract protected Object next (); -} +} \ No newline at end of file diff --git a/test/com/esotericsoftware/kryonet/BufferTest.java b/test/com/esotericsoftware/kryonet/BufferTest.java index f28f8d43..6063cfd6 100644 --- a/test/com/esotericsoftware/kryonet/BufferTest.java +++ b/test/com/esotericsoftware/kryonet/BufferTest.java @@ -25,8 +25,6 @@ import com.esotericsoftware.kryo.Kryo; public class BufferTest extends KryoNetTestCase { - AtomicInteger received = new AtomicInteger(); - AtomicInteger receivedBytes = new AtomicInteger(); public void testManyLargeMessages () throws IOException { final int messageCount = 1024; @@ -42,6 +40,7 @@ public void testManyLargeMessages () throws IOException { AtomicInteger received = new AtomicInteger(); AtomicInteger receivedBytes = new AtomicInteger(); + @Override public void received (Connection connection, Object object) { if (object instanceof LargeMessage) { System.out.println("Server sending message: " + received.get()); @@ -68,6 +67,7 @@ public void received (Connection connection, Object object) { AtomicInteger received = new AtomicInteger(); AtomicInteger receivedBytes = new AtomicInteger(); + @Override public void received (Connection connection, Object object) { if (object instanceof LargeMessage) { int count = received.incrementAndGet(); @@ -97,12 +97,12 @@ private void register (Kryo kryo) { } public static class LargeMessage { - public byte[] bytes; + byte[] bytes; public LargeMessage () { } - public LargeMessage (byte[] bytes) { + LargeMessage(byte[] bytes) { this.bytes = bytes; } } diff --git a/test/com/esotericsoftware/kryonet/DiscoverHostTest.java b/test/com/esotericsoftware/kryonet/DiscoverHostTest.java index 3934d540..cfd70f9e 100644 --- a/test/com/esotericsoftware/kryonet/DiscoverHostTest.java +++ b/test/com/esotericsoftware/kryonet/DiscoverHostTest.java @@ -1,15 +1,15 @@ /* Copyright (c) 2008, Nathan Sweet * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following * conditions are met: - * + * * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided with the distribution. * - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL @@ -44,6 +44,7 @@ public void testBroadcast () throws IOException { startEndPoint(server); server.bind(54555); server.addListener(new Listener() { + @Override public void disconnected (Connection connection) { broadcastServer.stop(); server.stop(); @@ -138,6 +139,7 @@ public void onFinally () { startEndPoint(server); server.bind(54555); server.addListener(new Listener() { + @Override public void disconnected (Connection connection) { broadcastServer.stop(); server.stop(); @@ -167,13 +169,13 @@ public void disconnected (Connection connection) { public static class DiscoveryResponsePacket { - public DiscoveryResponsePacket () { + DiscoveryResponsePacket() { // } - public int id; - public String gameName; - public String playerName; + int id; + String gameName; + String playerName; } -} +} \ No newline at end of file diff --git a/test/com/esotericsoftware/kryonet/InputStreamSenderTest.java b/test/com/esotericsoftware/kryonet/InputStreamSenderTest.java index 3d0bd9a2..e719e508 100644 --- a/test/com/esotericsoftware/kryonet/InputStreamSenderTest.java +++ b/test/com/esotericsoftware/kryonet/InputStreamSenderTest.java @@ -26,7 +26,7 @@ import com.esotericsoftware.kryonet.util.InputStreamSender; public class InputStreamSenderTest extends KryoNetTestCase { - boolean success; + private boolean success; public void testStream () throws IOException { final int largeDataSize = 12345; @@ -36,6 +36,7 @@ public void testStream () throws IOException { startEndPoint(server); server.bind(tcpPort, udpPort); server.addListener(new Listener() { + @Override public void connected (Connection connection) { ByteArrayOutputStream output = new ByteArrayOutputStream(largeDataSize); for (int i = 0; i < largeDataSize; i++) @@ -43,11 +44,13 @@ public void connected (Connection connection) { ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray()); // Send data in 512 byte chunks. connection.addListener(new InputStreamSender(input, 512) { + @Override protected void start () { // Normally would send an object so the receiving side knows how to handle the chunks we are about to send. System.out.println("starting"); } + @Override protected Object next (byte[] bytes) { System.out.println("sending " + bytes.length); return bytes; // Normally would wrap the byte[] with an object so the receiving side knows how to handle it. @@ -64,6 +67,7 @@ protected Object next (byte[] bytes) { client.addListener(new Listener() { int total; + @Override public void received (Connection connection, Object object) { if (object instanceof byte[]) { int length = ((byte[])object).length; diff --git a/test/com/esotericsoftware/kryonet/JsonTest.java b/test/com/esotericsoftware/kryonet/JsonTest.java index 9cbd024b..50f4dd22 100644 --- a/test/com/esotericsoftware/kryonet/JsonTest.java +++ b/test/com/esotericsoftware/kryonet/JsonTest.java @@ -19,14 +19,12 @@ package com.esotericsoftware.kryonet; -import com.esotericsoftware.jsonbeans.JsonWriter; import java.io.IOException; -import java.io.StringWriter; import java.util.Arrays; public class JsonTest extends KryoNetTestCase { - String fail; + private String fail; public void testJson () throws IOException { fail = null; @@ -40,11 +38,13 @@ public void testJson () throws IOException { startEndPoint(server); server.bind(tcpPort, udpPort); server.addListener(new Listener() { + @Override public void connected (Connection connection) { connection.sendTCP(dataTCP); connection.sendUDP(dataUDP); // Note UDP ping pong stops if a UDP packet is lost. } + @Override public void received (Connection connection, Object object) { if (object instanceof Data) { Data data = (Data)object; @@ -70,6 +70,7 @@ public void received (Connection connection, Object object) { final Client client = new Client(16384, 8192, new JsonSerialization()); startEndPoint(client); client.addListener(new Listener() { + @Override public void received (Connection connection, Object object) { if (object instanceof Data) { Data data = (Data)object; @@ -100,9 +101,8 @@ public void received (Connection connection, Object object) { private void populateData (Data data, boolean isTCP) { data.isTCP = isTCP; - StringBuffer buffer = new StringBuffer(); - for (int i = 0; i < 3000; i++) - buffer.append('a'); + StringBuilder buffer = new StringBuilder(); + buffer.append("a".repeat(3000)); data.string = buffer.toString(); data.strings = new String[] {"abcdefghijklmnopqrstuvwxyz0123456789", "", null, "!@#$", "�����"}; @@ -121,19 +121,19 @@ private void populateData (Data data, boolean isTCP) { static public class Data { public String string; - public String[] strings; - public int[] ints; - public short[] shorts; - public float[] floats; - public byte[] bytes; - public boolean[] booleans; - public Integer[] Ints; - public Short[] Shorts; - public Float[] Floats; - public Byte[] Bytes; - public Boolean[] Booleans; - public boolean isTCP; - + String[] strings; + int[] ints; + short[] shorts;float[] floats; + byte[] bytes; + boolean[] booleans; + Integer[] Ints; + Short[] Shorts; + Float[] Floats; + Byte[] Bytes; + Boolean[] Booleans; + boolean isTCP; + + @Override public int hashCode () { final int prime = 31; int result = 1; @@ -153,6 +153,7 @@ public int hashCode () { return result; } + @Override public boolean equals (Object obj) { if (this == obj) return true; if (obj == null) return false; @@ -172,10 +173,10 @@ public boolean equals (Object obj) { if (string == null) { if (other.string != null) return false; } else if (!string.equals(other.string)) return false; - if (!Arrays.equals(strings, other.strings)) return false; - return true; + return Arrays.equals(strings, other.strings); } + @Override public String toString () { return "Data"; } diff --git a/test/com/esotericsoftware/kryonet/KryoNetBufferUnderflowTest.java b/test/com/esotericsoftware/kryonet/KryoNetBufferUnderflowTest.java index 622df42a..4a81e968 100644 --- a/test/com/esotericsoftware/kryonet/KryoNetBufferUnderflowTest.java +++ b/test/com/esotericsoftware/kryonet/KryoNetBufferUnderflowTest.java @@ -1,15 +1,15 @@ /* Copyright (c) 2008, Nathan Sweet * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following * conditions are met: - * + * * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided with the distribution. * - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL @@ -54,7 +54,7 @@ public void received (Connection connection, Object object) { // Catching exception Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { - @Override + @Override public void uncaughtException (Thread t, Throwable e) { e.printStackTrace(); received.set(true); @@ -86,4 +86,4 @@ public void uncaughtException (Thread t, Throwable e) { Thread.sleep(100); } } -} +} \ No newline at end of file diff --git a/test/com/esotericsoftware/kryonet/KryoNetTestCase.java b/test/com/esotericsoftware/kryonet/KryoNetTestCase.java index 036a742b..78ad6437 100644 --- a/test/com/esotericsoftware/kryonet/KryoNetTestCase.java +++ b/test/com/esotericsoftware/kryonet/KryoNetTestCase.java @@ -33,15 +33,16 @@ abstract public class KryoNetTestCase extends TestCase { static public String host = "localhost"; static public int tcpPort = 54555, udpPort = 54777; - private ArrayList threads = new ArrayList(); - ArrayList endPoints = new ArrayList(); + private ArrayList threads = new ArrayList<>(); + private ArrayList endPoints = new ArrayList<>(); private Timer timer; - boolean fail; + private boolean fail; public KryoNetTestCase () { // Log.TRACE(); // Log.DEBUG(); Log.setLogger(new Logger() { + @Override public void log (int level, String category, String message, Throwable ex) { // if (category == null || category.equals("kryonet")) // super.log(level, category, message, ex); @@ -49,11 +50,13 @@ public void log (int level, String category, String message, Throwable ex) { }); } + @Override protected void setUp () throws Exception { System.out.println("---- " + getClass().getSimpleName()); timer = new Timer(); } + @Override protected void tearDown () throws Exception { timer.cancel(); } @@ -71,9 +74,9 @@ public void stopEndPoints () { public void stopEndPoints (int stopAfterMillis) { timer.schedule(new TimerTask() { + @Override public void run () { - for (EndPoint endPoint : endPoints) - endPoint.stop(); + endPoints.forEach(EndPoint::stop); endPoints.clear(); } }, stopAfterMillis); @@ -88,6 +91,7 @@ public void waitForThreads (int stopAfterMillis) { public void waitForThreads () { fail = false; TimerTask failTask = new TimerTask() { + @Override public void run () { stopEndPoints(); fail = true; @@ -95,9 +99,9 @@ public void run () { }; timer.schedule(failTask, 11000); while (true) { - for (Iterator iter = threads.iterator(); iter.hasNext();) { - Thread thread = (Thread)iter.next(); - if (!thread.isAlive()) iter.remove(); + for (Iterator iterator = threads.iterator(); iterator.hasNext();) { + Thread thread = (Thread)iterator.next(); + if (!thread.isAlive()) iterator.remove(); } if (threads.isEmpty()) break; try { @@ -113,4 +117,4 @@ public void run () { } catch (InterruptedException ignored) { } } -} +} \ No newline at end of file diff --git a/test/com/esotericsoftware/kryonet/MultipleServerTest.java b/test/com/esotericsoftware/kryonet/MultipleServerTest.java index a1bfd48a..498cb8ac 100644 --- a/test/com/esotericsoftware/kryonet/MultipleServerTest.java +++ b/test/com/esotericsoftware/kryonet/MultipleServerTest.java @@ -26,7 +26,7 @@ import com.esotericsoftware.kryo.Kryo; public class MultipleServerTest extends KryoNetTestCase { - AtomicInteger received = new AtomicInteger(); + private AtomicInteger received = new AtomicInteger(); public void testMultipleThreads () throws IOException { final Server server1 = new Server(16384, 8192); @@ -34,6 +34,7 @@ public void testMultipleThreads () throws IOException { startEndPoint(server1); server1.bind(tcpPort, udpPort); server1.addListener(new Listener() { + @Override public void received (Connection connection, Object object) { if (object instanceof String) { if (!object.equals("client1")) fail(); @@ -47,6 +48,7 @@ public void received (Connection connection, Object object) { startEndPoint(server2); server2.bind(tcpPort + 1, udpPort + 1); server2.addListener(new Listener() { + @Override public void received (Connection connection, Object object) { if (object instanceof String) { if (!object.equals("client2")) fail(); @@ -61,6 +63,7 @@ public void received (Connection connection, Object object) { client1.getKryo().register(String[].class); startEndPoint(client1); client1.addListener(new Listener() { + @Override public void connected (Connection connection) { connection.sendTCP("client1"); } @@ -71,6 +74,7 @@ public void connected (Connection connection) { client2.getKryo().register(String[].class); startEndPoint(client2); client2.addListener(new Listener() { + @Override public void connected (Connection connection) { connection.sendTCP("client2"); } diff --git a/test/com/esotericsoftware/kryonet/MultipleThreadTest.java b/test/com/esotericsoftware/kryonet/MultipleThreadTest.java index 6c28ac79..6b5b7e61 100644 --- a/test/com/esotericsoftware/kryonet/MultipleThreadTest.java +++ b/test/com/esotericsoftware/kryonet/MultipleThreadTest.java @@ -25,7 +25,7 @@ import com.esotericsoftware.kryo.Kryo; public class MultipleThreadTest extends KryoNetTestCase { - int receivedServer, receivedClient1, receivedClient2; + private int receivedServer; public void testMultipleThreads () throws IOException { receivedServer = 0; @@ -40,6 +40,7 @@ public void testMultipleThreads () throws IOException { startEndPoint(server); server.bind(tcpPort, udpPort); server.addListener(new Listener() { + @Override public void received (Connection connection, Object object) { receivedServer++; if (receivedServer == messageCount * clients) stopEndPoints(); @@ -55,6 +56,7 @@ public void received (Connection connection, Object object) { client.addListener(new Listener() { int received; + @Override public void received (Connection connection, Object object) { if (object instanceof String) { received++; @@ -75,11 +77,11 @@ public void received (Connection connection, Object object) { for (int i = 0; i < threads; i++) { new Thread() { + @Override public void run () { Connection[] connections = server.getConnections(); for (int i = 0; i < messageCount; i++) { - for (int ii = 0, n = connections.length; ii < n; ii++) - connections[ii].sendTCP("message" + i); + for (Connection connection : connections) connection.sendTCP("message" + i); try { Thread.sleep(sleepMillis); } catch (InterruptedException ignored) { diff --git a/test/com/esotericsoftware/kryonet/PingPongTest.java b/test/com/esotericsoftware/kryonet/PingPongTest.java index 996c584c..6b7d6459 100644 --- a/test/com/esotericsoftware/kryonet/PingPongTest.java +++ b/test/com/esotericsoftware/kryonet/PingPongTest.java @@ -25,7 +25,7 @@ import com.esotericsoftware.kryo.Kryo; public class PingPongTest extends KryoNetTestCase { - String fail; + private String fail; public void testPingPong () throws IOException { fail = null; @@ -40,11 +40,13 @@ public void testPingPong () throws IOException { startEndPoint(server); server.bind(tcpPort, udpPort); server.addListener(new Listener() { + @Override public void connected (Connection connection) { connection.sendTCP(dataTCP); connection.sendUDP(dataUDP); // Note UDP ping pong stops if a UDP packet is lost. } + @Override public void received (Connection connection, Object object) { if (object instanceof Data) { Data data = (Data)object; @@ -71,6 +73,7 @@ public void received (Connection connection, Object object) { register(client.getKryo()); startEndPoint(client); client.addListener(new Listener() { + @Override public void received (Connection connection, Object object) { if (object instanceof Data) { Data data = (Data)object; @@ -99,10 +102,7 @@ public void received (Connection connection, Object object) { private void populateData (Data data, boolean isTCP) { data.isTCP = isTCP; - StringBuffer buffer = new StringBuffer(); - for (int i = 0; i < 3000; i++) - buffer.append('a'); - data.string = buffer.toString(); + data.string = "a".repeat(3000); data.strings = new String[] {"abcdefghijklmnopqrstuvwxyz0123456789", "", null, "!@#$", "�����"}; data.ints = new int[] {-1234567, 1234567, -1, 0, 1, Integer.MAX_VALUE, Integer.MIN_VALUE}; @@ -110,7 +110,7 @@ private void populateData (Data data, boolean isTCP) { data.floats = new float[] {0, -0, 1, -1, 123456, -123456, 0.1f, 0.2f, -0.3f, (float)Math.PI, Float.MAX_VALUE, Float.MIN_VALUE}; data.doubles = new double[] {0, -0, 1, -1, 123456, -123456, 0.1d, 0.2d, -0.3d, Math.PI, Double.MAX_VALUE, Double.MIN_VALUE}; - data.longs = new long[] {0, -0, 1, -1, 123456, -123456, 99999999999l, -99999999999l, Long.MAX_VALUE, Long.MIN_VALUE}; + data.longs = new long[] {0, -0, 1, -1, 123456, -123456, 99999999999L, -99999999999L, Long.MAX_VALUE, Long.MIN_VALUE}; data.bytes = new byte[] {-123, 123, -1, 0, 1, Byte.MAX_VALUE, Byte.MIN_VALUE}; data.chars = new char[] {32345, 12345, 0, 1, 63, Character.MAX_VALUE, Character.MIN_VALUE}; data.booleans = new boolean[] {true, false}; @@ -120,7 +120,7 @@ private void populateData (Data data, boolean isTCP) { Float.MIN_VALUE}; data.Doubles = new Double[] {0d, -0d, 1d, -1d, 123456d, -123456d, 0.1d, 0.2d, -0.3d, Math.PI, Double.MAX_VALUE, Double.MIN_VALUE}; - data.Longs = new Long[] {0l, -0l, 1l, -1l, 123456l, -123456l, 99999999999l, -99999999999l, Long.MAX_VALUE, Long.MIN_VALUE}; + data.Longs = new Long[] {0L, -0L, 1L, -1L, 123456L, -123456L, 99999999999L, -99999999999L, Long.MAX_VALUE, Long.MIN_VALUE}; data.Bytes = new Byte[] {-123, 123, -1, 0, 1, Byte.MAX_VALUE, Byte.MIN_VALUE}; data.Chars = new Character[] {32345, 12345, 0, 1, 63, Character.MAX_VALUE, Character.MIN_VALUE}; data.Booleans = new Boolean[] {true, false}; @@ -149,25 +149,25 @@ private void register (Kryo kryo) { static public class Data { public String string; - public String[] strings; - public int[] ints; - public short[] shorts; - public float[] floats; - public double[] doubles; - public long[] longs; - public byte[] bytes; - public char[] chars; - public boolean[] booleans; - public Integer[] Ints; - public Short[] Shorts; - public Float[] Floats; - public Double[] Doubles; - public Long[] Longs; - public Byte[] Bytes; - public Character[] Chars; - public Boolean[] Booleans; - public boolean isTCP; - + String[] strings;int[] ints; + short[] shorts; + float[] floats; + double[] doubles; + long[] longs; + byte[] bytes; + char[] chars; + boolean[] booleans; + Integer[] Ints; + Short[] Shorts; + Float[] Floats; + Double[] Doubles; + Long[] Longs; + Byte[] Bytes; + Character[] Chars; + Boolean[] Booleans; + boolean isTCP; + + @Override public int hashCode () { final int prime = 31; int result = 1; @@ -193,6 +193,7 @@ public int hashCode () { return result; } + @Override public boolean equals (Object obj) { if (this == obj) return true; if (obj == null) return false; @@ -218,8 +219,7 @@ public boolean equals (Object obj) { if (string == null) { if (other.string != null) return false; } else if (!string.equals(other.string)) return false; - if (!Arrays.equals(strings, other.strings)) return false; - return true; + return Arrays.equals(strings, other.strings); } public String toString () { diff --git a/test/com/esotericsoftware/kryonet/PingTest.java b/test/com/esotericsoftware/kryonet/PingTest.java index d2f60460..0f0d5ffb 100644 --- a/test/com/esotericsoftware/kryonet/PingTest.java +++ b/test/com/esotericsoftware/kryonet/PingTest.java @@ -34,10 +34,12 @@ public void testPing () throws IOException { final Client client = new Client(); startEndPoint(client); client.addListener(new Listener() { + @Override public void connected (Connection connection) { client.updateReturnTripTime(); } + @Override public void received (Connection connection, Object object) { if (object instanceof Ping) { Ping ping = (Ping)object; diff --git a/test/com/esotericsoftware/kryonet/ReconnectTest.java b/test/com/esotericsoftware/kryonet/ReconnectTest.java index 77e3cb18..c1712ca9 100644 --- a/test/com/esotericsoftware/kryonet/ReconnectTest.java +++ b/test/com/esotericsoftware/kryonet/ReconnectTest.java @@ -44,19 +44,21 @@ public void run () { // ---- - final AtomicInteger reconnetCount = new AtomicInteger(); + final AtomicInteger reconnectCount = new AtomicInteger(); final Client client = new Client(); startEndPoint(client); client.addListener(new Listener() { + @Override public void disconnected (Connection connection) { - if (reconnetCount.getAndIncrement() == 2) { + if (reconnectCount.getAndIncrement() == 2) { stopEndPoints(); return; } new Thread() { + @Override public void run () { try { - System.out.println("Reconnecting: " + reconnetCount.get()); + System.out.println("Reconnecting: " + reconnectCount.get()); client.reconnect(); } catch (IOException ex) { ex.printStackTrace(); @@ -68,6 +70,6 @@ public void run () { client.connect(5000, host, tcpPort); waitForThreads(10000); - assertEquals(3, reconnetCount.getAndIncrement()); + assertEquals(3, reconnectCount.getAndIncrement()); } } diff --git a/test/com/esotericsoftware/kryonet/ReuseTest.java b/test/com/esotericsoftware/kryonet/ReuseTest.java index d5ab0410..a11e6159 100644 --- a/test/com/esotericsoftware/kryonet/ReuseTest.java +++ b/test/com/esotericsoftware/kryonet/ReuseTest.java @@ -29,11 +29,13 @@ public void testPingPong () throws IOException { final Server server = new Server(); startEndPoint(server); server.addListener(new Listener() { + @Override public void connected (Connection connection) { connection.sendTCP("TCP from server"); connection.sendUDP("UDP from server"); } + @Override public void received (Connection connection, Object object) { if (object instanceof String) { stringCount.incrementAndGet(); @@ -47,11 +49,13 @@ public void received (Connection connection, Object object) { final Client client = new Client(); startEndPoint(client); client.addListener(new Listener() { + @Override public void connected (Connection connection) { connection.sendTCP("TCP from client"); connection.sendUDP("UDP from client"); } + @Override public void received (Connection connection, Object object) { if (object instanceof String) { stringCount.incrementAndGet(); @@ -67,6 +71,7 @@ public void received (Connection connection, Object object) { try { Thread.sleep(250); } catch (InterruptedException ex) { + ex.printStackTrace(); } server.close(); } diff --git a/test/com/esotericsoftware/kryonet/UnregisteredClassTest.java b/test/com/esotericsoftware/kryonet/UnregisteredClassTest.java index 7f7284c9..6c93b362 100644 --- a/test/com/esotericsoftware/kryonet/UnregisteredClassTest.java +++ b/test/com/esotericsoftware/kryonet/UnregisteredClassTest.java @@ -19,11 +19,6 @@ package com.esotericsoftware.kryonet; -import com.esotericsoftware.kryo.Kryo; -import com.esotericsoftware.kryo.io.Input; -import com.esotericsoftware.kryo.io.Output; -import com.esotericsoftware.minlog.Log; - import java.io.IOException; import java.util.Arrays; import java.util.concurrent.atomic.AtomicInteger; @@ -43,11 +38,13 @@ public void testUnregisteredClasses () throws IOException { startEndPoint(server); server.bind(tcpPort, udpPort); server.addListener(new Listener() { + @Override public void connected (Connection connection) { connection.sendTCP(dataTCP); connection.sendUDP(dataUDP); } + @Override public void received (Connection connection, Object object) { if (object instanceof Data) { Data data = (Data)object; @@ -68,6 +65,7 @@ public void received (Connection connection, Object object) { client.getKryo().setRegistrationRequired(false); startEndPoint(client); client.addListener(new Listener() { + @Override public void received (Connection connection, Object object) { if (object instanceof Data) { Data data = (Data)object; @@ -95,10 +93,7 @@ public void received (Connection connection, Object object) { private void populateData (Data data, boolean isTCP) { data.isTCP = isTCP; - StringBuffer buffer = new StringBuffer(); - for (int i = 0; i < 3000; i++) - buffer.append('a'); - data.string = buffer.toString(); + data.string = "a".repeat(3000); data.strings = new String[] {"abcdefghijklmnopqrstuvwxyz0123456789", "", null, "!@#$", "�����"}; data.ints = new int[] {-1234567, 1234567, -1, 0, 1, Integer.MAX_VALUE, Integer.MIN_VALUE}; @@ -106,7 +101,7 @@ private void populateData (Data data, boolean isTCP) { data.floats = new float[] {0, -0, 1, -1, 123456, -123456, 0.1f, 0.2f, -0.3f, (float)Math.PI, Float.MAX_VALUE, Float.MIN_VALUE}; data.doubles = new double[] {0, -0, 1, -1, 123456, -123456, 0.1d, 0.2d, -0.3d, Math.PI, Double.MAX_VALUE, Double.MIN_VALUE}; - data.longs = new long[] {0, -0, 1, -1, 123456, -123456, 99999999999l, -99999999999l, Long.MAX_VALUE, Long.MIN_VALUE}; + data.longs = new long[] {0, -0, 1, -1, 123456, -123456, 99999999999L, -99999999999L, Long.MAX_VALUE, Long.MIN_VALUE}; data.bytes = new byte[] {-123, 123, -1, 0, 1, Byte.MAX_VALUE, Byte.MIN_VALUE}; data.chars = new char[] {32345, 12345, 0, 1, 63, Character.MAX_VALUE, Character.MIN_VALUE}; data.booleans = new boolean[] {true, false}; @@ -116,7 +111,7 @@ private void populateData (Data data, boolean isTCP) { Float.MIN_VALUE}; data.Doubles = new Double[] {0d, -0d, 1d, -1d, 123456d, -123456d, 0.1d, 0.2d, -0.3d, Math.PI, Double.MAX_VALUE, Double.MIN_VALUE}; - data.Longs = new Long[] {0l, -0l, 1l, -1l, 123456l, -123456l, 99999999999l, -99999999999l, Long.MAX_VALUE, Long.MIN_VALUE}; + data.Longs = new Long[] {0L, -0L, 1L, -1L, 123456L, -123456L, 99999999999L, -99999999999L, Long.MAX_VALUE, Long.MIN_VALUE}; data.Bytes = new Byte[] {-123, 123, -1, 0, 1, Byte.MAX_VALUE, Byte.MIN_VALUE}; data.Chars = new Character[] {32345, 12345, 0, 1, 63, Character.MAX_VALUE, Character.MIN_VALUE}; data.Booleans = new Boolean[] {true, false}; @@ -124,25 +119,26 @@ private void populateData (Data data, boolean isTCP) { static public class Data { public String string; - public String[] strings; - public int[] ints; - public short[] shorts; - public float[] floats; - public double[] doubles; - public long[] longs; - public byte[] bytes; - public char[] chars; - public boolean[] booleans; - public Integer[] Ints; - public Short[] Shorts; - public Float[] Floats; - public Double[] Doubles; - public Long[] Longs; - public Byte[] Bytes; - public Character[] Chars; - public Boolean[] Booleans; - public boolean isTCP; - + String[] strings; + int[] ints; + short[] shorts; + float[] floats; + double[] doubles; + long[] longs; + byte[] bytes; + char[] chars; + boolean[] booleans; + Integer[] Ints; + Short[] Shorts; + Float[] Floats; + Double[] Doubles; + Long[] Longs; + Byte[] Bytes; + Character[] Chars; + Boolean[] Booleans; + boolean isTCP; + + @Override public int hashCode () { final int prime = 31; int result = 1; @@ -168,6 +164,7 @@ public int hashCode () { return result; } + @Override public boolean equals (Object obj) { if (this == obj) return true; if (obj == null) return false; @@ -193,10 +190,10 @@ public boolean equals (Object obj) { if (string == null) { if (other.string != null) return false; } else if (!string.equals(other.string)) return false; - if (!Arrays.equals(strings, other.strings)) return false; - return true; + return Arrays.equals(strings, other.strings); } + @Override public String toString () { return "Data"; } diff --git a/test/com/esotericsoftware/kryonet/compress/DeflateTest.java b/test/com/esotericsoftware/kryonet/compress/DeflateTest.java index 1a30af17..46112207 100644 --- a/test/com/esotericsoftware/kryonet/compress/DeflateTest.java +++ b/test/com/esotericsoftware/kryonet/compress/DeflateTest.java @@ -49,6 +49,7 @@ public void testDeflate () throws IOException { startEndPoint(server); server.bind(tcpPort, udpPort); server.addListener(new Listener() { + @Override public void connected (Connection connection) { server.sendToAllTCP(data); connection.sendTCP(data); @@ -62,6 +63,7 @@ public void connected (Connection connection) { register(client.getKryo()); startEndPoint(client); client.addListener(new Listener() { + @Override public void received (Connection connection, Object object) { if (object instanceof SomeData) { SomeData data = (SomeData)object; diff --git a/test/com/esotericsoftware/kryonet/rmi/RmiSendObjectTest.java b/test/com/esotericsoftware/kryonet/rmi/RmiSendObjectTest.java index 026ac8a3..8c7dc1e9 100644 --- a/test/com/esotericsoftware/kryonet/rmi/RmiSendObjectTest.java +++ b/test/com/esotericsoftware/kryonet/rmi/RmiSendObjectTest.java @@ -56,11 +56,13 @@ public void testRMI () throws IOException { serverObjectSpace.register(777, serverTestObject.getOtherObject()); server.addListener(new Listener() { + @Override public void connected (final Connection connection) { // Allow the connection to access objects in the ObjectSpace. serverObjectSpace.addConnection(connection); } + @Override public void received (Connection connection, Object object) { // The test is complete when the client sends the OtherObject instance. if (object == serverTestObject.getOtherObject()) stopEndPoints(); @@ -75,6 +77,7 @@ public void received (Connection connection, Object object) { // The ThreadedListener means the network thread won't be blocked when waiting for RMI responses. client.addListener(new ThreadedListener(new Listener() { + @Override public void connected (final Connection connection) { TestObject test = ObjectSpace.getRemoteObject(connection, 42, TestObject.class); // Normal remote method call. @@ -93,35 +96,38 @@ public void connected (final Connection connection) { } /** Registers the same classes in the same order on both the client and server. */ - static public void register (Kryo kryo) { + private static void register(Kryo kryo) { kryo.register(TestObject.class); kryo.register(OtherObject.class, new RemoteObjectSerializer()); ObjectSpace.registerClasses(kryo); } - static public interface TestObject { - public float other (); + public interface TestObject { + float other (); - public OtherObject getOtherObject (); + OtherObject getOtherObject (); } static public class TestObjectImpl implements TestObject { - public OtherObject otherObject; + OtherObject otherObject; + @Override public float other () { return 43.21f; } + @Override public OtherObject getOtherObject () { return otherObject; } } - static public interface OtherObject { - public float value (); + public interface OtherObject { + float value (); } static public class OtherObjectImpl implements OtherObject { + @Override public float value () { return 12.34f; } diff --git a/test/com/esotericsoftware/kryonet/rmi/RmiTest.java b/test/com/esotericsoftware/kryonet/rmi/RmiTest.java index a812d097..0678ef63 100644 --- a/test/com/esotericsoftware/kryonet/rmi/RmiTest.java +++ b/test/com/esotericsoftware/kryonet/rmi/RmiTest.java @@ -45,11 +45,13 @@ public void testRMI () throws IOException { serverObjectSpace.register(42, serverTestObject); server.addListener(new Listener() { + @Override public void connected (final Connection connection) { serverObjectSpace.addConnection(connection); runTest(connection, 12, 1234); } + @Override public void received (Connection connection, Object object) { if (!(object instanceof MessageWithTestObject)) return; MessageWithTestObject m = (MessageWithTestObject)object; @@ -71,10 +73,12 @@ public void received (Connection connection, Object object) { startEndPoint(client); client.addListener(new Listener() { + @Override public void connected (final Connection connection) { runTest(connection, 42, 4321); } + @Override public void received (Connection connection, Object object) { if (!(object instanceof MessageWithTestObject)) return; MessageWithTestObject m = (MessageWithTestObject)object; @@ -103,10 +107,12 @@ public void testMany () throws IOException { serverObjectSpace.register(42, serverTestObject); server.addListener(new Listener() { + @Override public void connected (final Connection connection) { serverObjectSpace.addConnection(connection); } + @Override public void received (Connection connection, Object object) { if (object instanceof MessageWithTestObject) { assertEquals(256 + 512 + 1024, serverTestObject.moos); @@ -122,8 +128,10 @@ public void received (Connection connection, Object object) { startEndPoint(client); client.addListener(new Listener() { + @Override public void connected (final Connection connection) { new Thread() { + @Override public void run () { TestObject test = ObjectSpace.getRemoteObject(connection, 42, TestObject.class); test.other(); @@ -137,6 +145,7 @@ public void run () { try { Thread.sleep(300); } catch (InterruptedException ex) { + ex.printStackTrace(); } ((RemoteObject)test).setResponseTimeout(3000); for (int i = 0; i < 256; i++) @@ -157,8 +166,9 @@ public void run () { waitForThreads(); } - static public void runTest (final Connection connection, final int id, final float other) { + private static void runTest(final Connection connection, final int id, final float other) { new Thread() { + @Override public void run () { TestObject test = ObjectSpace.getRemoteObject(connection, id, TestObject.class); RemoteObject remoteObject = (RemoteObject)test; @@ -241,7 +251,7 @@ public void run () { } /** Registers the same classes in the same order on both the client and server. */ - static public void register (Kryo kryo) { + private static void register(Kryo kryo) { kryo.register(Object.class); // Needed for Object#toString, hashCode, etc. kryo.register(TestObject.class); kryo.register(MessageWithTestObject.class); @@ -252,18 +262,18 @@ static public void register (Kryo kryo) { ObjectSpace.registerClasses(kryo); } - static public interface TestObject { - public void throwException (); + public interface TestObject { + void throwException (); - public void moo (); + void moo (); - public void moo (String value); + void moo (String value); - public void moo (String value, long delay); + void moo (String value, long delay); - public float other (); + float other (); - public float slow (); + void slow (); } static public class TestObjectImpl implements TestObject { @@ -275,20 +285,24 @@ public TestObjectImpl (int other) { this.other = other; } + @Override public void throwException () { throw new UnsupportedOperationException("Why would I do that?"); } + @Override public void moo () { moos++; System.out.println("Moo!"); } + @Override public void moo (String value) { moos += 2; System.out.println("Moo: " + value); } + @Override public void moo (String value, long delay) { moos += 4; System.out.println("Moo: " + value); @@ -299,17 +313,18 @@ public void moo (String value, long delay) { } } + @Override public float other () { return other; } - public float slow () { + @Override + public void slow () { try { Thread.sleep(300); } catch (InterruptedException ex) { } - return 666; - } + } } static public class MessageWithTestObject {