Package com.linkedin.venice.pubsub
Class PubSubPositionFactory
java.lang.Object
com.linkedin.venice.pubsub.PubSubPositionFactory
- Direct Known Subclasses:
ApacheKafkaOffsetPositionFactory
,EarliestPositionFactory
,LatestPositionFactory
A factory interface for creating
PubSubPosition
instances and resolving their associated class names.
Each implementation is tied to a unique position type ID and is responsible for:
- Deserializing a
PubSubPosition
from itsPubSubPositionWireFormat
- Returning the class name of the position type it handles
Factories are used during deserialization to map a type ID to the appropriate PubSubPosition
implementation.
-
Constructor Summary
ConstructorsConstructorDescriptionPubSubPositionFactory
(int positionTypeId) Constructs a factory with the given position type ID. -
Method Summary
Modifier and TypeMethodDescriptionabstract PubSubPosition
createFromByteBuffer
(ByteBuffer buffer) Deserializes aPubSubPosition
from the given byte buffer.createFromWireFormat
(PubSubPositionWireFormat positionWireFormat) Creates aPubSubPosition
instance by deserializing the providedPubSubPositionWireFormat
.int
Returns the unique position type ID associated with this factory.abstract String
Returns the fully qualified class name of thePubSubPosition
implementation handled by this factory.
-
Constructor Details
-
PubSubPositionFactory
public PubSubPositionFactory(int positionTypeId) Constructs a factory with the given position type ID.- Parameters:
positionTypeId
- the unique integer identifier for the position type
-
-
Method Details
-
createFromWireFormat
Creates aPubSubPosition
instance by deserializing the providedPubSubPositionWireFormat
.This method validates that the type ID in the wire format matches the expected type ID for this factory. If the type ID does not match, an exception is thrown to prevent incorrect deserialization.
Internally, this delegates to
createFromByteBuffer(ByteBuffer)
to perform the actual decoding.- Parameters:
positionWireFormat
- the wire format containing the type ID and raw encoded bytes- Returns:
- a new
PubSubPosition
instance reconstructed from the wire format - Throws:
VeniceException
- if the type ID does not match the factory's expected type
-
createFromByteBuffer
Deserializes aPubSubPosition
from the given byte buffer.- Parameters:
buffer
- the byte buffer containing the serialized position- Returns:
- a new
PubSubPosition
instance
-
getPubSubPositionClassName
Returns the fully qualified class name of thePubSubPosition
implementation handled by this factory.- Returns:
- the fully qualified class name of the associated position class
-
getPositionTypeId
public int getPositionTypeId()Returns the unique position type ID associated with this factory.- Returns:
- the integer type ID
-