Class HybridLogicalClock
- Namespace
- Azure.Iot.Operations.Protocol
- Assembly
- Azure.Iot.Operations.Protocol.dll
public class HybridLogicalClock : IAsyncDisposable
- Inheritance
-
HybridLogicalClock
- Implements
- Inherited Members
Constructors
HybridLogicalClock(HybridLogicalClock)
Copy construct a HybridLogicalClock from another HybridLogicalClock
public HybridLogicalClock(HybridLogicalClock other)
Parameters
other
HybridLogicalClock
HybridLogicalClock(DateTime?, int, string?)
Construct a HybridLogicalClock instance.
public HybridLogicalClock(DateTime? timestamp = null, int counter = 0, string? nodeId = null)
Parameters
timestamp
DateTime?The timestamp for this clock. This timestamp will be rounded down to the nearest millisecond.
counter
intThe counter for this clock.
nodeId
stringThe node identifier for this clock.
Properties
Counter
The counter for this hybrid logical clock.
public int Counter { get; set; }
Property Value
Remarks
This counter is used in conjunction with the Timestamp to coordinate ordering of events within a distributed system where each device may have slightly different system clock times.
NodeId
A unique identifier for this node.
public string NodeId { get; }
Property Value
Remarks
This is only used to break ties where both the counter and timestamp of two competing nodes are exactly the same.
Timestamp
The current timestamp for this hybrid logical clock.
public DateTime Timestamp { get; set; }
Property Value
Remarks
This value is used in conjunction with Counter to coordinate ordering of events within a distributed system where each device may have slightly different system clock times.
This timestamp only allows for millisecond-level precision. Any provided value will automatically be rounded down to the nearest millisecond.
Methods
CompareTo(HybridLogicalClock)
public int CompareTo(HybridLogicalClock other)
Parameters
other
HybridLogicalClock
Returns
DecodeFromString(string, string)
public static HybridLogicalClock DecodeFromString(string propertyName, string encoded)
Parameters
Returns
DisposeAsync()
Asynchronously releases the resources used by the ApplicationContext.
public ValueTask DisposeAsync()
Returns
DisposeAsyncCore()
protected virtual ValueTask DisposeAsyncCore()
Returns
EncodeToString()
public string EncodeToString()
Returns
Equals(object?)
Determines whether the specified object is equal to the current object.
public override bool Equals(object? obj)
Parameters
obj
objectThe object to compare with the current object.
Returns
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.
UpdateNowAsync(TimeSpan?, CancellationToken)
Updates the application's HybridLogicalClock based on the current time and returns its string representation.
public Task<string> UpdateNowAsync(TimeSpan? maxClockDrift = null, CancellationToken cancellationToken = default)
Parameters
maxClockDrift
TimeSpan?Maximum allowed clock drift. Defaults to 1 minute if not specified.
cancellationToken
CancellationTokenA token to cancel the operation.
Returns
Exceptions
- ObjectDisposedException
If this instance has been disposed.
- OperationCanceledException
If the operation is canceled.
UpdateWithOtherAsync(HybridLogicalClock, TimeSpan?, CancellationToken)
Updates the application's HybridLogicalClock based on another HybridLogicalClock.
public Task UpdateWithOtherAsync(HybridLogicalClock other, TimeSpan? maxClockDrift = null, CancellationToken cancellationToken = default)
Parameters
other
HybridLogicalClockThe other HLC to update against.
maxClockDrift
TimeSpan?Maximum allowed clock drift. Defaults to 1 minute if not specified.
cancellationToken
CancellationTokenA token to cancel the operation.
Returns
Exceptions
- ObjectDisposedException
If this instance has been disposed.
- OperationCanceledException
If the operation is canceled.