/*! Copyright (c) 2018 Siemens AG. Licensed under the MIT License. */ import { IoActor, IoNode, IoSource } from ".."; import { IoContext } from "../model/io-context"; import { IoRouter } from "./io-router"; /** * Supports rule-based routing of data from IO sources to IO actors based on an * associated IO context. * * Define rules that determine whether a given pair if IO source and IO actor * should be associated or not. A rule is only applied if the value type of IO * source and IO actor are compatible. If no rules are defined or no rule * matches no associations between IO sources and IO actors are established. * * You can define global rules that match IO sources and actors of any * compatible value type or value-type specific rules that are only applied to * IO sources and IO actors with a given value type. * * By default, 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. * * Note that this router makes its IO context available by advertising and for * discovery (by core type, object type, or object Id) and listens for * Update-Complete events on its IO context, triggering `onIoContextChanged` * automatically. * * This router requires the following controller options: * - `ioContext`: the IO context for which this router is managing routes * (mandatory) * - `rules`: an array of rule definitions for this router. The rules listed * here override any rules defined in the `onInit` method. */ export declare class RuleBasedIoRouter extends IoRouter { private _currentAssociations; private _rules; onInit(): void; /** * Invoked when the IO context of this router has changed. * * Triggers reevaluation of all defined rules. */ onIoContextChanged(): void; /** * Define all association rules for routing. * * Note that any previously defined rules are discarded. * * Rules with undefined condition function are ignored. * * @param rules association rules for this IO router */ defineRules(...rules: IoAssociationRule[]): void; protected onStarted(): void; protected onStopped(): void; /** * The default function used to compute the recommended update rate of an * individual IO source - IO actor association. * * This function takes into account the maximum possible update rate of the * source and the desired update rate of the actor and returns a value that * satisfies both rates. * * Override this method in a subclass to implement a custom rate function. * * @param source the IoSource object * @param actor the IoActor object * @param sourceNode the IO source's node * @param sourceNode the IO actor's node */ protected computeDefaultUpdateRate(source: IoSource, actor: IoActor, sourceNode: IoNode, actorNode: IoNode): number; protected onIoNodeManaged(node: IoNode): void; protected onIoNodesUnmanaged(nodes: IoNode[]): void; private _evaluateRules; private _getCompatibleAssociations; private _match; private _resolve; private _act; private _computeCumulatedUpdateRate; } /** * Condition function type for IO routing rules. */ export declare type IoRoutingRuleConditionFunc = (source: IoSource, sourceNode: IoNode, actor: IoActor, actorNode: IoNode, context: IoContext, router: RuleBasedIoRouter) => boolean; /** * Defines a rule for associating IO sources with IO actors. */ export interface IoAssociationRule { /** * The name of the rule. Used for display purposes only. */ name: string; /** * The value type for which the rule is applicable. The rule is applied to * all IO source - IO actor pairs whose value type matches this value type. * * If the value type is undefined or an empty string, the rule acts as a * global rule. It applies to all IO source - IO actor pairs that have * compatible value types. Non-global rules have precedence over global * rules. Global rules only apply if there are no non-global rules whose * value type matches the value type of the corresponding IO source - IO * actor pair. */ valueType: string; /** * The rule condition function. * * When applied, the condition function is passed a pair of value-compatible * IO source and actor that are eligible for association. * * The condition function should return true if the passed-in association * pair should be associated; false or undefined otherwise. * * Eventually, an association pair is associated if there is at least one * applicable rule that returns true; otherwise the association pair * is not associated, i.e. it is actively disassociated if currently * associated. */ condition: IoRoutingRuleConditionFunc; }