Class PeerController
Represents local peer supporting HyParView membership protocol for Gossip-based broadcast.
Inherited Members
Namespace: DotNext.Net.Cluster.Discovery.HyParView
Assembly: DotNext.Net.Cluster.dll
Syntax
public abstract class PeerController : Disposable, IDisposable, IPeerMesh, IAsyncDisposable
Remarks
This controller implements core logic of HyParView algorithm without transport-specific details.
Constructors
| Edit this page View SourcePeerController(IPeerConfiguration)
Initializes a new HyParView protocol controller.
Declaration
protected PeerController(IPeerConfiguration configuration)
Parameters
Type | Name | Description |
---|---|---|
IPeerConfiguration | configuration | The configuration of the algorithm. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
Properties
| Edit this page View SourceLifecycleToken
Gets the token associated with the lifecycle of this object.
Declaration
protected CancellationToken LifecycleToken { get; }
Property Value
Type | Description |
---|---|
CancellationToken |
Logger
Gets the logger associated with this controller.
Declaration
[CLSCompliant(false)]
protected virtual ILogger Logger { get; }
Property Value
Type | Description |
---|---|
ILogger |
Neighbors
Gets a collection of discovered peers.
Declaration
public IReadOnlySet<EndPoint> Neighbors { get; }
Property Value
Type | Description |
---|---|
IReadOnlySet<EndPoint> |
PeerComparer
Gets peer address comparer.
Declaration
protected IEqualityComparer<EndPoint> PeerComparer { get; }
Property Value
Type | Description |
---|---|
IEqualityComparer<EndPoint> |
Methods
| Edit this page View SourceDestroy(EndPoint)
Releases all local resources associated with the remote peer.
Declaration
protected virtual void Destroy(EndPoint peer)
Parameters
Type | Name | Description |
---|---|---|
EndPoint | peer | The peer to destroy. |
Remarks
By default, this method does nothing.
DestroyAsync(EndPoint)
Releases all local resources associated with the remote peer.
Declaration
protected virtual ValueTask DestroyAsync(EndPoint peer)
Parameters
Type | Name | Description |
---|---|---|
EndPoint | peer | The peer to dispose. |
Returns
Type | Description |
---|---|
ValueTask | The task representing asynchronous result of the operation. |
Remarks
By default, this method does nothing.
DisconnectAsync(EndPoint)
Called automatically when the connection to the remote peer can be closed.
Declaration
protected virtual ValueTask DisconnectAsync(EndPoint peer)
Parameters
Type | Name | Description |
---|---|---|
EndPoint | peer | The peer to disconnect. |
Returns
Type | Description |
---|---|
ValueTask | The task representing asynchronous result of the operation. |
Remarks
Calling of this method indicates that the peer is no longer available.
DisconnectAsync(EndPoint, bool, CancellationToken)
Sends Disconnect notification to the peer.
Declaration
protected abstract Task DisconnectAsync(EndPoint peer, bool isAlive, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
EndPoint | peer | The receiver of the notification. |
bool | isAlive | true if sender remains alive; false if sender is shutting down gracefully. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
Task | The task representing asynchronous result of the operation. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
Dispose(bool)
Releases managed and unmanaged resources associated with this object.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing | true if called from Dispose(); false if called from finalizer ~Disposable(). |
Overrides
| Edit this page View SourceDisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
Declaration
public ValueTask DisposeAsync()
Returns
Type | Description |
---|---|
ValueTask | A task that represents the asynchronous dispose operation. |
DisposeAsyncCore()
Releases managed resources associated with this object asynchronously.
Declaration
protected override ValueTask DisposeAsyncCore()
Returns
Type | Description |
---|---|
ValueTask | The task representing asynchronous execution of this method. |
Overrides
Remarks
This method makes sense only if derived class implements IAsyncDisposable interface.
EnqueueBroadcastAsync(Func<PeerController, IRumorSender>, CancellationToken)
Spreads the rumor across neighbors.
Declaration
public ValueTask EnqueueBroadcastAsync(Func<PeerController, IRumorSender> senderFactory, CancellationToken token = default)
Parameters
Type | Name | Description |
---|---|---|
Func<PeerController, IRumorSender> | senderFactory | The rumour sender factory. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
ValueTask | The task representing asynchronous result. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
ObjectDisposedException | The controller has been disposed. |
EnqueueDisconnectAsync(EndPoint, bool, CancellationToken)
Must be called by transport layer when Disconnect request is received.
Declaration
protected ValueTask EnqueueDisconnectAsync(EndPoint sender, bool isAlive, CancellationToken token = default)
Parameters
Type | Name | Description |
---|---|---|
EndPoint | sender | The sender of the request which is about to disconnect. |
bool | isAlive | true if the sender remains alive after disconnect; false if the sender is disconnected gracefully and will no longer available in the cluster. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
ValueTask | The task representing asynchronous result. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
ObjectDisposedException | The controller has been disposed. |
EnqueueForwardJoinAsync(EndPoint, EndPoint, int, CancellationToken)
Must be called by transport layer when ForwardJoin request is received.
Declaration
protected ValueTask EnqueueForwardJoinAsync(EndPoint sender, EndPoint joinedPeer, int timeToLive, CancellationToken token = default)
Parameters
Type | Name | Description |
---|---|---|
EndPoint | sender | The sender of the request. |
EndPoint | joinedPeer | The joined peer. |
int | timeToLive | The number of hops the request is forwarded. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
ValueTask | The task representing asynchronous result. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
ObjectDisposedException | The controller has been disposed. |
EnqueueJoinAsync(EndPoint, CancellationToken)
Must be called by transport layer when Join request is received.
Declaration
protected ValueTask EnqueueJoinAsync(EndPoint joinedPeer, CancellationToken token = default)
Parameters
Type | Name | Description |
---|---|---|
EndPoint | joinedPeer | The joined peer. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
ValueTask | The task representing asynchronous result. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
ObjectDisposedException | The controller has been disposed. |
EnqueueNeighborAsync(EndPoint, bool, CancellationToken)
Must be called by transport layer when Neighbor request is received.
Declaration
protected ValueTask EnqueueNeighborAsync(EndPoint sender, bool highPriority, CancellationToken token = default)
Parameters
Type | Name | Description |
---|---|---|
EndPoint | sender | The announcement of the neighbor peer. |
bool | highPriority | true to replace another peer from the current active view with the announced peer; false to place the announced peer to the current passive view if active view is full. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
ValueTask | The task representing asynchronous result. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
ObjectDisposedException | The controller has been disposed. |
EnqueueShuffleAsync(EndPoint, EndPoint, IReadOnlyCollection<EndPoint>, int, CancellationToken)
Must be called by transport layer when Shuffle request is received.
Declaration
protected ValueTask EnqueueShuffleAsync(EndPoint sender, EndPoint origin, IReadOnlyCollection<EndPoint> peers, int timeToLive, CancellationToken token = default)
Parameters
Type | Name | Description |
---|---|---|
EndPoint | sender | The announcement of the neighbor peer. |
EndPoint | origin | The initial sender of the request. |
IReadOnlyCollection<EndPoint> | peers | The portion of active and passive view randomly selected by the initial sender. |
int | timeToLive | The number of random hops the request is forwarded. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
ValueTask | The task representing asynchronous result. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
ObjectDisposedException | The controller has been disposed. |
EnqueueShuffleAsync(CancellationToken)
Forces sending of Shuffle message to randomly selected peer from active view.
Declaration
public ValueTask EnqueueShuffleAsync(CancellationToken token = default)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
ValueTask | The task representing asynchronous result. |
Remarks
Use this method only if ShufflePeriod is set to null.
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
ObjectDisposedException | The controller has been disposed. |
InvalidOperationException | Manual shuffle is not allowed. |
EnqueueShuffleReplyAsync(IReadOnlyCollection<EndPoint>, CancellationToken)
Must be called by transport layer when Shuffle reply is received.
Declaration
protected ValueTask EnqueueShuffleReplyAsync(IReadOnlyCollection<EndPoint> peers, CancellationToken token = default)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyCollection<EndPoint> | peers | The portion of passive view randomly selected by the final receiver of Shuffle request. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
ValueTask | The task representing asynchronous result. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
ObjectDisposedException | The controller has been disposed. |
ForwardJoinAsync(EndPoint, EndPoint, int, CancellationToken)
Sends ForwardJoin request to the peer.
Declaration
protected abstract Task ForwardJoinAsync(EndPoint receiver, EndPoint joinedPeer, int timeToLive, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
EndPoint | receiver | The receiver of the message. |
EndPoint | joinedPeer | The joined peer. |
int | timeToLive | TTL value that controlls broadcast of ForwardJoin request. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
Task | The task representing asynchronous result of the operation. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
IsLocalNode(EndPoint)
Determines whether the address of the local node is equal to the specified address.
Declaration
protected abstract bool IsLocalNode(EndPoint peer)
Parameters
Type | Name | Description |
---|---|---|
EndPoint | peer | The peer address to compare. |
Returns
Type | Description |
---|---|
bool |
JoinAsync(EndPoint, CancellationToken)
Sends Join request to contact node.
Declaration
protected abstract Task JoinAsync(EndPoint contactNode, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
EndPoint | contactNode | The address of the contact node. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
Task | The task representing communication operation. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
NeighborAsync(EndPoint, bool, CancellationToken)
Sends Neighbor message to the specified peer.
Declaration
protected abstract Task NeighborAsync(EndPoint neighbor, bool highPriority, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
EndPoint | neighbor | The receiver of the message. |
bool | highPriority | true to add the peer to the active view of receiver even if view is full; otherwise, false. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
Task | The task representing asynchronous result of the operation. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
OnError(EndPoint, Exception)
Reports communication error associated with the peer.
Declaration
protected virtual void OnError(EndPoint peer, Exception e)
Parameters
Type | Name | Description |
---|---|---|
EndPoint | peer | The unavailable peer. |
Exception | e | The exception describing communication issue. |
ReportFailedPeerAsync(EndPoint, CancellationToken)
Reports failed peer.
Declaration
public ValueTask ReportFailedPeerAsync(EndPoint failedPeer, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
EndPoint | failedPeer | The address of the failed peer. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
ValueTask | The task representing asynchronous result. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
ObjectDisposedException | The controller has been disposed. |
ShuffleAsync(EndPoint, EndPoint?, IReadOnlyCollection<EndPoint>, int, CancellationToken)
Sends Shuffle message to the specified peer.
Declaration
protected abstract Task ShuffleAsync(EndPoint receiver, EndPoint? origin, IReadOnlyCollection<EndPoint> peers, int timeToLive, CancellationToken token = default)
Parameters
Type | Name | Description |
---|---|---|
EndPoint | receiver | The receiver of the message. |
EndPoint | origin | The original sender of the initial Shuffle message; or null if the current peer is the sender of the message. |
IReadOnlyCollection<EndPoint> | peers | The collection of peers to announce. |
int | timeToLive | The number of hops to reach the receiver of the message. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
Task | The task representing asynchronous result of the operation. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
ShuffleReplyAsync(EndPoint, IReadOnlyCollection<EndPoint>, CancellationToken)
Sends reply to the original sender of Shuffle message.
Declaration
protected abstract Task ShuffleReplyAsync(EndPoint receiver, IReadOnlyCollection<EndPoint> peers, CancellationToken token = default)
Parameters
Type | Name | Description |
---|---|---|
EndPoint | receiver | The original sender of Shuffle message. |
IReadOnlyCollection<EndPoint> | peers | The portion of peers from local passive view. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
Task | The task representing asynchronous result of the operation. |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | The operation has been canceled. |
StartAsync(EndPoint?, CancellationToken)
Starts serving HyParView messages and join to the cluster.
Declaration
public Task StartAsync(EndPoint? contactNode, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
EndPoint | contactNode | The contact node used to announce the current peer. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
Task | The task representing asynchronous result of the operation. |
StopAsync(CancellationToken)
Gracefully shutdowns this peer.
Declaration
public virtual Task StopAsync(CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
Task | The task representing asynchronous result of the operation. |
Events
| Edit this page View SourcePeerDiscovered
An event raised when a new remote peer has been discovered.
Declaration
public event Action<PeerController, PeerEventArgs> PeerDiscovered
Event Type
Type | Description |
---|---|
Action<PeerController, PeerEventArgs> |
PeerGone
An event raised when the visible neighbor becomes unavailable.
Declaration
public event Action<PeerController, PeerEventArgs> PeerGone
Event Type
Type | Description |
---|---|
Action<PeerController, PeerEventArgs> |