Provide access to an in-order list of all class

registrations.
Also made the direct register by ID method public
so that external callers can register serializers
for specific IDs.
With these changes, it is possible for a server to
authoritatively send out a list of all registrations
to its clients greatly reducing the "registration
dependency" that exists otherwise.


git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10948 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
experimental
PSp..om 11 years ago
parent 90913bf8c3
commit 797caf6936
  1. 16
      engine/src/networking/com/jme3/network/serializing/Serializer.java

@ -61,6 +61,7 @@ public abstract class Serializer {
private static final Map<Short, SerializerRegistration> idRegistrations = new HashMap<Short, SerializerRegistration>();
private static final Map<Class, SerializerRegistration> classRegistrations = new HashMap<Class, SerializerRegistration>();
private static final List<SerializerRegistration> registrations = new ArrayList<SerializerRegistration>();
private static final Serializer fieldSerializer = new FieldSerializer();
private static final Serializer serializableSerializer = new SerializableSerializer();
@ -167,7 +168,12 @@ public abstract class Serializer {
return nextAvailableId--;
}
protected static SerializerRegistration registerClassForId( short id, Class cls, Serializer serializer ) {
/**
* Directly registers a class for a specific ID. Generally, use the regular
* registerClass() method. This method is intended for framework code that might
* be maintaining specific ID maps across client and server.
*/
public static SerializerRegistration registerClassForId( short id, Class cls, Serializer serializer ) {
SerializerRegistration reg = new SerializerRegistration(serializer, cls, id);
@ -178,6 +184,10 @@ public abstract class Serializer {
serializer.initialize(cls);
// Add the class after so that dependency order is preserved if the
// serializer registers its own classes.
registrations.add(reg);
return reg;
}
@ -285,6 +295,10 @@ public abstract class Serializer {
return getSerializerRegistration(cls, failOnMiss).getSerializer();
}
public static Collection<SerializerRegistration> getSerializerRegistrations() {
return registrations;
}
public static SerializerRegistration getExactSerializerRegistration(Class cls) {
return classRegistrations.get(cls);
}

Loading…
Cancel
Save