Class LeaderInformationRegister
- java.lang.Object
-
- org.apache.flink.runtime.leaderelection.LeaderInformationRegister
-
public class LeaderInformationRegister extends Object
A register containing theLeaderInformation
for multiple contenders based on theircomponentId
. No emptyLeaderInformation
is stored physically. No entry and an entry with an emptyLeaderInformation
are, therefore, semantically the same.
-
-
Constructor Summary
Constructors Constructor Description LeaderInformationRegister(Map<String,LeaderInformation> leaderInformationPerComponentId)
Creates aLeaderInformationRegister
based on the passed leader information.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static LeaderInformationRegister
clear(LeaderInformationRegister leaderInformationRegister, String componentId)
Creates a newLeaderInformationRegister
that matches the passedLeaderInformationRegister
except for the entry ofcomponentId
which is removed if it existed.static LeaderInformationRegister
empty()
Optional<LeaderInformation>
forComponentId(String componentId)
Returns theLeaderInformation
that is stored or an emptyOptional
if no entry exists for the passedcomponentId
.LeaderInformation
forComponentIdOrEmpty(String componentId)
Returns aLeaderInformation
which is empty if noLeaderInformation
is stored for the passedcomponentId
.Iterable<String>
getRegisteredComponentIds()
Returns thecomponentId
s for which leader information is stored.boolean
hasLeaderInformation(String componentId)
Checks whether the register holds non-emptyLeaderInformation
for the passedcomponentId
.boolean
hasNoLeaderInformation()
Checks that no non-emptyLeaderInformation
is stored.static LeaderInformationRegister
merge(LeaderInformationRegister leaderInformationRegister, String componentId, LeaderInformation leaderInformation)
Merges anotherLeaderInformationRegister
with additional leader information into a newLeaderInformationRegister
instance.static LeaderInformationRegister
of(String componentId, LeaderInformation leaderInformation)
Creates a single-entry instance containing only the passed information.
-
-
-
Constructor Detail
-
LeaderInformationRegister
public LeaderInformationRegister(Map<String,LeaderInformation> leaderInformationPerComponentId)
Creates aLeaderInformationRegister
based on the passed leader information.
-
-
Method Detail
-
empty
public static LeaderInformationRegister empty()
-
of
public static LeaderInformationRegister of(String componentId, LeaderInformation leaderInformation)
Creates a single-entry instance containing only the passed information.
-
merge
public static LeaderInformationRegister merge(@Nullable LeaderInformationRegister leaderInformationRegister, String componentId, LeaderInformation leaderInformation)
Merges anotherLeaderInformationRegister
with additional leader information into a newLeaderInformationRegister
instance. Any existingLeaderInformation
for the passedcomponentId
will be overwritten.Empty
LeaderInformation
results in the removal of the corresponding entry (if it exists).
-
clear
public static LeaderInformationRegister clear(@Nullable LeaderInformationRegister leaderInformationRegister, String componentId)
Creates a newLeaderInformationRegister
that matches the passedLeaderInformationRegister
except for the entry ofcomponentId
which is removed if it existed.
-
forComponentId
public Optional<LeaderInformation> forComponentId(String componentId)
Returns theLeaderInformation
that is stored or an emptyOptional
if no entry exists for the passedcomponentId
.
-
forComponentIdOrEmpty
public LeaderInformation forComponentIdOrEmpty(String componentId)
Returns aLeaderInformation
which is empty if noLeaderInformation
is stored for the passedcomponentId
.
-
getRegisteredComponentIds
public Iterable<String> getRegisteredComponentIds()
Returns thecomponentId
s for which leader information is stored.
-
hasLeaderInformation
public boolean hasLeaderInformation(String componentId)
Checks whether the register holds non-emptyLeaderInformation
for the passedcomponentId
.
-
hasNoLeaderInformation
public boolean hasNoLeaderInformation()
Checks that no non-emptyLeaderInformation
is stored.- Returns:
true
, if there is no entry that refers to a non-emptyLeaderInformation
; otherwisefalse
(i.e. either no information is stored under anycomponentId
or there are entries for certaincomponentId
s that refer to an emptyLeaderInformation
record).
-
-