Class PubSubPositionTypeRegistry
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
Reserved type IDs for internal standardPubSubPosition
implementations.static final int
static final org.apache.logging.log4j.Logger
static final int
static final it.unimi.dsi.fastutil.ints.Int2ObjectMap<String>
A predefined map of reserved PubSub position type IDs to their corresponding fully qualified factory class names.static final PubSubPositionTypeRegistry
A default, pre-configuredPubSubPositionTypeRegistry
instance that contains all reservedPubSubPosition
type IDs and their associated factory class names. -
Constructor Summary
ConstructorsConstructorDescriptionPubSubPositionTypeRegistry
(it.unimi.dsi.fastutil.ints.Int2ObjectMap<String> userProvidedMap) Constructs aPubSubPositionTypeRegistry
by merging the provided type ID to class name map with the system-defined reserved position type mappings. -
Method Summary
Modifier and TypeMethodDescriptionboolean
containsFactoryClass
(String positionFactoryClassName) Checks if the given pubsub position factory class name is present in the registry.static PubSubPositionTypeRegistry
fromPropertiesOrDefault
(VeniceProperties properties) Creates aPubSubPositionTypeRegistry
from the givenVeniceProperties
by reading the config keyConfigKeys.PUBSUB_TYPE_ID_TO_POSITION_CLASS_NAME_MAP
.getFactoryByTypeId
(int typeId) Returns the fully qualified class name of thePubSubPositionFactory
implementationint
getTypeIdForFactoryClass
(String factoryClassName) Returns the integer type ID for the given pubsub position factory class name.int
getTypeIdForFactoryInstance
(PubSubPositionFactory pubSubPositionFactory) Returns the integer type ID for the givenPubSubPositionFactory
implementation.toString()
-
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_IDReserved type IDs for internal standardPubSubPosition
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:
-2
—>PubSubSymbolicPosition.EARLIEST
: Marker for the earliest retrievable position in a partition-1
—>PubSubSymbolicPosition.LATEST
: Marker for the latest retrievable position in a partition0
—>ApacheKafkaOffsetPosition
: Standard Kafka offset-based position
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_MAPA 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
A default, pre-configuredPubSubPositionTypeRegistry
instance that contains all reservedPubSubPosition
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 asApacheKafkaOffsetPosition
.Note: This instance is read-only and should not be modified or extended at runtime.
-
-
Constructor Details
-
PubSubPositionTypeRegistry
Constructs aPubSubPositionTypeRegistry
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
, andApacheKafkaOffsetPosition
) 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, anVeniceException
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 classClassNotFoundException
- if any of the provided class names cannot be loaded
-
-
Method Details
-
getTypeIdForFactoryClass
Returns the integer type ID for the given pubsub position factory class name.- Parameters:
factoryClassName
- the fully qualified class name of aPubSubPositionFactory
implementation- Returns:
- the integer type ID or throws an exception if the class name is not found
-
getTypeIdForFactoryInstance
Returns the integer type ID for the givenPubSubPositionFactory
implementation.- Parameters:
pubSubPositionFactory
- thePubSubPositionFactory
implementation- Returns:
- the integer type ID, or throws an exception if the factory is null
-
containsFactoryClass
Checks if the given pubsub position factory class name is present in the registry.- Parameters:
positionFactoryClassName
- the fully qualified class name of aPubSubPositionFactory
implementation- Returns:
- true if the class name is present, false otherwise
-
getFactoryByTypeId
Returns the fully qualified class name of thePubSubPositionFactory
implementation- Parameters:
typeId
- the integer type ID of aPubSubPosition
implementation- Returns:
- the fully qualified class name, or throws an exception if the type ID is not found
-
toString
-
fromPropertiesOrDefault
Creates aPubSubPositionTypeRegistry
from the givenVeniceProperties
by reading the config keyConfigKeys.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
- theVeniceProperties
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
-