Options
All
  • Public
  • Public/Protected
  • All
Menu

Base IO router class for context-driven routing of IO values.

This router implements the base logic of routing. It observes IO nodes that are associated with the router's IO context and manages routes for the IO sources and actors of these nodes.

This router implements a basic routing algorithm where all compatible pairs of IO sources and IO actors are associated. An IO source and an IO actor are compatible if both define equal value types in equal data formats. You can define your own custom compatibility check on value types in a subclass by overriding the areValueTypesCompatible method.

To implement context-specific routing strategies extend this class and implement the abstract protected methods.

Note that this router makes its IO context available for discovery (by core type, object type, or object Id) and listens for Update-Complete events on its IO context, triggering onIoContextChanged automatically.

This base router class requires the following controller options:

  • ioContext: the IO context for which this router is managing routes (mandatory)

Hierarchy

Index

Constructors

constructor

Accessors

communicationManager

container

ioContext

managedIoNodes

  • get managedIoNodes(): Readonly<Map<string, IoNode>>

options

registeredName

  • get registeredName(): string
  • Gets the registered name of this controller.

    The registered name is either defined by the corresponding key in the Components.controllers object in the container configuration, or by invoking Container.registerController method with this name.

    Returns string

runtime

Methods

Protected areValueTypesCompatible

  • Checks whether the value types and value data formats of the given IO source and actor match.

    This is a precondition for associating IO source and actor.

    The base implementation returns true, if the given source value type is identical to the given actor value type and both value data formats (either raw binary or JSON) match; otherwise false.

    Override this base implementation if you need a custom value type compatibility check in your router.

    Parameters

    Returns boolean

Protected associate

  • Associates the given IO source and actor by publishing an Associate event.

    Parameters

    • source: IoSource

      an IO source object

    • actor: IoActor

      an IO actor object

    • updateRate: number

      the recommended update rate (in milliseconds)

    Returns void

Protected disassociate

  • Disassociates the given IO source and actor by publishing an Associate event with an undefined route.

    Parameters

    Returns void

Protected extendLogObject

  • extendLogObject(log: Log): void
  • Whenever one of the controller's log methods (e.g. logDebug, logInfo, logWarning, logError, logFatal) is called by application code, the controller creates a Log object with appropriate property values and passes it to this method before advertising it.

    You can override this method to additionally set certain properties (such as LogHost.hostname or Log.logLabels). Ensure that super.extendLogObject is called in your override. The base method does nothing.

    Parameters

    • log: Log

      log object to be extended before being advertised

    Returns void

findManagedIoNode

  • findManagedIoNode(predicate: (node: IoNode) => boolean): IoNode
  • Finds a managed IO node that matches the given predicate.

    Returns undefined if no such IO node exists.

    Parameters

    • predicate: (node: IoNode) => boolean

      a function returning true if an IO node matches; false otherwise.

        • Parameters

          Returns boolean

    Returns IoNode

logDebug

  • logDebug(message: string, ...tags: string[]): void

logError

  • logError(error: any, message: string, ...tags: string[]): void
  • Advertise a Log object for an error.

    Parameters

    • error: any

      an error (object)

    • message: string

      additional error message

    • Rest ...tags: string[]

      any number of log tags

    Returns void

logErrorWithStacktrace

  • logErrorWithStacktrace(error: any, message: string, ...tags: string[]): void

logFatal

  • logFatal(error: any, message: string, ...tags: string[]): void
  • Advertise a Log object for a fatal error.

    Parameters

    • error: any

      an error (object)

    • message: string

      additional error message

    • Rest ...tags: string[]

      any number of log tags

    Returns void

logInfo

  • logInfo(message: string, ...tags: string[]): void

logWarning

  • logWarning(message: string, ...tags: string[]): void

onCommunicationManagerStarting

  • onCommunicationManagerStarting(): void

onCommunicationManagerStopping

  • onCommunicationManagerStopping(): void

onDispose

  • onDispose(): void
  • Called by the container when this instance should be disposed.

    Implement cleanup side effects here. Ensure that super.onDispose is called in your override. The base implementation does nothing.

    Returns void

onInit

  • onInit(): void
  • Called when the container has completely set up and injected all dependency components, including all its controllers.

    Override this method to perform initializations in your custom controller class instead of defining a constructor. Although the base implementation does nothing it is good practice to call super.onInit() in your override method; especially if your custom controller class does not extend from the base Controller class directly.

    Returns void

Protected onIoContextChanged

  • onIoContextChanged(): void
  • Called by this IO router when its IO context has changed.

    The base method just advertises the changed IO context object.

    Overwrite this method in your router subclass to reevaluate all associations between IO sources and IO actors currently held by this router.

    Ensure to invoke super.onIoContextChanged so that the changed IO context is (re)advertised.

    Returns void

Protected Abstract onIoNodeManaged

  • onIoNodeManaged(node: IoNode): any
  • Called by the IO router base implementation when an IO node is being managed.

    To be implemented by concrete subclasses.

    Parameters

    Returns any

Protected Abstract onIoNodesUnmanaged

  • onIoNodesUnmanaged(nodes: IoNode[]): any
  • Called by the IO router base implementation when currently managed IO nodes are going to be unmanaged.

    To be implemented by concrete subclasses.

    Parameters

    Returns any

Protected onStarted

  • onStarted(): void
  • Override this method to perform side effects when this router is started.

    This method does nothing.

    Returns void

Protected onStopped

  • onStopped(): void
  • Override this method to perform side effects when this router is stopped.

    This method does nothing.

    Subclasses should disassociate all current associations in this method.

    Returns void

Generated using TypeDoc