pymap.cluster

class pymap.cluster.MemberInterface(*args, **kwargs)[source]

A hashable type that represents a cluster member node.

abstract property name: str

The name of the cluster member node.

abstract property metadata: Mapping[str, bytes]

The metadata mapping from the cluster member node.

class pymap.cluster.ListenCallback(*args, **kwargs)[source]
abstract __call__(arg, /, metadata)[source]

Called when the value associated with a local metadata key has been changed.

Parameters:
  • arg (ArgT_contra) – The argument given when the callback was registered with listen().

  • metadata (Mapping[str, bytes]) – The updated local metadata mapping.

Return type:

None

class pymap.cluster.ClusterMetadata(init=None, /)[source]

Keeps a mapping of metadata pertaining to the current instance and possibly other clustered instances, if the current instance is part of a cluster.

The object also acts as a set of MemberInterface objects. The cluster service should add new or updated members and discard them as they go offline.

Parameters:

init (Collection[MemberInterface] | None) – Initial remote cluster members.

add(member)[source]

Add an element.

Parameters:

member (MemberInterface)

Return type:

None

discard(member)[source]

Remove an element. Do not raise an exception if absent.

Parameters:

member (MemberInterface)

Return type:

None

property local: MutableMapping[str, bytes]

The local cluster instance metadata. Keys added, removed, and modified in this mapping should be disseminated to the rest of the cluster.

property remote: Mapping[str, Mapping[MemberInterface, bytes]]

The remote cluster instance metadata, organized by metadata key.

get_all(key)[source]

Returns the set of all known values for the metadata key, local and remote.

Parameters:

key (str) – The metadata key.

Return type:

Set[bytes]

listen(callback, arg)[source]

Adds a callback to be run whenever the local metadata has been modified. Cluster services can use this to disseminate metadata changes.

Note

The arg object is weakly referenced, and the callback will be automatically removed if it is garbage-collected.

Parameters:
  • callback (ListenCallback[ArgT]) – Function called with the updated local metadata mapping.

  • arg (ArgT) – The first argument passed to callback.

Return type:

None

pymap.cluster.swim