Table of Contents

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 int

The counter for this clock.

nodeId string

The node identifier for this clock.

Properties

Counter

The counter for this hybrid logical clock.

public int Counter { get; set; }

Property Value

int

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

string

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

DateTime

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

int

DecodeFromString(string, string)

public static HybridLogicalClock DecodeFromString(string propertyName, string encoded)

Parameters

propertyName string
encoded string

Returns

HybridLogicalClock

DisposeAsync()

Asynchronously releases the resources used by the ApplicationContext.

public ValueTask DisposeAsync()

Returns

ValueTask

DisposeAsyncCore()

protected virtual ValueTask DisposeAsyncCore()

Returns

ValueTask

EncodeToString()

public string EncodeToString()

Returns

string

Equals(object?)

Determines whether the specified object is equal to the current object.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current object.

Returns

bool

true if the specified object is equal to the current object; otherwise, false.

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 CancellationToken

A token to cancel the operation.

Returns

Task<string>

String representation of the updated HLC.

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 HybridLogicalClock

The other HLC to update against.

maxClockDrift TimeSpan?

Maximum allowed clock drift. Defaults to 1 minute if not specified.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task

Exceptions

ObjectDisposedException

If this instance has been disposed.

OperationCanceledException

If the operation is canceled.