Class PubSubPositionTypeRegistry

java.lang.Object
com.linkedin.venice.pubsub.PubSubPositionTypeRegistry

public class PubSubPositionTypeRegistry extends Object
A configurable registry that maintains a bidirectional mapping between PubSubPositionFactory implementation class names (fully qualified) and their corresponding integer type IDs.

This registry enables compact serialization and deserialization of PubSubPosition instances by representing them with integer type IDs instead of full class names.

During construction, the registry validates that all class names are well-formed and resolvable at runtime. It also enforces consistency with reserved type IDs for symbolic positions such as PubSubSymbolicPosition.EARLIEST and, PubSubSymbolicPosition.LATEST, and ApacheKafkaOffsetPosition, rejecting any attempts to override them with mismatched types.

This registry is immutable after construction. The internal mappings cannot be modified once built, ensuring thread safety and predictable behavior throughout the lifetime of the instance.

This class is intended for use in components that need to serialize, deserialize, or resolve PubSubPosition types based on their type IDs or class names.

  • Field Details

    • LOGGER

      public static final org.apache.logging.log4j.Logger LOGGER
    • EARLIEST_POSITION_RESERVED_TYPE_ID

      public static final int EARLIEST_POSITION_RESERVED_TYPE_ID
      Reserved type IDs for internal standard PubSubPosition implementations.

      These constants define special type IDs used to identify symbolic or built-in PubSub positions. They are reserved for internal use and must not be reused, overridden, or assigned to custom PubSubPosition implementations by client code.

      Reserved IDs:

      POSITION_TYPE_INVALID_MAGIC_VALUE is used as a sentinel value to indicate that a position type ID has not yet been assigned or initialized. It must never be used as a valid position type.

      See Also:
    • LATEST_POSITION_RESERVED_TYPE_ID

      public static final int LATEST_POSITION_RESERVED_TYPE_ID
      See Also:
    • APACHE_KAFKA_OFFSET_POSITION_TYPE_ID

      public static final int APACHE_KAFKA_OFFSET_POSITION_TYPE_ID
      See Also:
    • POSITION_TYPE_INVALID_MAGIC_VALUE

      public static final int POSITION_TYPE_INVALID_MAGIC_VALUE
      See Also:
    • RESERVED_POSITION_TYPE_ID_TO_CLASS_NAME_MAP

      public static final it.unimi.dsi.fastutil.ints.Int2ObjectMap<String> RESERVED_POSITION_TYPE_ID_TO_CLASS_NAME_MAP
      A predefined map of reserved PubSub position type IDs to their corresponding fully qualified factory class names.

      This map is intended for internal use to bootstrap or validate known position implementations. It includes all reserved positions that are part of the standard Venice PubSub position model.

    • RESERVED_POSITION_TYPE_REGISTRY

      public static final PubSubPositionTypeRegistry RESERVED_POSITION_TYPE_REGISTRY
      A default, pre-configured PubSubPositionTypeRegistry instance that contains all reserved PubSubPosition type IDs and their associated factory class names.

      This instance should be used wherever a standard, system-defined position registry is sufficient. It includes entries for known symbolic positions like PubSubSymbolicPosition.EARLIEST, PubSubSymbolicPosition.LATEST, and standard implementations such as ApacheKafkaOffsetPosition.

      Note: This instance is read-only and should not be modified or extended at runtime.

  • Constructor Details

    • PubSubPositionTypeRegistry

      public PubSubPositionTypeRegistry(it.unimi.dsi.fastutil.ints.Int2ObjectMap<String> userProvidedMap)
      Constructs a PubSubPositionTypeRegistry by merging the provided type ID to class name map with the system-defined reserved position type mappings.

      Reserved position type IDs (such as those for PubSubSymbolicPosition.EARLIEST, PubSubSymbolicPosition.LATEST, and ApacheKafkaOffsetPosition) are validated to ensure they are not overridden with a conflicting class name. If a reserved ID is present in the provided map, it must map to the exact same class name as the reserved definition; otherwise, an VeniceException is thrown.

      Any reserved IDs not present in the input map are automatically included. The final registry is unmodifiable after construction.

      Parameters:
      userProvidedMap - a map from position type IDs to fully qualified class names
      Throws:
      VeniceException - if a reserved type ID is overridden with a different class
      ClassNotFoundException - if any of the provided class names cannot be loaded
  • Method Details

    • getTypeIdForFactoryClass

      public int getTypeIdForFactoryClass(String factoryClassName)
      Returns the integer type ID for the given pubsub position factory class name.
      Parameters:
      factoryClassName - the fully qualified class name of a PubSubPositionFactory implementation
      Returns:
      the integer type ID or throws an exception if the class name is not found
    • getTypeIdForFactoryInstance

      public int getTypeIdForFactoryInstance(PubSubPositionFactory pubSubPositionFactory)
      Returns the integer type ID for the given PubSubPositionFactory implementation.
      Parameters:
      pubSubPositionFactory - the PubSubPositionFactory implementation
      Returns:
      the integer type ID, or throws an exception if the factory is null
    • containsFactoryClass

      public boolean containsFactoryClass(String positionFactoryClassName)
      Checks if the given pubsub position factory class name is present in the registry.
      Parameters:
      positionFactoryClassName - the fully qualified class name of a PubSubPositionFactory implementation
      Returns:
      true if the class name is present, false otherwise
    • getFactoryByTypeId

      public PubSubPositionFactory getFactoryByTypeId(int typeId)
      Returns the fully qualified class name of the PubSubPositionFactory implementation
      Parameters:
      typeId - the integer type ID of a PubSubPosition implementation
      Returns:
      the fully qualified class name, or throws an exception if the type ID is not found
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • fromPropertiesOrDefault

      public static PubSubPositionTypeRegistry fromPropertiesOrDefault(VeniceProperties properties)
      Creates a PubSubPositionTypeRegistry from the given VeniceProperties by reading the config key ConfigKeys.PUBSUB_TYPE_ID_TO_POSITION_CLASS_NAME_MAP.

      If the key is present, it loads the type-to-class-name mapping from the config and merges it with the reserved system-defined types. If the key is not present, it returns the default registry containing only the reserved types.

      Parameters:
      properties - the VeniceProperties containing the configuration
      Returns:
      a PubSubPositionTypeRegistry constructed from the provided configuration, or the default registry if not configured
      Throws:
      VeniceException - if the provided configuration attempts to override a reserved type with a different class