Even more documentation
This commit is contained in:
@@ -27,15 +27,46 @@ type InterfaceConnectionEntry<ConfigInterface> = {
|
||||
config: ConfigInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* The core of the library.
|
||||
* @remarks
|
||||
* Here are all Interface Servers and Connectors are created and managed.
|
||||
* Also every request is handled here.
|
||||
*/
|
||||
export default class MultiMessageBroker {
|
||||
private static instance: MultiMessageBroker|null = null;
|
||||
|
||||
/**
|
||||
* Whether the broker is prepared.
|
||||
*/
|
||||
private prepared: boolean = false;
|
||||
|
||||
/**
|
||||
* All registered AASs.
|
||||
*/
|
||||
private aasRegistrations: AASRegistrationPrepared[] = [];
|
||||
/**
|
||||
* All registered Interface Connectors.
|
||||
*/
|
||||
private interfaceConnections: InterfaceConnectionEntry<any>[] = [];
|
||||
|
||||
public constructor() {}
|
||||
private constructor() {}
|
||||
|
||||
public registerAAS<T>(registration: AASRegistration): void {
|
||||
/**
|
||||
* Get the singleton instance of the broker.
|
||||
*/
|
||||
public static getInstance(): MultiMessageBroker {
|
||||
if (this.instance === null) this.instance = new MultiMessageBroker();
|
||||
return this.instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an AAS.
|
||||
* @remarks
|
||||
* This will also create the {@link AIMCMapper} for the AAS
|
||||
* @param registration AAS registration
|
||||
*/
|
||||
public registerAAS(registration: AASRegistration): void {
|
||||
this.aasRegistrations.push({
|
||||
...registration,
|
||||
serverInstances: [],
|
||||
@@ -44,10 +75,20 @@ export default class MultiMessageBroker {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an Interface Connector.
|
||||
* @param interfaceConnectionEntry Interface connector registration
|
||||
* @typeParam T - The config interface for your interface connector.
|
||||
*/
|
||||
public registerInterfaceConnection<T>(interfaceConnectionEntry: InterfaceConnectionEntry<T>): void {
|
||||
this.interfaceConnections.push(interfaceConnectionEntry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the broker.
|
||||
* @remarks
|
||||
* This will create instances of the {@link AASInterfaceServer} and {@link InterfaceConnectionObject} classes.
|
||||
*/
|
||||
public prepare(): void {
|
||||
for (const registration of this.aasRegistrations) {
|
||||
|
||||
@@ -92,6 +133,9 @@ export default class MultiMessageBroker {
|
||||
this.prepared = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the broker.
|
||||
*/
|
||||
public start(): void {
|
||||
if (!this.prepared) this.prepare();
|
||||
|
||||
@@ -101,6 +145,12 @@ export default class MultiMessageBroker {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback on an server request
|
||||
* @param request Request
|
||||
* @param registration AAS Registration
|
||||
* @returns Value or success state or nothing based on the request type
|
||||
*/
|
||||
private onInterfaceRequest(request: Request, registration: AASRegistrationPrepared): any {
|
||||
|
||||
const getConnector = (target: types.Class) => {
|
||||
@@ -162,6 +212,10 @@ export default class MultiMessageBroker {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback on a connector event.
|
||||
* @param response
|
||||
*/
|
||||
private onConnectorEvent(response: any) {
|
||||
for (const aas of this.aasRegistrations) {
|
||||
for (const server of aas.serverInstances ?? []) {
|
||||
|
||||
Reference in New Issue
Block a user