diff --git a/src/dorkbox/network/connection/EndPointBase.java b/src/dorkbox/network/connection/EndPointBase.java index e3ef2d4a..debbac51 100644 --- a/src/dorkbox/network/connection/EndPointBase.java +++ b/src/dorkbox/network/connection/EndPointBase.java @@ -115,7 +115,7 @@ class EndPointBase extends EndPoint { /** - * @param type this is either "Client" or "Server", depending on who is creating this endpoint. + * @param type this is either "Client" or "Server", depending on who is creating this endpoint. * @param config these are the specific connection options * * @throws InitializationException diff --git a/src/dorkbox/network/serialization/RmiSerializationManager.java b/src/dorkbox/network/serialization/RmiSerializationManager.java index f9d60d83..e00db0e2 100644 --- a/src/dorkbox/network/serialization/RmiSerializationManager.java +++ b/src/dorkbox/network/serialization/RmiSerializationManager.java @@ -26,58 +26,53 @@ public interface RmiSerializationManager extends SerializationManager { /** - * Registers the class using the lowest, next available integer ID and the - * {@link Kryo#getDefaultSerializer(Class) default serializer}. If the class - * is already registered, the existing entry is updated with the new - * serializer. Registering a primitive also affects the corresponding - * primitive wrapper. - *

- * Because the ID assigned is affected by the IDs registered before it, the - * order classes are registered is important when using this method. The - * order must be the same at deserialization as it was for serialization. + * Registers the class using the lowest, next available integer ID and the {@link Kryo#getDefaultSerializer(Class) default serializer}. + * If the class is already registered, the existing entry is updated with the new serializer. + *

+ * Registering a primitive also affects the corresponding primitive wrapper. + *

+ * Because the ID assigned is affected by the IDs registered before it, the order classes are registered is important when using this + * method. The order must be the same at deserialization as it was for serialization. */ @Override RmiSerializationManager register(Class clazz); /** - * Registers the class using the specified ID. If the ID is - * already in use by the same type, the old entry is overwritten. If the ID + * Registers the class using the specified ID. If the ID is already in use by the same type, the old entry is overwritten. If the ID * is already in use by a different type, a {@link KryoException} is thrown. + *

* Registering a primitive also affects the corresponding primitive wrapper. - *

+ *

* IDs must be the same at deserialization as they were for serialization. * - * @param id Must be >= 0. Smaller IDs are serialized more efficiently. IDs - * 0-8 are used by default for primitive types and String, but - * these IDs can be repurposed. + * @param id Must be >= 0. Smaller IDs are serialized more efficiently. IDs 0-8 are used by default for primitive types and String, but + * these IDs can be repurposed. */ @Override RmiSerializationManager register(Class clazz, int id); /** - * Registers the class using the lowest, next available integer ID and the - * specified serializer. If the class is already registered, the existing - * entry is updated with the new serializer. Registering a primitive also - * affects the corresponding primitive wrapper. - *

- * Because the ID assigned is affected by the IDs registered before it, the - * order classes are registered is important when using this method. The - * order must be the same at deserialization as it was for serialization. + * Registers the class using the lowest, next available integer ID and the specified serializer. If the class is already registered, + * the existing entry is updated with the new serializer. + *

+ * Registering a primitive also affects the corresponding primitive wrapper. + *

+ * Because the ID assigned is affected by the IDs registered before it, the order classes are registered is important when using this + * method. The order must be the same at deserialization as it was for serialization. */ @Override RmiSerializationManager register(Class clazz, Serializer serializer); /** - * Registers the class using the specified ID and serializer. If the ID is - * already in use by the same type, the old entry is overwritten. If the ID - * is already in use by a different type, a {@link KryoException} is thrown. + * Registers the class using the specified ID and serializer. If the ID is already in use by the same type, the old entry is + * overwritten. If the ID is already in use by a different type, a {@link KryoException} is thrown. + *

* Registering a primitive also affects the corresponding primitive wrapper. - *

+ *

* IDs must be the same at deserialization as they were for serialization. * - * @param id Must be >= 0. Smaller IDs are serialized more efficiently. IDs - * 0-8 are used by default for primitive types and String, but - * these IDs can be repurposed. + * @param id Must be >= 0. Smaller IDs are serialized more efficiently. IDs 0-8 are used by default for primitive types and String, but + * these IDs can be repurposed. */ @Override RmiSerializationManager register(Class clazz, Serializer serializer, int id); @@ -133,20 +128,27 @@ interface RmiSerializationManager extends SerializationManager { /** * Enable remote method invocation (RMI) for this connection. There is additional overhead to using RMI. - *

+ *

* Specifically, It costs at least 2 bytes more to use remote method invocation than just sending the parameters. If the method has a - * return value which is not {@link dorkbox.network.rmi.RemoteObject#setAsync(boolean) ignored}, an extra byte is written. If the - * type of a parameter is not final (primitives are final) then an extra byte is written for that parameter. + * return value which is not {@link dorkbox.network.rmi.RemoteObject#setAsync(boolean) ignored}, an extra byte is written. + *

+ * If the type of a parameter is not final (primitives are final) then an extra byte is written for that parameter. */ RmiSerializationManager registerRmiInterface(Class ifaceClass); /** - * Objects that we want to use RMI with, must be accessed via an interface. This method configures the serialization of an - * implementation to be serialized via the defined interface, as a RemoteObject (ie: proxy object). If the implementation class is - * ALREADY registered, then it's registration will be overwritten by this one + * Enable remote method invocation (RMI) for this connection. There is additional overhead to using RMI. + *

+ * Specifically, It costs at least 2 bytes more to use remote method invocation than just sending the parameters. If the method has a + * return value which is not {@link dorkbox.network.rmi.RemoteObject#setAsync(boolean) ignored}, an extra byte is written. + *

+ * If the type of a parameter is not final (primitives are final) then an extra byte is written for that parameter. + *

+ * This method overrides the interface -> implementation. This is so incoming proxy objects will get auto-changed into their correct + * implementation type, so this side of the connection knows what to do with the proxy object. + *

* - * @param ifaceClass The interface used to access the remote object - * @param implClass The implementation class of the interface + * @throws IllegalArgumentException if the iface/impl have previously been overridden */ RmiSerializationManager registerRmiImplementation(Class ifaceClass, Class implClass); } diff --git a/src/dorkbox/network/serialization/SerializationManager.java b/src/dorkbox/network/serialization/SerializationManager.java index 1c8c945c..55f635a9 100644 --- a/src/dorkbox/network/serialization/SerializationManager.java +++ b/src/dorkbox/network/serialization/SerializationManager.java @@ -270,7 +270,7 @@ class SerializationManager implements CryptoSerializationManager, RmiSerializati // the server will ONLY send this object to the client RemoteIfaceClass remoteIfaceClass = (RemoteIfaceClass) clazz; - // registers the interface, so that when it is read, it becomes a "magic" proxy object + // registers the interface, so that when it is READ, it becomes a "magic" proxy object kryo.register(remoteIfaceClass.ifaceClass, remoteObjectSerializer); } else if (clazz instanceof RemoteImplClass) { @@ -281,7 +281,7 @@ class SerializationManager implements CryptoSerializationManager, RmiSerializati // the server will ONLY send this object to the client RemoteImplClass remoteImplClass = (RemoteImplClass) clazz; - // registers the implementation, so that when it is written, it becomes a "magic" proxy object + // registers the implementation, so that when it is WRITTEN, it becomes a "magic" proxy object int id = kryo.register(remoteImplClass.implClass, remoteObjectSerializer).getId(); // sets up the RMI, so when we receive the iface class from the client, we know what impl to use @@ -303,8 +303,9 @@ class SerializationManager implements CryptoSerializationManager, RmiSerializati /** * Registers the class using the lowest, next available integer ID and the {@link Kryo#getDefaultSerializer(Class) default serializer}. - * If the class is already registered, the existing entry is updated with the new serializer. Registering a primitive also affects the - * corresponding primitive wrapper. + * If the class is already registered, the existing entry is updated with the new serializer. + *

+ * Registering a primitive also affects the corresponding primitive wrapper. *

* Because the ID assigned is affected by the IDs registered before it, the order classes are registered is important when using this * method. The order must be the same at deserialization as it was for serialization. @@ -325,15 +326,14 @@ class SerializationManager implements CryptoSerializationManager, RmiSerializati } /** - * Registers the class using the specified ID. If the ID is - * already in use by the same type, the old entry is overwritten. If the ID + * Registers the class using the specified ID. If the ID is already in use by the same type, the old entry is overwritten. If the ID * is already in use by a different type, a {@link KryoException} is thrown. + *

* Registering a primitive also affects the corresponding primitive wrapper. - *

+ *

* IDs must be the same at deserialization as they were for serialization. * - * @param id Must be >= 0. Smaller IDs are serialized more efficiently. IDs - * 0-8 are used by default for primitive types and String, but + * @param id Must be >= 0. Smaller IDs are serialized more efficiently. IDs 0-8 are used by default for primitive types and String, but * these IDs can be repurposed. */ @Override @@ -353,8 +353,10 @@ class SerializationManager implements CryptoSerializationManager, RmiSerializati } /** - * Registers the class using the lowest, next available integer ID and the specified serializer. If the class is already registered, the - * existing entry is updated with the new serializer. Registering a primitive also affects the corresponding primitive wrapper. + * Registers the class using the lowest, next available integer ID and the specified serializer. If the class is already registered, + * the existing entry is updated with the new serializer. + *

+ * Registering a primitive also affects the corresponding primitive wrapper. *

* Because the ID assigned is affected by the IDs registered before it, the order classes are registered is important when using this * method. The order must be the same at deserialization as it was for serialization. @@ -377,13 +379,14 @@ class SerializationManager implements CryptoSerializationManager, RmiSerializati /** * Registers the class using the specified ID and serializer. If the ID is already in use by the same type, the old entry is - * overwritten. If the ID is already in use by a different type, a {@link KryoException} is thrown. Registering a primitive also affects - * the corresponding primitive wrapper. + * overwritten. If the ID is already in use by a different type, a {@link KryoException} is thrown. + *

+ * Registering a primitive also affects the corresponding primitive wrapper. *

* IDs must be the same at deserialization as they were for serialization. * - * @param id Must be >= 0. Smaller IDs are serialized more efficiently. IDs 0-8 are used by default for primitive types and - * String, but these IDs can be repurposed. + * @param id Must be >= 0. Smaller IDs are serialized more efficiently. IDs 0-8 are used by default for primitive types and String, but + * these IDs can be repurposed. */ @Override public synchronized @@ -403,10 +406,11 @@ class SerializationManager implements CryptoSerializationManager, RmiSerializati /** * Enable remote method invocation (RMI) for this connection. There is additional overhead to using RMI. - *

+ *

* Specifically, It costs at least 2 bytes more to use remote method invocation than just sending the parameters. If the method has a - * return value which is not {@link dorkbox.network.rmi.RemoteObject#setAsync(boolean) ignored}, an extra byte is written. If the - * type of a parameter is not final (primitives are final) then an extra byte is written for that parameter. + * return value which is not {@link dorkbox.network.rmi.RemoteObject#setAsync(boolean) ignored}, an extra byte is written. + *

+ * If the type of a parameter is not final (primitives are final) then an extra byte is written for that parameter. */ @Override public synchronized @@ -426,10 +430,16 @@ class SerializationManager implements CryptoSerializationManager, RmiSerializati } /** + * Enable remote method invocation (RMI) for this connection. There is additional overhead to using RMI. + *

+ * Specifically, It costs at least 2 bytes more to use remote method invocation than just sending the parameters. If the method has a + * return value which is not {@link dorkbox.network.rmi.RemoteObject#setAsync(boolean) ignored}, an extra byte is written. + *

+ * If the type of a parameter is not final (primitives are final) then an extra byte is written for that parameter. + *

* This method overrides the interface -> implementation. This is so incoming proxy objects will get auto-changed into their correct * implementation type, so this side of the connection knows what to do with the proxy object. *

- * NOTE: You must have ALREADY registered the implementation class. This method just enables the proxy magic. * * @throws IllegalArgumentException if the iface/impl have previously been overridden */ @@ -482,7 +492,8 @@ class SerializationManager implements CryptoSerializationManager, RmiSerializati } /** - * Called when initialization is complete. This is to prevent (and recognize) out-of-order class/serializer registration. + * Called when initialization is complete. This is to prevent (and recognize) out-of-order class/serializer registration. If an ID + * is already in use by a different type, a {@link KryoException} is thrown. */ @Override public synchronized