Table of Contents

Class Transport

Namespace
Pamoja.Core
Assembly
Pamoja.Core.dll

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

handle nint

The pointer a native call produced.

what string

What 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

bool

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

Task

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

inner Transport

The transport to wrap, consumed by this call.

dropEvery uint

Lose one send in every this many, or 0 to lose none.

up uint

How many sends the link stays up for, or 0 to never go down.

down uint

How 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

inner Transport

The transport to wrap, consumed by this call.

failures int

How 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

topic string

The destination topic.

payload ReadOnlyMemory<byte>

The bytes to send.

Returns

Task

Exceptions

PamojaException

The transport would not take it.

SubscribeAsync(string)

Subscribes this transport to a topic.

public Task SubscribeAsync(string topic)

Parameters

topic string

The topic to subscribe to.

Returns

Task

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.