diff --git a/README.md b/README.md index 856f2df6..0a3bb736 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ This fork was specifically made for [ProjectGG](https://github.com/eskalon/Proje * A TypeListener for easier message handling (see the example below; also fixes [#130](https://github.com/EsotericSoftware/kryonet/issues/130)) * Listener is now an interface ([#39](https://github.com/EsotericSoftware/kryonet/issues/39)) * Kryo 4.0.1 is used for the serialization ([#77](https://github.com/EsotericSoftware/kryonet/issues/77); also fixes [#123](https://github.com/EsotericSoftware/kryonet/issues/123)) -* Fixes for the Android 5 and iOS crashes ([#106](https://github.com/EsotericSoftware/kryonet/issues/106)) +* Includes a fix for the common Android 5 crash ([#106](https://github.com/EsotericSoftware/kryonet/issues/106)) * The LAN Host Discovery is now available to Non-Kryo-Serializations ([#127](https://github.com/EsotericSoftware/kryonet/issues/127)) * A few other changes to serializations (see the respective paragraph below) * Kryonet now uses a [gradle](https://gradle.org/) build setup @@ -35,8 +35,9 @@ server.addListener(typeListener); ## Changes to (Custom) Serializations -* The serialization objects are created by [factories](https://github.com/crykn/kryonet/blob/master/src/main/java/com/esotericsoftware/kryonet/serialization/SerializationFactory.java) -* The server now uses a serialization instance _per_ TCP connection (and still only one serialization instance for the UDP connections). This allows the server to keep responding while another message is serialized (see [#137](https://github.com/EsotericSoftware/kryonet/issues/137)). +* The serialization objects are now created by [factories](https://github.com/crykn/kryonet/blob/master/src/main/java/com/esotericsoftware/kryonet/serialization/SerializationFactory.java): `SerializationFactory#newInstance(Connection)` +* The in-built serializations still behave exactly the same (i.e. one serialization instance is used for the server) +* Custom serializations on the other hand can now decide to only get used _once per TCP connection_ (all UDP connections still use one instance). This allows the server to keep responding while a message for another connection is still being serialized (see [#137](https://github.com/EsotericSoftware/kryonet/issues/137)). ## Download @@ -52,6 +53,6 @@ allprojects { } dependencies { - compile 'com.github.crykn:kryonet:2.22.1' + compile 'com.github.crykn:kryonet:2.22.2' } ``` \ No newline at end of file diff --git a/build.gradle b/build.gradle index b45aacec..4502d151 100644 --- a/build.gradle +++ b/build.gradle @@ -1,16 +1,17 @@ apply plugin: "java" -version '2.22.1' +version '2.22.2' sourceCompatibility = 1.9 targetCompatibility = 1.9 repositories { mavenCentral() + maven { url 'https://jitpack.io' } } dependencies { - compile "com.esotericsoftware:jsonbeans:0.7" - compile "com.esotericsoftware:kryo:4.0.1" + compile 'com.github.esotericsoftware:jsonbeans:0.9' + compile "com.esotericsoftware:kryo:4.0.2" testCompile group: 'junit', name: 'junit', version: '4.12' } diff --git a/src/main/java/com/esotericsoftware/kryonet/serialization/JsonSerializationFactory.java b/src/main/java/com/esotericsoftware/kryonet/serialization/JsonSerializationFactory.java index 942652a1..b72fe0ec 100644 --- a/src/main/java/com/esotericsoftware/kryonet/serialization/JsonSerializationFactory.java +++ b/src/main/java/com/esotericsoftware/kryonet/serialization/JsonSerializationFactory.java @@ -19,9 +19,15 @@ public class JsonSerializationFactory implements SerializationFactory { + private final Serialization INSTANCE; + @Override public Serialization newInstance(Connection connection) { - return new JsonSerialization(); + return INSTANCE; + } + + public JsonSerializationFactory() { + this.INSTANCE = new JsonSerialization(); } public class JsonSerialization implements Serialization { diff --git a/src/main/java/com/esotericsoftware/kryonet/serialization/KryoSerializationFactory.java b/src/main/java/com/esotericsoftware/kryonet/serialization/KryoSerializationFactory.java index c623218b..21442c99 100644 --- a/src/main/java/com/esotericsoftware/kryonet/serialization/KryoSerializationFactory.java +++ b/src/main/java/com/esotericsoftware/kryonet/serialization/KryoSerializationFactory.java @@ -11,11 +11,19 @@ import com.esotericsoftware.kryonet.FrameworkMessage.Ping; import com.esotericsoftware.kryonet.FrameworkMessage.RegisterTCP; import com.esotericsoftware.kryonet.FrameworkMessage.RegisterUDP; +import com.esotericsoftware.kryonet.serialization.JsonSerializationFactory.JsonSerialization; public class KryoSerializationFactory implements SerializationFactory { private Kryo kryo; + private final KryoSerialization INSTANCE; + + @Override + public Serialization newInstance(Connection connection) { + return INSTANCE; + } + public KryoSerializationFactory() { this(new Kryo()); @@ -30,28 +38,19 @@ public KryoSerializationFactory(Kryo kryo) { this.kryo.register(KeepAlive.class); this.kryo.register(DiscoverHost.class); this.kryo.register(Ping.class); + + this.INSTANCE = new KryoSerialization(kryo); } public Kryo getKryo() { return kryo; } - @Override - public Serialization newInstance(Connection connection) { - return new KryoSerialization(connection, kryo); - } - public class KryoSerialization implements Serialization { private final Kryo kryo; private final ByteBufferInput input; private final ByteBufferOutput output; - public KryoSerialization(Connection connection, Kryo kryo) { - this(kryo); - - kryo.getContext().put("connection", connection); - } - public KryoSerialization(Kryo kryo) { this.kryo = kryo; diff --git a/src/test/java/com/esotericsoftware/kryonet/KryoNetTestCase.java b/src/test/java/com/esotericsoftware/kryonet/KryoNetTestCase.java index 036a742b..c32e2e73 100644 --- a/src/test/java/com/esotericsoftware/kryonet/KryoNetTestCase.java +++ b/src/test/java/com/esotericsoftware/kryonet/KryoNetTestCase.java @@ -93,7 +93,7 @@ public void run () { fail = true; } }; - timer.schedule(failTask, 11000); + timer.schedule(failTask, 13000); while (true) { for (Iterator iter = threads.iterator(); iter.hasNext();) { Thread thread = (Thread)iter.next(); diff --git a/src/test/java/com/esotericsoftware/kryonet/rmi/RmiTest.java b/src/test/java/com/esotericsoftware/kryonet/rmi/RmiTest.java index 7d2d1663..46f29441 100644 --- a/src/test/java/com/esotericsoftware/kryonet/rmi/RmiTest.java +++ b/src/test/java/com/esotericsoftware/kryonet/rmi/RmiTest.java @@ -38,8 +38,6 @@ public class RmiTest extends KryoNetTestCase { * other features. */ public void testRMI() throws IOException { - Log.set(Log.LEVEL_DEBUG); - Server server = new Server(); Kryo serverKryo = server.getKryo(); register(serverKryo);