import type { IActionContext } from '@comunica/types'; import type { Bus } from './Bus'; import type { Logger } from './Logger'; /** * An actor can act on messages of certain types and provide output of a certain type. * * The flow of an actor is as follows: * 1. Send a message to {@link Actor#test} to test if an actor can run that action. * 2. If the actor can reply to the message, let the actor run the action using {@link Actor#run}. * * An actor is typically subscribed to a bus, * using which the applicability to an action can be tested. * * @see Bus * * @template I The input type of an actor. * @template T The test type of an actor. * @template O The output type of an actor. */ export declare abstract class Actor implements IActorArgs { readonly name: string; readonly bus: Bus, I, T, O>; readonly beforeActors: Actor[]; /** * All enumerable properties from the `args` object are inherited to this actor. * * The actor will subscribe to the given bus when this constructor is called. * * @param {IActorArgs} args Arguments object * @param {string} args.name The name for this actor. * @param {Bus, I extends IAction, T extends IActorTest, O extends IActorOutput>} args.bus * The bus this actor subscribes to. * @throws When required arguments are missing. */ protected constructor(args: IActorArgs); /** * Get the logger from the given context. * @param {ActionContext} context An optional context. * @return {Logger} The logger or undefined. */ static getContextLogger(context: IActionContext): Logger | undefined; /** * Check if this actor can run the given action, * without actually running it. * * @param {I} action The action to test. * @return {Promise} A promise that resolves to the test result. */ abstract test(action: I): Promise; /** * Run the given action on this actor. * * In most cases, this method should not be called directly. * Instead, {@link #runObservable} should be called. * * @param {I} action The action to run. * @return {Promise} A promise that resolves to the run result. */ abstract run(action: I): Promise; /** * Run the given action on this actor * AND invokes the {@link Bus#onRun} method. * * @param {I} action The action to run. * @return {Promise} A promise that resolves to the run result. */ runObservable(action: I): Promise; /** * Initialize this actor. * This should be used for doing things that take a while, * such as opening files. * * @return {Promise} A promise that resolves when the actor has been initialized. */ initialize(): Promise; /** * Deinitialize this actor. * This should be used for cleaning up things when the application is shut down, * such as closing files and removing temporary files. * * @return {Promise} A promise that resolves when the actor has been deinitialized. */ deinitialize(): Promise; protected getDefaultLogData(context: IActionContext, data?: (() => any)): any; protected logTrace(context: IActionContext, message: string, data?: (() => any)): void; protected logDebug(context: IActionContext, message: string, data?: (() => any)): void; protected logInfo(context: IActionContext, message: string, data?: (() => any)): void; protected logWarn(context: IActionContext, message: string, data?: (() => any)): void; protected logError(context: IActionContext, message: string, data?: (() => any)): void; protected logFatal(context: IActionContext, message: string, data?: (() => any)): void; } export interface IActorArgs { /** * The name for this actor. * @default {} */ name: string; /** * The bus this actor subscribes to. */ bus: Bus, I, T, O>; /** * Actor that must be registered in the bus before this actor. */ beforeActors?: Actor[]; } /** * Data interface for the type of action. */ export interface IAction { /** * The input context that is passed through by actors. */ context: IActionContext; } /** * Data interface for the type of an actor test result. */ export interface IActorTest { } /** * Data interface for the type of an actor run result. */ export interface IActorOutput { }