Class Transport
One transport, ready to compose into a ladder or a wrapper.
public sealed class Transport : 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.
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.
Properties
IsAvailable
Whether this transport is still holdable, or has been handed on.
public bool IsAvailable { get; }
Property Value
Methods
Borrow()
Lends the native handle without giving it away.
public nint Borrow()
Returns
- nint
The pointer, still owned by this transport.
Exceptions
- PamojaException
This transport was already handed on.
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.
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.
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.