Skip to content

InMemorySingletonLeaseStore

Namespace AgentPrism · Assembly AgentPrism.Core.dll

A store that keeps singleton execution leases in process memory.

public sealed class InMemorySingletonLeaseStore : ISingletonLeaseStore

objectInMemorySingletonLeaseStore

ISingletonLeaseStore

object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

In a single-process deployment, it always acquires the lease because there is no competitor. A multi-process deployment needs a SQL provider, SqlSingletonLeaseStore, for real coordination.

Limits: process lifetime and a single node.

InMemorySingletonLeaseStore(TimeProvider?)

Section titled “ InMemorySingletonLeaseStore(TimeProvider?)”

Initializes a new in-memory lease store.

public InMemorySingletonLeaseStore(TimeProvider? timeProvider = null)

timeProvider TimeProvider?

The time provider. Uses TimeProvider.System when omitted.

ReleaseAsync(string, string, CancellationToken)

Section titled “ ReleaseAsync(string, string, CancellationToken)”

Releases the lease. It does nothing when the caller is not the owner.

public ValueTask ReleaseAsync(string name, string ownerId, CancellationToken cancellationToken = default)

name string

The name of the lease.

ownerId string

The id of the instance that claims to hold the lease.

cancellationToken CancellationToken

The cancellation token.

ValueTask

A task that completes when the work is done.

RenewAsync(string, string, TimeSpan, CancellationToken)

Section titled “ RenewAsync(string, string, TimeSpan, CancellationToken)”

Extends the lease that is held. It returns false when the lease has moved to someone else — the caller MUST then drop the job.

public ValueTask<bool> RenewAsync(string name, string ownerId, TimeSpan duration, CancellationToken cancellationToken = default)

name string

The name of the lease.

ownerId string

The id of the instance that claims to hold the lease.

duration TimeSpan

The new lease duration.

cancellationToken CancellationToken

The cancellation token.

ValueTask<bool>

true when the renewal succeeded.

TryAcquireAsync(string, string, TimeSpan, CancellationToken)

Section titled “ TryAcquireAsync(string, string, TimeSpan, CancellationToken)”

Tries to take the lease. It returns false when someone else holds the lease and it has not expired.

public ValueTask<bool> TryAcquireAsync(string name, string ownerId, TimeSpan duration, CancellationToken cancellationToken = default)

name string

The name of the lease (the id of the protected job).

ownerId string

The id of this instance.

duration TimeSpan

How long the lease stays valid.

cancellationToken CancellationToken

The cancellation token.

ValueTask<bool>

true when the lease was taken.