Class SchemaRegistry

java.lang.Object
org.j7m.middleware.codec.api.SchemaRegistry

public final class SchemaRegistry extends Object
Immutable allowlist of application-owned schemas; safe for concurrent codec calls.
  • Constructor Details

    • SchemaRegistry

      public SchemaRegistry(List<SchemaDescriptor<?>> descriptors)
      Creates a registry and rejects duplicate registrations and incompatible adjacent versions. Adding/removing optional fields is compatible; field types and required fields cannot change.
      Parameters:
      descriptors - explicitly trusted schema definitions; may be empty
      Throws:
      IllegalArgumentException - for duplicate or incompatible schemas
  • Method Details

    • forType

      public SchemaDescriptor<?> forType(Class<?> type)
      Finds an explicitly trusted class without class loading.
      Parameters:
      type - exact registered class
      Returns:
      descriptor or null when unregistered
    • forVersion

      public SchemaDescriptor<?> forVersion(String id, int version)
      Finds an explicitly registered wire version.
      Parameters:
      id - stable schema identifier
      version - positive version
      Returns:
      descriptor or null when unregistered
    • checkCompatible

      public static void checkCompatible(SchemaDescriptor<?> a, SchemaDescriptor<?> b)
      Checks symmetric compatibility before decoding or registration, without invoking trusted functions.
      Parameters:
      a - first descriptor
      b - second descriptor
      Throws:
      IllegalArgumentException - if fields are incompatible