Interface INopeInstanceManager

A Manager, which is capable of creating instance on different Managers in the Network.

It is defaultly implemented by NopeInstanceManager

The instanceManager is used to create, remove and get access to instances. the approach is based on the object oriented method. I.e. there are the following elements:

  • Classes:
  • These describe a blueprint of a behavior.
  • Are identified in NoPE by an ID / a type.
  • Classes have constructors that create an instance:
    • Offered in NoPE as a service (service name includes the identifier, among other things).
  • Instances:
    • Are instances of a class (corresponds to so-called objects).
    • Are identified in NoPE by identifier (here strings)
    • have the properties, methods and eventEmitters created in the classes.
    • Can be "destroyed" via so-called destroyers. Thus they are deleted.

The manager keeps track of the available instances in the network and allows to create wrappers for these instances. This allows to simplify and unify the access for the user of instances running in a different runtime. To make this possible it uses the following elements:

  • connectivityManager: see above. Used to identify new and dead dispatchers.
    • if a new dispatcher is identified, standardized descriptions of all hosted instances are sent.
    • if a dispatcher is identified as dead, the wrappers are deleted or removed.
  • rpcManager: see above. Used here to distribute constructorsof classes anddestructors` of instances on the network. I.e.:
    • The creation of a new instance corresponds to a service call.
    • Deleting an instance corresponds to a service call
    • The constructors of the classes and destructors of the instances follow a defined naming convention, so that they can be identified by the instanceManager. The InstanceManger can be interacted with using the following methods and properties:
  • getInstancesOfType: returns all available instances of a given type.
  • instanceExists: tests if an instance with the given identifier exists.
  • getInstanceDescription: Returns the standardized description of an instance. This information is also shared with all instanceManagers on the network.
  • registerInstance: Allows to manually register an instance.
  • deleteInstance: Allows the manual removal of an instance.
  • registerConstructor: Registers a constructor. Among other things, it is possible to specify the number of instances that may be created on the instanceManager. If more than one dispatcher is able to create an instance with the given type, then - as with rpcManger - the selection follows via a so-called selector.
  • unregisterConstructor: Removes a constructor.
  • constructorExists: Tests if a constructor is known for a type.
  • createInstance: Allows the creation of an instance. This may be the case for remote dispatchers or for the same element. Only a wrapper communicating with a dispatcher is returned, since we do not know where the element is provided. To know which instanceManager hosts the instance can use the getDispatcherForInstance method. The returned wrapper behaves like a normal "internal" class. If this method is called, a GenericModule is returned as type by default. If a special wrapper is required for a type, such wrappers can be defined and customized via registerInternalWrapperGenerator and unregisterInternalWrapperGenerator. Here, too, the type is decisive.

Example

// Describe the required Test:
let manager = new NopeInstanceManager(
{
communicator: getLayer("event", "", false),
logger: false,
},
() => new NopeEventEmitter(),
() => new NopeObservable(),
async () => "test",
"test",
undefined,
undefined,
manager as any
);

// Crate a sample Class we want to be able to create:
class TestModule extends NopeBaseModule {

public async dispose(): Promise<void> {
await super.dispose();
called = true;
}

public async init(p1: string, p2: string): Promise<void> {
this.author = {
forename: "test",
surename: "test",
mail: "test",
};
this.version = {
date: new Date(),
version: 1,
};
this.description = "Sample Class";
await super.init();
}

}

await manager.ready.waitFor();

// Now we register the constructor with the type 'TestModule'
await manager.registerConstructor(
"TestModule",
async (core, identifier) => {
assert(
identifier === "instance",
"The identifier has not been transmitted"
);
return new TestModule(core);
}
);

// Check the Constructors
const constructors = manager.constructors.extractedKey;
expect(constructors).to.include("TestModule");
expect(manager.constructors.amountOf.get("TestModule")).to.be(1);
expect(manager.constructorExists("TestModule")).to.be.true;

// Create an Instance:
const instance = await manager.createInstance<TestModule>({
identifier: "instance",
type: "TestModule",
params: ["p1", "p2"],
});

Author

M.Karkowski

Export

INopeInstanceManager

Hierarchy

  • INopeInstanceManager

Implemented by

Properties

constructorServices: INopeObservable<string[], string[], string[], IEventAdditionalData>

Contains the rpcs used to create instances.

constructors: IMapBasedMergeData<string, string[], string, string>

Overview of the available Constructors in the network.

Author

M.Karkowski

Memberof

INopeInstanceManager

Overview of the available instances in the network.

  • OriginalKey = DispatcherID (string);
  • OriginalValue = Available Instance Messages (IAvailableInstancesMsg);
  • ExtractedKey = The name of the Instance (string);
  • ExtractedValue = instance-description (INopeModuleDescription);

Author

M.Karkowski

Memberof

INopeInstanceManager

internalInstances: INopeObservable<string[], string[], string[], IEventAdditionalData>

Contains the identifiers of the instances, which are hosted in the provided dispatcher.

Author

M.Karkowski

Memberof

INopeInstanceManager

ready: INopeObservable<boolean, boolean, boolean, IEventAdditionalData>

Flag to indicate, that the system is ready.

Author

M.Karkowski

Memberof

INopeInstanceManager

Methods

  • Helper to test if a constructor linkt to the provided "typeIdentifier" exists or not.

    Author

    M.Karkowski

    Returns

    Result

    Memberof

    INopeInstanceManager

    Parameters

    • typeIdentifier: string

      The identifier for the Constructor (Like a service)

    Returns boolean

  • Allows to create an instance. This might be the case on remote dispatchers or on the same element. Only a wrapper is returned, which communicates with a dispatcher, because we dont know where the element is provided. To know which instanceManager hosts the instance can use the INopeInstanceManager.getDispatcherForInstance method. The returned wrapper behaves like a normal "internal" class. If this method is called, a {@link IGenericNopeModule} is returned as type by default. If a special wrapper is required for a type, such wrappers can be defined and customized via registerInternalWrapperGenerator and unregisterInternalWrapperGenerator. Here, too, the type is decisive. *

    If there are multiple INopeInstanceManager able to create an instance, the selector is used to select a dispatcherand its instanceManger, to create the instance.

    If the instances already exists and the type is matching, the assignmentValid callback is used, to test if the required assignmet could be valid. E.g. you require the instance to be hosted on a specific host. The assignmentValid will check if the assignment is valid.

    Example

    // Create an Instance:
    const instance = await manager.createInstance<TestModule>({
    identifier: "instance", // <- Must be provided
    type: "TestModule", // <- Must be provided and present in the Network
    params: ["p1", "p2"], // <- Optional. The Parameters, required by the class to initialize see {@link INopeModule.init}
    });

    Author

    M.Karkowski

    Returns

    Memberof

    INopeInstanceManager

    Type Parameters

    Parameters

    • description: Partial<IInstanceCreationMsg>

      Description requrired to create the Message (see IInstanceCreationMsg). The properties type and identifier must be provided.

    • Optional options: {
          assignmentValid?: TValidAsssignmentChecker;
          linkEvents?: boolean;
          linkProperties?: boolean;
          selector?: ValidSelectorFunction;
      }

      Additional Options used during creating the Instance

      • Optional assignmentValid?: TValidAsssignmentChecker

        If the instances already exists and the type is matching, the assignmentValid callback is used, to test if the required assignmet could be valid. E.g. you require the instance to be hosted on a specific host. The assignmentValid will check if the assignment is valid.

      • Optional linkEvents?: boolean

        Flag to link the events. Defaults to true. Should not be touched. can be used, if e.g. only methods of an instance are relevant.

      • Optional linkProperties?: boolean

        Flag to link the properties. Defaults to true. Should not be touched. can be used, if e.g. only methods of an instance are relevant.

      • Optional selector?: ValidSelectorFunction

        If there are multiple INopeInstanceManager able to create an instance, the selector is used to select a dispatcherand its instanceManger, to create the instance.

    Returns Promise<I & IGenericNopeModule>

  • Disposes an instance and removes it. Thereby the Instance wont be available for other InstanceManagers in the system.

    Author

    M.Karkowski

    Returns

    Memberof

    INopeInstanceManager

    Type Parameters

    Parameters

    • instance: string | I

      The Instance to consider

    Returns Promise<boolean>

  • Helper, to test if an instance with the given identifier exists or not.

    Author

    M.Karkowski

    Returns

    Result

    Memberof

    INopeInstanceManager

    Parameters

    • instanceIdentifier: string

      identifier of the instance.

    Returns boolean

  • Registers a Constructor, that enables other NopeInstanceManagers to create an instance of the given type. Therefore a callback "cb" is registered with the given "typeIdentifier".

    The function allways need as callback which must return a INopeModule (or an extension of it)

    Example:

    Example

    // Now we register the constructor with the type 'TestModule'
    await manager.registerConstructor(
    "TestModule",
    async (core, identifier) => {
    assert(
    identifier === "instance",
    "The identifier has not been transmitted"
    );
    return new TestModule(core);
    }
    );

    Author

    M.Karkowski

    Returns

    Memberof

    INopeInstanceManager

    Type Parameters

    Parameters

    • typeIdentifier: string

      The identifier for the Constructor (Like a service)

    • cb: TConstructorCallback<I>

      The callback used, to create an instance.

    Returns Promise<void>

  • Option, to statically register an instance, without using an specific generator etc. This instance is just present in the network.

    Author

    M.Karkowski

    Returns

    Memberof

    INopeInstanceManager

    Type Parameters

    Parameters

    • instance: I

      The Instance to consider

    Returns Promise<I>

  • Defaultly a generic wrapper will be returned, when an instance is created. you can specifiy specific wrapper type for different "typeIdentifier" with this method.

    Author

    M.Karkowski

    Memberof

    INopeInstanceManager

    Parameters

    Returns void

  • Description of an Instance-Manager

    Returns {
        constructors: {
            all: string[];
            internal: string[];
        };
        instances: {
            all: INopeModuleDescription[];
            internal: string[];
        };
    }

    • constructors: {
          all: string[];
          internal: string[];
      }
      • all: string[]
      • internal: string[]
    • instances: {
          all: INopeModuleDescription[];
          internal: string[];
      }
  • Unregisters a present Constructor. After this, created instances are still valid, the user isnt able to create new ones.

    Author

    M.Karkowski

    Returns

    Memberof

    INopeInstanceManager

    Parameters

    • typeIdentifier: string

      The identifier for the Constructor (Like a service)

    Returns Promise<void>

  • Removes a specific generator for for a wrapper.

    Author

    M.Karkowski

    Memberof

    INopeInstanceManager

    Parameters

    • typeIdentifier: string

      The identifier for the Constructor (Like a service)

    Returns void

Generated using TypeDoc