EntryStatus
EntryStatus represents status flags of an IEntry object:
Enum | Description |
---|---|
Unassigned | Initial state. Query processing has not started. |
Processing | State is set when handlers start processing the request. |
Cancelled | Request is cancelled. |
Value | Result is assigned by a handler. |
NoValue | No handler has produced a result. |
Error | Handler has assigned an error status. |
UnexpectedError | Unexpected exception was captured from handler. |
ValueDisposed | Value is disposed along with service or cache. |
ValueNulled | Reference to value is removed from entry. |
Disposed | Entry has been disposed. |
Entry starts at Unassigned state.
// Create entry
IEntry<string> entry = new Entry<string>();
// Print status
WriteLine(entry.Status); // "Unassigned"
.SetProcessing() marks entry into Processing state.
// Set processing
entry.SetProcessing();
// Print status
WriteLine(entry.Status); // "Processing"
.SetValue() marks entry into Value state.
// Set value
entry.SetValue("Result");
// Print status
WriteLine(entry.Status); // "Value"
.SetError() marks entry into Error state.
// Set error result
entry.SetError(new NotSupportedException());
// Print status
WriteLine(entry.Status); // "Error"
.SetUnexpectedError() marks entry into UnexpectedError state.
// Set unexpected error
entry.SetUnexpectedError(new InvalidOperationException());
// Print status
WriteLine(entry.Status); // "UnexpectedError"
.Dispose() marks entry into Disposed state.
// Set value
entry.SetValue(new Semaphore(1, 1));
// Disepose entry and value
((IDisposable)entry).Dispose();
// Print status
WriteLine(entry.Status); // "Disposed"
Flow chart of entry states.
EntryStatus enum definition.
/// <summary>Status of <see cref="IEntry"/>.</summary>
[Flags]
public enum EntryStatus : ulong
{
////// Below here are states. Only one state may apply. //////
////// However, they are listed as flags so that multiple states may be indicated. //////
/// <summary>Unassigned.</summary>
Unassigned = 0,
/// <summary>Query started.</summary>
Processing = 1UL << 10,
/// <summary>Query was cancelled.</summary>
Cancelled = 1UL << 12,
/// <summary>Request was processed, but no handler was able to produce a value.</summary>
NoValue = 1UL << 14,
/// <summary>Query resolved to a successful value.</summary>
Value = 1UL << 16,
/// <summary>Query resolved successfully but result is an error value.</summary>
Error = 1UL << 18,
/// <summary>Unexpected exception was captured.</summary>
UnexpectedError = 1UL << 20,
/// <summary>Value is disposed.</summary>
ValueDisposed = 1UL << 22,
/// <summary>Value reference is nulled or defaulted.</summary>
ValueNulled = 1UL << 23,
/// <summary>Entry container is disposed.</summary>
Disposed = 1UL << 24,
/// <summary>Any value assigned. Used with <see cref="IService.TryGetInitialized"/></summary>
AssignedStates = Cancelled | NoValue | Value | Error | UnexpectedError | ValueDisposed | ValueNulled | Disposed,
////// Below here are status flags //////
/// <summary>Query completed (or broken). This flag that indicates that resolver has applied query on every <see cref="IHandlerBase"/>.</summary>
Completed = 1UL << 30,
/// <summary>Entry is being managed by a cache.</summary>
Cached = 1UL << 31,
/// <summary>Reserved for future use for the library</summary>
Reserved2 = 1UL << 32,
/// <summary>Reserved for future use for the library</summary>
Reserved3 = 1UL << 33,
/// <summary>Reserved for future use for the library</summary>
Reserved4 = 1UL << 34,
/// <summary>Reserved for future use for the library</summary>
Reserved5 = 1UL << 35,
/// <summary>Reserved for future use for the library</summary>
Reserved6 = 1UL << 36,
/// <summary>Reserved for future use for the library</summary>
Reserved7 = 1UL << 37,
/// <summary>Reserved for future use for the library</summary>
Reserved8 = 1UL << 38,
/// <summary>Reserved for future use for the library</summary>
Reserved9 = 1UL << 39,
/// <summary>Flag allocated for any 3rd party use</summary>
User0 = 1UL << 40,
/// <summary>Flag allocated for any 3rd party use</summary>
User1 = 1UL << 41,
/// <summary>Flag allocated for any 3rd party use</summary>
User2 = 1UL << 42,
/// <summary>Flag allocated for any 3rd party use</summary>
User3 = 1UL << 43,
/// <summary>Flag allocated for any 3rd party use</summary>
User4 = 1UL << 44,
/// <summary>Flag allocated for any 3rd party use</summary>
User5 = 1UL << 45,
/// <summary>Flag allocated for any 3rd party use</summary>
User6 = 1UL << 46,
/// <summary>Flag allocated for any 3rd party use</summary>
User7 = 1UL << 47,
/// <summary>Mask for flags</summary>
Flags = Completed | Cached | Reserved2 | Reserved3 | Reserved4 | Reserved5 | Reserved6 | Reserved7 | Reserved8 | Reserved9 | User0 | User1 | User3 | User4 | User5 | User6 | User7,
}
Full Example
Full example
using System;
using System.Threading;
using Avalanche.Service;
using static System.Console;
public class entry_entrystate
{
public static void Run()
{
{
// <01>
// Create entry
IEntry<string> entry = new Entry<string>();
// Print status
WriteLine(entry.Status); // "Unassigned"
// </01>
}
{
// Create entry
IEntry<string> entry = new Entry<string>();
// <02>
// Set processing
entry.SetProcessing();
// Print status
WriteLine(entry.Status); // "Processing"
// </02>
}
{
// Create entry
IEntry<string> entry = new Entry<string>();
// <03>
// Set value
entry.SetValue("Result");
// Print status
WriteLine(entry.Status); // "Value"
// </03>
}
{
// Create entry
IEntry<string> entry = new Entry<string>();
// <04>
// Set error result
entry.SetError(new NotSupportedException());
// Print status
WriteLine(entry.Status); // "Error"
// </04>
}
{
// Create entry
IEntry<string> entry = new Entry<string>();
// <05>
// Set unexpected error
entry.SetUnexpectedError(new InvalidOperationException());
// Print status
WriteLine(entry.Status); // "UnexpectedError"
// </05>
}
{
// Create entry
IEntry<Semaphore> entry = new Entry<Semaphore>(EntryPolicy.Default);
// <06>
// Set value
entry.SetValue(new Semaphore(1, 1));
// Disepose entry and value
((IDisposable)entry).Dispose();
// Print status
WriteLine(entry.Status); // "Disposed"
// </06>
}
}
}