Added the ability to put the serializer registry

in "read only" mode.  Modified the SerializerRegistrationMessage
to put the serializer registry into read only after
it compiles the message so that the server won't accidentally
register messages after they've been compiled.
experimental
Paul Speed 10 years ago
parent c93c746b8b
commit c1dc819953
  1. 4
      jme3-networking/src/main/java/com/jme3/network/message/SerializerRegistrationsMessage.java
  2. 22
      jme3-networking/src/main/java/com/jme3/network/serializing/Serializer.java

@ -127,7 +127,9 @@ public class SerializerRegistrationsMessage extends AbstractMessage {
}
compiled = list.toArray(new Registration[list.size()]);
INSTANCE = new SerializerRegistrationsMessage(compiled);
INSTANCE = new SerializerRegistrationsMessage(compiled);
Serializer.setReadOnly(true);
}
public void registerAll() {

@ -71,6 +71,8 @@ public abstract class Serializer {
private static boolean strictRegistration = true;
private static volatile boolean locked = false;
// Registers the classes we already have serializers for.
static {
@ -168,6 +170,20 @@ public abstract class Serializer {
return nextAvailableId--;
}
/**
* Can put the registry in a read-only state such that additional attempts
* to register classes will fail. This can be used by servers to lock the
* registry to avoid accidentally registering classes after a full registry
* set has been compiled.
*/
public static void setReadOnly( boolean b ) {
locked = b;
}
public static boolean isReadOnly() {
return locked;
}
/**
* Directly registers a class for a specific ID. Generally, use the regular
* registerClass() method. This method is intended for framework code that might
@ -175,7 +191,11 @@ public abstract class Serializer {
*/
public static SerializerRegistration registerClassForId( short id, Class cls, Serializer serializer ) {
SerializerRegistration reg = new SerializerRegistration(serializer, cls, id);
if( locked ) {
throw new RuntimeException("Serializer registry locked trying to register class:" + cls);
}
SerializerRegistration reg = new SerializerRegistration(serializer, cls, id);
idRegistrations.put(id, reg);
classRegistrations.put(cls, reg);

Loading…
Cancel
Save