Class Role
java.lang.Object
io.krabka.streams.coordination.Role
- All Implemented Interfaces:
Comparable<Role>
The validated name of one coordination role, such as the name of an active
controller.
A role becomes a Kafka transactional.id. The transaction coordinator mints
one producer epoch for that id, so the role names the fenced group of members that
compete for the same leadership. All records of one role go to one partition of
CoordinationCodec.TOPIC, and RolePartitioner computes that partition
from the name.
of(String) is the only way to build a role, so every Role value
is proof that the name is well formed. The factory rejects an empty name and a name
longer than MAX_LENGTH bytes.
Example
Role controller = Role.of("controller");
producerSettings.put(ProducerConfig.TRANSACTIONAL_ID_CONFIG, controller.name());
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe maximum length of a role name, in bytes. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]bytes()Returns the UTF-8 bytes of the role name.intOrders two roles by their names.booleanReports whether another object is a role with the same name.inthashCode()Returns a hash of the role name.name()Returns the role name.static RoleParses a role name.toString()Returns the role name.
-
Field Details
-
MAX_LENGTH
public static final int MAX_LENGTHThe maximum length of a role name, in bytes.The bound is the bound Kafka puts on a topic name, so a role stays short enough to log and to compare.
- See Also:
-
-
Method Details
-
of
Parses a role name.- Parameters:
name- the role name, in UTF-8- Returns:
- the validated role
- Throws:
CoordinationException- if the name is empty or holds more thanMAX_LENGTHbytesNullPointerException- if the name is null
-
name
-
bytes
public byte[] bytes()Returns the UTF-8 bytes of the role name.RolePartitionerhashes these bytes, andCoordinationCodecwrites them into a key.- Returns:
- a fresh array of the name bytes
-
compareTo
Orders two roles by their names.- Specified by:
compareToin interfaceComparable<Role>- Parameters:
other- the role to compare against- Returns:
- a negative number, zero, or a positive number as this name sorts before, with, or after the other name
-
equals
-
hashCode
-
toString
-