Record Class BijectiveNodeIdMapping
java.lang.Object
java.lang.Record
io.kroxylicious.proxy.internal.routing.BijectiveNodeIdMapping
- All Implemented Interfaces:
NodeIdMapping
public record BijectiveNodeIdMapping(Map<String,Integer> routeIds, int totalRoutes)
extends Record
implements NodeIdMapping
Bijective node ID mapping:
V = id + S × t, where
V is the virtual ID, t is the target node ID,
S is the total number of routes, and id is
the route's configured identifier.
Example with two routes (S=2) whose upstream clusters each have node IDs 0, 1, 2:
route[0] (id=0): V = 0 + 2×0, 0 + 2×1, 0 + 2×2 → 0, 2, 4 route[1] (id=1): V = 1 + 2×0, 1 + 2×1, 1 + 2×2 → 1, 3, 5
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.kroxylicious.proxy.internal.routing.NodeIdMapping
NodeIdMapping.RouteAndNode -
Constructor Summary
ConstructorsConstructorDescriptionBijectiveNodeIdMapping(Map<String, Integer> routeIds, int totalRoutes) Creates an instance of aBijectiveNodeIdMappingrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.fromVirtual(int virtualNodeId) Translates a virtual node ID back to its route and target-cluster node ID.intfromVirtual(String route, int virtualNodeId) Translates a virtual node ID back to its target-cluster node ID, given the route.final inthashCode()Returns a hash code value for this object.routeIds()Returns the value of therouteIdsrecord component.final StringtoString()Returns a string representation of this record class.intReturns the value of thetotalRoutesrecord component.intTranslates a target-cluster node ID to a virtual node ID.
-
Constructor Details
-
BijectiveNodeIdMapping
Creates an instance of aBijectiveNodeIdMappingrecord class.- Parameters:
routeIds- the value for therouteIdsrecord componenttotalRoutes- the value for thetotalRoutesrecord component
-
-
Method Details
-
toVirtual
Description copied from interface:NodeIdMappingTranslates a target-cluster node ID to a virtual node ID.Negative values (Kafka protocol sentinels such as
-1"no leader") are returned unchanged and must not be fed into the translation formula.- Specified by:
toVirtualin interfaceNodeIdMapping- Parameters:
route- the route nametargetNodeId- the node ID on the target cluster- Returns:
- the virtual node ID, or
targetNodeIdunchanged if negative
-
fromVirtual
Description copied from interface:NodeIdMappingTranslates a virtual node ID back to its target-cluster node ID, given the route. The route is always supplied by the router viaRouterContext.sendRequest(io.kroxylicious.proxy.topology.VirtualNode, org.apache.kafka.common.message.RequestHeaderData, org.apache.kafka.common.protocol.ApiMessage).As with
NodeIdMapping.toVirtual(java.lang.String, int), negative values are returned unchanged.- Specified by:
fromVirtualin interfaceNodeIdMapping- Parameters:
route- the route namevirtualNodeId- the virtual node ID- Returns:
- the target-cluster node ID, or
virtualNodeIdunchanged if negative
-
fromVirtual
Description copied from interface:NodeIdMappingTranslates a virtual node ID back to its route and target-cluster node ID. Only works for dedicated (one-to-one) mappings where the route can be recovered from the virtual node ID alone.Behaviour is undefined for negative inputs; proxy port node IDs are always non-negative and this method is never called with a sentinel value.
- Specified by:
fromVirtualin interfaceNodeIdMapping- Parameters:
virtualNodeId- the virtual node ID- Returns:
- the route name and target node ID
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
routeIds
Returns the value of therouteIdsrecord component.- Returns:
- the value of the
routeIdsrecord component
-
totalRoutes
public int totalRoutes()Returns the value of thetotalRoutesrecord component.- Returns:
- the value of the
totalRoutesrecord component
-