reformating code
This commit is contained in:
parent
1c1014c81b
commit
9e305ebef0
@ -2,7 +2,7 @@
|
||||
* @author Martin Karkowski
|
||||
* @email m.karkowski@zema.de
|
||||
* @create date 2020-11-06 08:52:36
|
||||
* @modify date 2020-12-04 17:44:34
|
||||
* @modify date 2021-01-12 08:54:17
|
||||
* @desc [description]
|
||||
*/
|
||||
|
||||
@ -30,21 +30,23 @@ const METHODS: Array<keyof ICommunicationInterface> = [
|
||||
"onNewObservablesAvailable",
|
||||
"onNewServicesAvailable",
|
||||
"onStatusUpdate",
|
||||
"onTaskCancelation",
|
||||
"onTaskCancelation"
|
||||
];
|
||||
|
||||
const METHOD_MAPPING: {[P in keyof ICommunicationInterface]: keyof ICommunicationInterface} = {
|
||||
"onAurevoir": "emitAurevoir",
|
||||
"onBonjour": "emitBonjour",
|
||||
"onEvent":"emitEvent",
|
||||
"onNewInstanceGeneratorsAvailable": "emitNewInstanceGeneratorsAvailable",
|
||||
"onNewInstancesAvailable": "emitNewInstancesAvailable",
|
||||
"onNewObservablesAvailable": "emitNewObersvablesAvailable",
|
||||
"onNewServicesAvailable":"emitNewServicesAvailable",
|
||||
"onRpcRequest":"emitRpcRequest",
|
||||
"onRpcResponse": "emitRpcResponse",
|
||||
"onTaskCancelation": "emitTaskCancelation",
|
||||
"onStatusUpdate":"emitStatusUpdate"
|
||||
const METHOD_MAPPING: {
|
||||
[P in keyof ICommunicationInterface]: keyof ICommunicationInterface;
|
||||
} = {
|
||||
onAurevoir: "emitAurevoir",
|
||||
onBonjour: "emitBonjour",
|
||||
onEvent: "emitEvent",
|
||||
onNewInstanceGeneratorsAvailable: "emitNewInstanceGeneratorsAvailable",
|
||||
onNewInstancesAvailable: "emitNewInstancesAvailable",
|
||||
onNewObservablesAvailable: "emitNewObersvablesAvailable",
|
||||
onNewServicesAvailable: "emitNewServicesAvailable",
|
||||
onRpcRequest: "emitRpcRequest",
|
||||
onRpcResponse: "emitRpcResponse",
|
||||
onTaskCancelation: "emitTaskCancelation",
|
||||
onStatusUpdate: "emitStatusUpdate"
|
||||
};
|
||||
|
||||
const STORING: Array<keyof ICommunicationInterface> = [
|
||||
@ -91,19 +93,22 @@ export class Bridge implements ICommunicationInterface {
|
||||
this._layers.set(layer, forward);
|
||||
|
||||
if (this._enableDynamicAdding) {
|
||||
|
||||
const _this = this;
|
||||
|
||||
// Play the history:
|
||||
for (const method of STORING) {
|
||||
for (const cb of this[`_map_${method}`]) {
|
||||
layer[method as any](forward ? this._wrapMethodWithoutName(cb,layer,method) : cb);
|
||||
layer[method as any](
|
||||
forward ? this._wrapMethodWithoutName(cb, layer, method) : cb
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Create a dictionary, which maps the container
|
||||
// to the corresponding Method.
|
||||
const dict: {[index:string]: "onRpcResponse" | "onRpcRequest" | "onEvent"} = {
|
||||
const dict: {
|
||||
[index: string]: "onRpcResponse" | "onRpcRequest" | "onEvent";
|
||||
} = {
|
||||
_onRpcResponse: "onRpcResponse",
|
||||
_onRpcRequest: "onRpcRequest",
|
||||
_onEvent: "onEvent"
|
||||
@ -118,7 +123,12 @@ export class Bridge implements ICommunicationInterface {
|
||||
// 2. Iterate over the Elements.
|
||||
for (const [event, callbacks] of map.entries()) {
|
||||
// 3. Add all callbacks (Use the Map operator.)
|
||||
Array.from(callbacks).map(cb => layer[method](event,forward ? _this._wrapMethod(event,cb,layer,method) : cb));
|
||||
Array.from(callbacks).map((cb) =>
|
||||
layer[method](
|
||||
event,
|
||||
forward ? _this._wrapMethod(event, cb, layer, method) : cb
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -156,8 +166,7 @@ export class Bridge implements ICommunicationInterface {
|
||||
// is connected.
|
||||
this.connected.getter = () => {
|
||||
for (const layer of _this._layers.keys()) {
|
||||
if (!layer.connected.getContent())
|
||||
return false;
|
||||
if (!layer.connected.getContent()) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -168,10 +177,7 @@ export class Bridge implements ICommunicationInterface {
|
||||
for (const method of METHODS) {
|
||||
// If the Subscription should be stored and dynamic Adding is enabled =>
|
||||
// Add the methods.
|
||||
if (
|
||||
_enableDynamicAdding &&
|
||||
STORING.includes(method)
|
||||
) {
|
||||
if (_enableDynamicAdding && STORING.includes(method)) {
|
||||
this[`_map_${method}`] = new Array<any[]>();
|
||||
// Define a Function which stores the Actions:
|
||||
this[method as any] = async (cb) => {
|
||||
@ -179,14 +185,17 @@ export class Bridge implements ICommunicationInterface {
|
||||
_this[`_map_${method}`].push(cb);
|
||||
|
||||
for (const [_layer, _forward] of _this._layers) {
|
||||
_layer[method as any](_forward? _this._wrapMethodWithoutName(cb,_layer,method): cb);
|
||||
_layer[method as any](
|
||||
_forward ? _this._wrapMethodWithoutName(cb, _layer, method) : cb
|
||||
);
|
||||
}
|
||||
};
|
||||
} else if
|
||||
} else if (
|
||||
// Else if the method store the events individually =>
|
||||
// Creaete a different Method:
|
||||
(_enableDynamicAdding &&
|
||||
SPECIFIC_STORING.includes(method)) {
|
||||
_enableDynamicAdding &&
|
||||
SPECIFIC_STORING.includes(method)
|
||||
) {
|
||||
// Determine the Container name.
|
||||
const _container = `_${method}`;
|
||||
// Define the Container itself
|
||||
@ -201,14 +210,18 @@ export class Bridge implements ICommunicationInterface {
|
||||
for (const [_layer, _forward] of _this._layers) {
|
||||
// Store the Callback. Because it is a "method" which listens on the
|
||||
// events => wrap the method, to forward the event to the other layers.
|
||||
_layer[method as any](name, _forward ? _this._wrapMethod(name, cb, _layer, method) : cb);
|
||||
_layer[method as any](
|
||||
name,
|
||||
_forward ? _this._wrapMethod(name, cb, _layer, method) : cb
|
||||
);
|
||||
}
|
||||
};
|
||||
}else if
|
||||
} else if (
|
||||
// Else if the method store the events individually =>
|
||||
// Creaete a different Method:
|
||||
(_enableDynamicAdding &&
|
||||
SPECIFIC_REMOVING.includes(method)) {
|
||||
_enableDynamicAdding &&
|
||||
SPECIFIC_REMOVING.includes(method)
|
||||
) {
|
||||
// Determine the Container name.
|
||||
const _container = method.replace("off", "_on");
|
||||
// Define the Container itself
|
||||
@ -243,7 +256,12 @@ export class Bridge implements ICommunicationInterface {
|
||||
}
|
||||
|
||||
protected _wrappedMethods = new Map<(data) => any, (data) => any>();
|
||||
protected _wrapMethod(name: string, cb: (data) => any, layer: ICommunicationInterface, method: keyof ICommunicationInterface): (data) => any{
|
||||
protected _wrapMethod(
|
||||
name: string,
|
||||
cb: (data) => any,
|
||||
layer: ICommunicationInterface,
|
||||
method: keyof ICommunicationInterface
|
||||
): (data) => any {
|
||||
const _this = this;
|
||||
const _wrapped = (data) => {
|
||||
// _this._logger.info("Forwarding",method,name);
|
||||
@ -260,7 +278,11 @@ export class Bridge implements ICommunicationInterface {
|
||||
this._wrappedMethods.set(cb, _wrapped);
|
||||
return _wrapped;
|
||||
}
|
||||
protected _wrapMethodWithoutName(cb: (data) => any, layer: ICommunicationInterface, method: keyof ICommunicationInterface): (data) => any{
|
||||
protected _wrapMethodWithoutName(
|
||||
cb: (data) => any,
|
||||
layer: ICommunicationInterface,
|
||||
method: keyof ICommunicationInterface
|
||||
): (data) => any {
|
||||
const _this = this;
|
||||
return (data) => {
|
||||
// _this._logger.info("Forwarding",method);
|
||||
@ -282,10 +304,14 @@ export class Bridge implements ICommunicationInterface {
|
||||
* @param event the name of the event
|
||||
* @param cb the callback
|
||||
*/
|
||||
protected _adaptStore(name: "_onRpcResponse" | "_onRpcRequest" | "_onEvent", mode: "add" | "delete", event: string, cb: any): void {
|
||||
protected _adaptStore(
|
||||
name: "_onRpcResponse" | "_onRpcRequest" | "_onEvent",
|
||||
mode: "add" | "delete",
|
||||
event: string,
|
||||
cb: any
|
||||
): void {
|
||||
if (this._enableDynamicAdding) {
|
||||
const _set01 =
|
||||
this[name].get(event) || new Set();
|
||||
const _set01 = this[name].get(event) || new Set();
|
||||
_set01[mode](cb);
|
||||
this[name].set(event, _set01);
|
||||
}
|
||||
|
@ -59,23 +59,28 @@ class HostStatusComponent extends React.Component<
|
||||
os: string;
|
||||
ram: number;
|
||||
name: string;
|
||||
pids: { pid: number; dispatchers: {id: string, status: ENopeDispatcherStatus, timestamp: number}[] }[];
|
||||
status: ENopeDispatcherStatus,
|
||||
timestamp: number
|
||||
pids: {
|
||||
pid: number;
|
||||
dispatchers: {
|
||||
id: string;
|
||||
status: ENopeDispatcherStatus;
|
||||
timestamp: number;
|
||||
}[];
|
||||
}[];
|
||||
status: ENopeDispatcherStatus;
|
||||
timestamp: number;
|
||||
};
|
||||
},
|
||||
{
|
||||
lastUpdate: string,
|
||||
variant: "success" | "warning" | "danger",
|
||||
badge: boolean,
|
||||
badgeText: string
|
||||
lastUpdate: string;
|
||||
variant: "success" | "warning" | "danger";
|
||||
badge: boolean;
|
||||
badgeText: string;
|
||||
}
|
||||
> {
|
||||
|
||||
protected _intervall: any = null;
|
||||
|
||||
get _state() {
|
||||
|
||||
const dict = {
|
||||
0: "success",
|
||||
1: "info",
|
||||
@ -84,7 +89,7 @@ class HostStatusComponent extends React.Component<
|
||||
};
|
||||
|
||||
return {
|
||||
lastUpdate: (new Date(this.props.status.timestamp)).toISOString(),
|
||||
lastUpdate: new Date(this.props.status.timestamp).toISOString(),
|
||||
variant: dict[this.props.status.status],
|
||||
badge: this.props.status.status !== ENopeDispatcherStatus.HEALTHY,
|
||||
badgeText: ENopeDispatcherStatus[this.props.status.status]
|
||||
@ -113,10 +118,23 @@ class HostStatusComponent extends React.Component<
|
||||
return (
|
||||
<Card border={this.state.variant}>
|
||||
<Card.Body>
|
||||
<Card.Title> {this.state.badge ? <>{this.props.status.name} <Badge variant={this.state.variant}>ELEMENT {this.state.badgeText} !</Badge> </> : <>{this.props.status.name}</> } </Card.Title>
|
||||
<Card.Title>
|
||||
{" "}
|
||||
{this.state.badge ? (
|
||||
<>
|
||||
{this.props.status.name}{" "}
|
||||
<Badge variant={this.state.variant}>
|
||||
ELEMENT {this.state.badgeText} !
|
||||
</Badge>{" "}
|
||||
</>
|
||||
) : (
|
||||
<>{this.props.status.name}</>
|
||||
)}{" "}
|
||||
</Card.Title>
|
||||
<Table bordered>
|
||||
<tbody>
|
||||
{ this.props.status.ram > 0 ? (<tr>
|
||||
{this.props.status.ram > 0 ? (
|
||||
<tr>
|
||||
<td>RAM</td>
|
||||
<td>
|
||||
{" "}
|
||||
@ -125,7 +143,10 @@ class HostStatusComponent extends React.Component<
|
||||
value={this.props.status.ram}
|
||||
></MemoryStatusComponent>
|
||||
</td>
|
||||
</tr>) : <></>}
|
||||
</tr>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
<tr>
|
||||
<td>CPU</td>
|
||||
<td>{this.props.status.cpu}</td>
|
||||
@ -146,7 +167,9 @@ class HostStatusComponent extends React.Component<
|
||||
</Table>
|
||||
</Card.Body>
|
||||
<Card.Footer>
|
||||
<small className="text-muted">Last updated <b>{this.state.lastUpdate}</b></small>
|
||||
<small className="text-muted">
|
||||
Last updated <b>{this.state.lastUpdate}</b>
|
||||
</small>
|
||||
</Card.Footer>
|
||||
</Card>
|
||||
);
|
||||
@ -155,14 +178,24 @@ class HostStatusComponent extends React.Component<
|
||||
|
||||
class AvailableDispatchers extends React.Component<
|
||||
{ dispatcher: INopeDispatcher },
|
||||
{ dispatchers: {
|
||||
{
|
||||
dispatchers: {
|
||||
cpu: string;
|
||||
cores: number;
|
||||
os: string;
|
||||
ram: number;
|
||||
name: string;
|
||||
pids: { pid: number; dispatchers: {id: string, status: ENopeDispatcherStatus, timestamp: number}[] }[];
|
||||
}[][]; connected: boolean }
|
||||
pids: {
|
||||
pid: number;
|
||||
dispatchers: {
|
||||
id: string;
|
||||
status: ENopeDispatcherStatus;
|
||||
timestamp: number;
|
||||
}[];
|
||||
}[];
|
||||
}[][];
|
||||
connected: boolean;
|
||||
}
|
||||
> {
|
||||
private _observer: INopeObserver[] = [];
|
||||
|
||||
@ -174,9 +207,15 @@ class AvailableDispatchers extends React.Component<
|
||||
os: string;
|
||||
ram: number;
|
||||
name: string;
|
||||
pids: { [index: string]: {id: string, status: ENopeDispatcherStatus, timestamp: number}[] };
|
||||
status: ENopeDispatcherStatus,
|
||||
timestamp: number
|
||||
pids: {
|
||||
[index: string]: {
|
||||
id: string;
|
||||
status: ENopeDispatcherStatus;
|
||||
timestamp: number;
|
||||
}[];
|
||||
};
|
||||
status: ENopeDispatcherStatus;
|
||||
timestamp: number;
|
||||
};
|
||||
} = {};
|
||||
const ret: {
|
||||
@ -185,9 +224,16 @@ class AvailableDispatchers extends React.Component<
|
||||
os: string;
|
||||
ram: number;
|
||||
name: string;
|
||||
pids: { pid: number; dispatchers: {id: string, status: ENopeDispatcherStatus, timestamp: number}[] }[];
|
||||
status: ENopeDispatcherStatus,
|
||||
timestamp: number
|
||||
pids: {
|
||||
pid: number;
|
||||
dispatchers: {
|
||||
id: string;
|
||||
status: ENopeDispatcherStatus;
|
||||
timestamp: number;
|
||||
}[];
|
||||
}[];
|
||||
status: ENopeDispatcherStatus;
|
||||
timestamp: number;
|
||||
}[] = [];
|
||||
|
||||
for (const dispatcher of this.props.dispatcher.externalDispatchers.getContent()) {
|
||||
@ -207,8 +253,14 @@ class AvailableDispatchers extends React.Component<
|
||||
sorted[dispatcher.host.name].pids[dispatcher.pid] = [];
|
||||
}
|
||||
|
||||
sorted[dispatcher.host.name].status = Math.max(sorted[dispatcher.host.name].status, dispatcher.status);
|
||||
sorted[dispatcher.host.name].timestamp = Math.min(sorted[dispatcher.host.name].timestamp, dispatcher.timestamp);
|
||||
sorted[dispatcher.host.name].status = Math.max(
|
||||
sorted[dispatcher.host.name].status,
|
||||
dispatcher.status
|
||||
);
|
||||
sorted[dispatcher.host.name].timestamp = Math.min(
|
||||
sorted[dispatcher.host.name].timestamp,
|
||||
dispatcher.timestamp
|
||||
);
|
||||
|
||||
// Store the Dispatcher Status
|
||||
sorted[dispatcher.host.name].pids[dispatcher.pid].push({
|
||||
|
Loading…
Reference in New Issue
Block a user