Class DocumentSpecialistStore
- Namespace
- IntentSharp.Specialist
- Assembly
- IntentSharp.Specialist.dll
An ISpecialistStore over the state of a core IDocumentStore, so what a SpecialistRuntime knows survives a restart and is shared by every process on the same store. It keeps, per intent and request hash, the ticket and the fit report, per intent the times of the requests, and per intent the held record of the specialist in use (HeldSpecialist). Several runtimes on one store send one request per intent and request hash and share one hourly limit; a restarted runtime waits on the request it recorded instead of sending a new one.
public sealed class DocumentSpecialistStore : ISpecialistStore
- Inheritance
-
objectDocumentSpecialistStore
- Implements
- Inherited Members
-
object.Equals(object)object.Equals(object, object)object.GetHashCode()object.GetType()object.ReferenceEquals(object, object)object.ToString()
- Extension Methods
Remarks
Each value's first version is created with the store's create-only write (TryCreateStateAsync(string, JsonNode, CancellationToken))
and every later one is a compare-and-swap with the version tag the read returned, as the client's change ledger and
trial counts are kept. A store that several processes share must override TryCreateStateAsync; both shipped
stores do.
An offer holds the specialist itself, which may be a provider object the service adapter built, so offers are kept in this instance's memory only. After a restart the runtime obtains the offer again by waiting on the recorded ticket, and reuses the recorded fit report when it was made for the same offered definition and the same specialist (OfferHash); otherwise it judges the offer again.
A held record's definition is saved as a versioned document of the store, at Prefix followed by
held/, the intent's name in lower case and .json, with a new version only when the text changes; the
rest of the record is kept in state with the version it belongs to. So a restarted runtime, or another process on the
same store, finds the specialist's name and the returned definition, and can put the specialist in use again
without asking the service when the offer named a provider configured on the client.
A request that one process began and has not yet recorded a ticket for is awaited by the others. When that process stops before the ticket is recorded, another one may send the request after ClaimTimeout. The values sit under Prefix, followed by the intent's name in lower case.
Constructors
- DocumentSpecialistStore(IDocumentStore, string?, TimeSpan?)
Creates a store.
Fields
- DefaultClaimTimeout
How long a request one process began may go without a ticket before another may send it, unless another time is given: 2 minutes.
- DefaultPrefix
The start of every state key unless another is given:
specialist/.
Properties
- ClaimTimeout
How long a begun request may go without a ticket before another process may send it.
- Prefix
The start of every state key.
- Store
The document store whose state holds the values.
Methods
- AbandonRequestAsync(string, string, CancellationToken)
Called by the runtime when a request it began with BeginRequestAsync(string, string, int, DateTimeOffset, CancellationToken) could not be sent, so another caller may send it. The request's time stays recorded. The default does nothing.
- BeginRequestAsync(string, string, int, DateTimeOffset, CancellationToken)
Called by the runtime before it sends a request, to decide who sends it: returns the ticket when one is already recorded for the intent and request hash; the hourly limit when the intent had
maxRequestsPerHourrequests in the hour beforenow; that another caller is sending it; or that this caller sends it, in which case the request is recorded atnowand counts toward the limit. The default reads the ticket and the count and then records the request, which is not atomic: a store that several processes share overrides it so that one of them sends each request and the limit holds across them, as DocumentSpecialistStore does.
- CountRequestsAsync(string, DateTimeOffset, CancellationToken)
The number of requests recorded for the intent at or after
since.
- GetFitReportAsync(string, string, CancellationToken)
The fit report recorded for the intent and request hash, or null.
- GetHeldAsync(string, CancellationToken)
The held record of the intent, or null. The default answers null.
- GetOfferAsync(string, string, CancellationToken)
The offer recorded for the intent and request hash, or null.
- GetTicketAsync(string, string, CancellationToken)
The ticket recorded for the intent and request hash, or null.
- ListHeldAsync(CancellationToken)
Every held record, one per intent, in no set order. The default answers none.
- RecordRequestAsync(string, DateTimeOffset, CancellationToken)
Records that a request was sent for the intent at
at.
- RemoveAsync(string, string, CancellationToken)
Forgets the ticket, the offer and the fit report recorded for the intent and request hash. The request times stay.
- RemoveHeldAsync(string, CancellationToken)
Forgets the held record of the intent. The default does nothing.
- SaveFitReportAsync(string, FitReport, CancellationToken)
Records the verdict on the offer of a request, under its RequestHash.
- SaveHeldAsync(HeldSpecialist, CancellationToken)
Keeps the held record of the specialist put in use for an intent, replacing the one held for that intent before. The default keeps nothing, so a store that does not implement the held members never recalls a specialist.
- SaveOfferAsync(string, string, SpecialistOffer, CancellationToken)
Records the offer received for a request.
- SaveTicketAsync(string, SpecialistTicket, CancellationToken)
Records the ticket of a request, under its request hash.