P
- type of the peer's statuspublic interface PeerMonitor<P> extends Observable<PeerListener<P>>
Peer monitor allows peers to get status from each other. Sometimes defining
a status for the entire node does not work because by the time the node is
recognized as active, some services may not be. As an example imagine a
component based application where components are initialized following a
particular order. Some components may not be ready by the time the node is
recognized as reachable (either active or inactive). Using a
PeerMonitor
components will get notifications of their peers, which
are the ones they interact with in a distributed system.
One example would be the usage of PublishSubscribeService
. Using
PeerMonitor
components would make sure when the peers are ready to
receive messages (They have subscribed).
-------------------------------- -------------------------------- | ... | | ... | | -------------------------- | | -------------------------- | | | Layer k+1 | | <-- Peer Monitor K+1 --> | | Layer k+1 | | | -------------------------- | | -------------------------- | | -------------------------- | | -------------------------- | | | Layer k | | <-- Peer Monitor K --> | | Layer k | | | -------------------------- | | -------------------------- | | ... | | ... | -------------------------------- -------------------------------- Node i Node j
Note that layer could be a component, service, application, etc. Any distributed algorithm that coordinates with its peers.
Modifier and Type | Method and Description |
---|---|
Collection<Pair<Node,P>> |
getKnownPeers()
Gets known peers (including the local peer if its initial state has
been reported via
updateLocalPeer(Object) ) which are the peers
for which the state is considered up to date. |
Collection<Pair<Node,P>> |
getUnknownPeers()
Gets unknown peers (including the local peer if its initial state has
not been reported via
updateLocalPeer(Object) ) which are the
peers for which the state is considered unknown or out of date: These
are peers that have never joined the cluster, peers that have not
reported status after they left, or peers that previously reported
status but the node they belong to are not part of
ClusterService.getActiveNodes() . |
void |
updateLocalPeer(P localPeer)
Updates the state of the local peer.
|
register, unregister
void updateLocalPeer(P localPeer)
This method should be called when the initial state of the local peer is available, and after that when such state changes.
localPeer
- local peerCollection<Pair<Node,P>> getKnownPeers()
updateLocalPeer(Object)
) which are the peers
for which the state is considered up to date. These are peers that have
reported status and for which the node they belong to are part of
ClusterService.getActiveNodes()
. Note that a peer is only known
if it has reported status after joining the cluster; Thus, a node that
is part of ClusterService.getActiveNodes()
is not guaranteed to
be known.Collection<Pair<Node,P>> getUnknownPeers()
updateLocalPeer(Object)
) which are the
peers for which the state is considered unknown or out of date: These
are peers that have never joined the cluster, peers that have not
reported status after they left, or peers that previously reported
status but the node they belong to are not part of
ClusterService.getActiveNodes()
.
The peer's status included in the result is the last known if
available, otherwise null
.
Copyright © 2015. All Rights Reserved.