Class SerializerRegistry

java.lang.Object
pt.unl.fct.di.novasys.babel2.channels.serializers.SerializerRegistry

public final class SerializerRegistry extends Object
Central registry that maps Java types and message IDs to their BabelNetworkSerializer / BabelNetworkMessageSerializer implementations.

All registrations happen in a static initializer block that runs exactly once per JVM. The registry uses the ServiceLoader mechanism to discover implementations:

This class is not instantiable.

  • Method Details

    • getMessageSerializerByClass

      public static <T extends BabelMessage> @Nullable BabelNetworkMessageSerializer<T> getMessageSerializerByClass(Class<T> clazz)
      Looks up the BabelNetworkMessageSerializer registered for the given message class.
      Type Parameters:
      T - the message type
      Parameters:
      clazz - the class object for the message type
      Returns:
      the corresponding serializer, or null if no serializer has been registered for clazz
    • getSerializerByClass

      public static <T> @Nullable BabelNetworkSerializer<T> getSerializerByClass(Class<T> clazz)
      Looks up the BabelNetworkSerializer registered for the given object class. This method returns only non-message serializers.
      Type Parameters:
      T - the object type
      Parameters:
      clazz - the class object for the type to look up
      Returns:
      the corresponding serializer, or null if no serializer has been registered for clazz
    • getSignedBabelMessageSerializerByClass

      public static <T extends BabelMessage> @Nullable BasicSignedBabelMessageSerializer<T> getSignedBabelMessageSerializerByClass(Class<T> clazz)
      Looks up the BasicSignedBabelMessageSerializer registered for the given message class.
      Type Parameters:
      T - the message type
      Parameters:
      clazz - the class object for the message type
      Returns:
      the corresponding signed serializer, or null if no serializer has been registered for clazz
    • getMessageSerializerById

      public static <T extends BabelMessage> @Nullable BabelNetworkMessageSerializer<T> getMessageSerializerById(int id)
      Looks up the BabelNetworkMessageSerializer registered for the given message ID.
      Type Parameters:
      T - the message type
      Parameters:
      id - the message type ID
      Returns:
      the corresponding serializer, or null if no serializer has been registered for id
    • getSignedBabelMessageSerializerById

      public static <T extends BabelMessage> @Nullable BasicSignedBabelMessageSerializer<T> getSignedBabelMessageSerializerById(int id)
      Looks up the BasicSignedBabelMessageSerializer registered for the given message ID.
      Type Parameters:
      T - the message type
      Parameters:
      id - the message type ID
      Returns:
      the corresponding signed serializer, or null if no serializer has been registered for id
    • getSignedMessageSerializerById

      public static <T extends BabelMessage> @Nullable BasicSignedBabelMessageSerializer<T> getSignedMessageSerializerById(int id)
      Looks up the BasicSignedBabelMessageSerializer registered for the given message ID. Alias for getSignedBabelMessageSerializerById(int).
      Type Parameters:
      T - the message type
      Parameters:
      id - the message type ID
      Returns:
      the corresponding signed serializer, or null if no serializer has been registered for id