Skip to content
James Kerber edited this page May 7, 2021 · 6 revisions

Concepts

Event

An Event is a simple, unique object representing a request and containing the data necessary to satisfy such request.

Ideally, it should be subclassed in order to provide parsing, validation, and means to respond to its request, for example by a HttpRequestEvent. See @yagura/http for an example implementation

Layer

A Layer is an object containing the business logic to process Events.

Having received an Event, a Layer can do the following:

  • Consume the Event, preventing it from reaching any other Layer; an Event is consumed when:

    • It has been successfully processed; the request has been responded to and needs no further processing
    • It has been filtered out; the Layer acted as a filter function, deciding the Event is not suitable for further processing
  • Return or pass the Event to the next Layer

    • Layers can be used as middleware

The passing-through of Events through Layers is known as "event flow".

Scaffold

A Scaffold is an ordered set of Layers, collectively acting as a pipeline for Events to pass through.

Various types of Scaffolds exist:

  • SeriesScaffold: a simple sequential series of Layers, you'll encounter this one the most often
  • ParallelScaffold: it accepts one Event, and has n layers process it simultaneously, outputting up to n processed versions of the initial Event
    • (coming soon) a ParallelScaffold also accepts an optional reducer layer, assuring that it outputs only one Event

Advanced scaffolding

Scaffold is actually a subclass of Layer, meaning that Scaffolds can be nested, for example a SeriesScaffold can contain a ParallelScaffold, multiple of them, or vice-versa.

Here's a few examples where this can be useful.

TBD

Service

A Service is a utility class exposing additional functionality to Layers without affecting Event flow.

One Service built into Yagura is 'Logger', implemented by DefaultLogger.

Other examples of a classic Service could be a DatabaseConnection, with methods such as getById() or createEntry(), or
Services can also emit events to Yagura. A practical example could be a HttpServer service or MQEmitter.

However, the most interesting part of Service implementation is dynamic service management. Read more on the Service feature page

Clone this wiki locally