Table of Contents

Class EventPublisher

Namespace
Pamoja.Bus
Assembly
Pamoja.Bus.dll

A publish-only handle to an event bus.

public sealed class EventPublisher : IDisposable
Inheritance
EventPublisher
Implements
Inherited Members

Remarks

It has no queue of its own, so a part that only announces never fills a buffer it does not read. Publishing never waits and may be called from any thread, so an event handler, such as a pin edge or a timer callback, can announce without awaiting anything.

Constructors

EventPublisher(int)

Creates a bus with no subscribers yet, and a publisher on it.

public EventPublisher(int capacity = 64)

Parameters

capacity int

How many events a slow subscriber may fall behind before it starts missing them, rounded up to the next power of two and at most 1048576.

Exceptions

ArgumentOutOfRangeException

The capacity is negative.

PamojaException

The native bus could not be created.

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Publish(ReadOnlyMemory<byte>)

Hands an event to every current subscriber.

public int Publish(ReadOnlyMemory<byte> payload)

Parameters

payload ReadOnlyMemory<byte>

The event bytes.

Returns

int

How many subscribers the event was handed to. An event published while no one is subscribed is dropped, and the count is 0.

Exceptions

PamojaException

The native call failed.

Publish(string)

Hands text to every current subscriber: an event name, or a reading written out.

public int Publish(string text)

Parameters

text string

The event text, as UTF-8.

Returns

int

How many subscribers the event was handed to. An event published while no one is subscribed is dropped, and the count is 0.

Exceptions

PamojaException

The native call failed.

Publisher()

Takes another publisher on the same bus, for another part that announces.

public EventPublisher Publisher()

Returns

EventPublisher

A publisher with a lifetime of its own.

Exceptions

PamojaException

The native call failed.

Subscribe()

Subscribes to the bus.

public EventBus Subscribe()

Returns

EventBus

An endpoint that sees events published from now on.

Exceptions

PamojaException

The native call failed.