Class LeaderInformationRegister
- java.lang.Object
-
- org.apache.flink.runtime.leaderelection.LeaderInformationRegister
-
public class LeaderInformationRegister extends Object
A register containing theLeaderInformationfor multiple contenders based on theircomponentId. No emptyLeaderInformationis stored physically. No entry and an entry with an emptyLeaderInformationare, therefore, semantically the same.
-
-
Constructor Summary
Constructors Constructor Description LeaderInformationRegister(Map<String,LeaderInformation> leaderInformationPerComponentId)Creates aLeaderInformationRegisterbased on the passed leader information.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static LeaderInformationRegisterclear(LeaderInformationRegister leaderInformationRegister, String componentId)Creates a newLeaderInformationRegisterthat matches the passedLeaderInformationRegisterexcept for the entry ofcomponentIdwhich is removed if it existed.static LeaderInformationRegisterempty()Optional<LeaderInformation>forComponentId(String componentId)Returns theLeaderInformationthat is stored or an emptyOptionalif no entry exists for the passedcomponentId.LeaderInformationforComponentIdOrEmpty(String componentId)Returns aLeaderInformationwhich is empty if noLeaderInformationis stored for the passedcomponentId.Iterable<String>getRegisteredComponentIds()Returns thecomponentIds for which leader information is stored.booleanhasLeaderInformation(String componentId)Checks whether the register holds non-emptyLeaderInformationfor the passedcomponentId.booleanhasNoLeaderInformation()Checks that no non-emptyLeaderInformationis stored.static LeaderInformationRegistermerge(LeaderInformationRegister leaderInformationRegister, String componentId, LeaderInformation leaderInformation)Merges anotherLeaderInformationRegisterwith additional leader information into a newLeaderInformationRegisterinstance.static LeaderInformationRegisterof(String componentId, LeaderInformation leaderInformation)Creates a single-entry instance containing only the passed information.
-
-
-
Constructor Detail
-
LeaderInformationRegister
public LeaderInformationRegister(Map<String,LeaderInformation> leaderInformationPerComponentId)
Creates aLeaderInformationRegisterbased 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 anotherLeaderInformationRegisterwith additional leader information into a newLeaderInformationRegisterinstance. Any existingLeaderInformationfor the passedcomponentIdwill be overwritten.Empty
LeaderInformationresults in the removal of the corresponding entry (if it exists).
-
clear
public static LeaderInformationRegister clear(@Nullable LeaderInformationRegister leaderInformationRegister, String componentId)
Creates a newLeaderInformationRegisterthat matches the passedLeaderInformationRegisterexcept for the entry ofcomponentIdwhich is removed if it existed.
-
forComponentId
public Optional<LeaderInformation> forComponentId(String componentId)
Returns theLeaderInformationthat is stored or an emptyOptionalif no entry exists for the passedcomponentId.
-
forComponentIdOrEmpty
public LeaderInformation forComponentIdOrEmpty(String componentId)
Returns aLeaderInformationwhich is empty if noLeaderInformationis stored for the passedcomponentId.
-
getRegisteredComponentIds
public Iterable<String> getRegisteredComponentIds()
Returns thecomponentIds for which leader information is stored.
-
hasLeaderInformation
public boolean hasLeaderInformation(String componentId)
Checks whether the register holds non-emptyLeaderInformationfor the passedcomponentId.
-
hasNoLeaderInformation
public boolean hasNoLeaderInformation()
Checks that no non-emptyLeaderInformationis stored.- Returns:
true, if there is no entry that refers to a non-emptyLeaderInformation; otherwisefalse(i.e. either no information is stored under anycomponentIdor there are entries for certaincomponentIds that refer to an emptyLeaderInformationrecord).
-
-