Class Transport
One transport, ready to compose into a ladder or a wrapper.
public sealed class Transport : ILink, IDisposable
- Inheritance
-
Transport
- Implements
- Inherited Members
Remarks
A ladder rung, a fault injector, and a degraded link all take some transport, which a C ABI cannot express, so one handle carries whichever kind was built. Composing consumes it: the thing it is composed into owns it from then on, so a spent transport throws rather than aliasing a link it no longer holds. A link written in .NET enters through FromHandlers(ITransportHandlers) and is one of these from then on.
Calls on one transport run one at a time, so a send made while a receive is waiting runs once the receive returns. A task that listens should have a link of its own.
Constructors
Transport(nint, string)
Wraps a native transport handle.
public Transport(nint handle, string what)
Parameters
handlenintThe pointer a native call produced.
whatstringWhat was being created, for the exception message.
Exceptions
- PamojaException
The native call produced no transport.
Properties
IsAvailable
Whether this transport is still holdable, or has been handed on.
public bool IsAvailable { get; }
Property Value
Methods
ConnectAsync()
Connects this transport.
public Task ConnectAsync()
Returns
Exceptions
- PamojaException
The link could not be established.
Degraded(Transport, uint, uint, uint)
Wraps a transport in a link that loses packets and goes down.
public static Transport Degraded(Transport inner, uint dropEvery = 0, uint up = 0, uint down = 0)
Parameters
innerTransportThe transport to wrap, consumed by this call.
dropEveryuintLose one send in every this many, or 0 to lose none.
upuintHow many sends the link stays up for, or 0 to never go down.
downuintHow many sends it then stays down for.
Returns
- Transport
A transport owning the wrapped one.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Faulty(Transport, int)
Wraps a transport so a set number of its next sends fail.
public static Transport Faulty(Transport inner, int failures)
Parameters
innerTransportThe transport to wrap, consumed by this call.
failuresintHow many upcoming sends to fail.
Returns
- Transport
A transport owning the wrapped one.
Remarks
This is how a caller checks that a ladder falls through to its next rung, or that a buffer fills, without unplugging anything.
FromHandlers(ITransportHandlers)
Wraps a link written in .NET as a transport.
public static Transport FromHandlers(ITransportHandlers handlers)
Parameters
handlersITransportHandlersThe link.
Returns
- Transport
A transport whose every operation is one of the handlers.
Remarks
The handlers are held for the life of the transport and every transport composed from it, and released once nothing will call them again. A IReceivingTransportHandlers is listened on; plain ITransportHandlers only send, and a ladder never listens on them.
Exceptions
- PamojaException
The native transport could not be created.
LendAsync<TResult>(Func<nint, Task<TResult>>)
Lends the native handle to asynchronous work, such as a store draining into this transport, which runs once any call on the transport has returned.
public Task<TResult> LendAsync<TResult>(Func<nint, Task<TResult>> work)
Parameters
Returns
- Task<TResult>
Whatever the work produced.
Type Parameters
TResultThe value the work produces.
Exceptions
- PamojaException
This transport was already handed on.
ReceiveAsync()
Waits for the next message this transport delivers on a subscribed topic.
public Task<TransportMessage?> ReceiveAsync()
Returns
- Task<TransportMessage>
The message, or
nullonce the link has ended.
Exceptions
- PamojaException
The transport is not connected.
ReceiveAsync(TimeSpan)
Waits a limited time for the next message on a subscribed topic.
public Task<TransportMessage?> ReceiveAsync(TimeSpan timeout)
Parameters
timeoutTimeSpanHow long to wait.
Returns
- Task<TransportMessage>
The message, or
nullonce the link has ended.
Remarks
When the time runs out nothing is lost: a message arriving afterwards waits for the next receive.
Exceptions
- TimeoutException
No message arrived in time.
- PamojaException
The transport is not connected.
SendAsync(string, ReadOnlyMemory<byte>)
Sends a payload to a topic over this transport.
public Task SendAsync(string topic, ReadOnlyMemory<byte> payload)
Parameters
topicstringThe destination topic.
payloadReadOnlyMemory<byte>The bytes to send.
Returns
Exceptions
- PamojaException
The transport would not take it.
SendAsync(string, string)
Sends text to a topic over this transport: words, or a number written out.
public Task SendAsync(string topic, string text)
Parameters
Returns
Exceptions
- PamojaException
The transport would not take it.
SubscribeAsync(string)
Subscribes this transport to a topic.
public Task SubscribeAsync(string topic)
Parameters
topicstringThe topic to subscribe to.
Returns
Exceptions
- PamojaException
The subscription was refused.
Take()
Hands the native handle on, leaving this one spent.
public nint Take()
Returns
- nint
The pointer the caller now owns.
Exceptions
- PamojaException
This transport was already handed on, or a call on it is still running.