Hazelcast Cluster

class ClusterService(internal_cluster_service)[source]

Bases: object

Cluster service for Hazelcast clients.

It provides access to the members in the cluster and one can register for changes in the cluster members.

add_listener(member_added: Optional[Callable[[MemberInfo], None]] = None, member_removed: Optional[Callable[[MemberInfo], None]] = None, fire_for_existing=False) str[source]

Adds a membership listener to listen for membership updates.

It will be notified when a member is added to the cluster or removed from the cluster. There is no check for duplicate registrations, so if you register the listener twice, it will get events twice.

Parameters:
  • member_added – Function to be called when a member is added to the cluster.

  • member_removed – Function to be called when a member is removed from the cluster.

  • fire_for_existing – Whether or not fire member_added for existing members.

Returns:

Registration id of the listener which will be used for removing this listener.

remove_listener(registration_id: str) bool[source]

Removes the specified membership listener.

Parameters:

registration_id – Registration id of the listener to be removed.

Returns:

True if the registration is removed, False otherwise.

get_members(member_selector: Optional[Callable[[MemberInfo], bool]] = None) List[MemberInfo][source]

Lists the current members in the cluster.

Every member in the cluster returns the members in the same order. To obtain the oldest member in the cluster, you can retrieve the first item in the list.

Parameters:

member_selector – Function to filter members to return. If not provided, the returned list will contain all the available cluster members.

Returns:

Current members in the cluster