mirror of
https://github.com/nasa/openmct.git
synced 2025-05-03 01:02:52 +00:00
[Staleness] Fix removed object error and clean up (#6241)
* fixing error from plots when removing swg and making methods and props private for swg staleness provider * removing unsubscribes from destroy hooks if the item has been removed already and reverting an unneccesary change * checking for undefined staleness response * removed un-neccesary code
This commit is contained in:
parent
c1c1d87953
commit
c1e8c7915c
@ -23,14 +23,18 @@
|
|||||||
import EventEmitter from 'EventEmitter';
|
import EventEmitter from 'EventEmitter';
|
||||||
|
|
||||||
export default class SinewaveLimitProvider extends EventEmitter {
|
export default class SinewaveLimitProvider extends EventEmitter {
|
||||||
|
#openmct;
|
||||||
|
#observingStaleness;
|
||||||
|
#watchingTheClock;
|
||||||
|
#isRealTime;
|
||||||
|
|
||||||
constructor(openmct) {
|
constructor(openmct) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.openmct = openmct;
|
this.#openmct = openmct;
|
||||||
this.observingStaleness = {};
|
this.#observingStaleness = {};
|
||||||
this.watchingTheClock = false;
|
this.#watchingTheClock = false;
|
||||||
this.isRealTime = undefined;
|
this.#isRealTime = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
supportsStaleness(domainObject) {
|
supportsStaleness(domainObject) {
|
||||||
@ -38,114 +42,116 @@ export default class SinewaveLimitProvider extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isStale(domainObject, options) {
|
isStale(domainObject, options) {
|
||||||
if (!this.providingStaleness(domainObject)) {
|
if (!this.#providingStaleness(domainObject)) {
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
isStale: false,
|
isStale: false,
|
||||||
utc: 0
|
utc: 0
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const id = this.getObjectKeyString(domainObject);
|
const id = this.#getObjectKeyString(domainObject);
|
||||||
|
|
||||||
if (!this.observerExists(id)) {
|
if (!this.#observerExists(id)) {
|
||||||
this.createObserver(id);
|
this.#createObserver(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve(this.observingStaleness[id].isStale);
|
return Promise.resolve(this.#observingStaleness[id].isStale);
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribeToStaleness(domainObject, callback) {
|
subscribeToStaleness(domainObject, callback) {
|
||||||
const id = this.getObjectKeyString(domainObject);
|
const id = this.#getObjectKeyString(domainObject);
|
||||||
|
|
||||||
if (this.isRealTime === undefined) {
|
if (this.#isRealTime === undefined) {
|
||||||
this.updateRealTime(this.openmct.time.clock());
|
this.#updateRealTime(this.#openmct.time.clock());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.handleClockUpdate();
|
this.#handleClockUpdate();
|
||||||
|
|
||||||
if (this.observerExists(id)) {
|
if (this.#observerExists(id)) {
|
||||||
this.addCallbackToObserver(id, callback);
|
this.#addCallbackToObserver(id, callback);
|
||||||
} else {
|
} else {
|
||||||
this.createObserver(id, callback);
|
this.#createObserver(id, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
const intervalId = setInterval(() => {
|
const intervalId = setInterval(() => {
|
||||||
if (this.providingStaleness(domainObject)) {
|
if (this.#providingStaleness(domainObject)) {
|
||||||
this.updateStaleness(id, !this.observingStaleness[id].isStale);
|
this.#updateStaleness(id, !this.#observingStaleness[id].isStale);
|
||||||
}
|
}
|
||||||
}, 10000);
|
}, 10000);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
clearInterval(intervalId);
|
clearInterval(intervalId);
|
||||||
this.updateStaleness(id, false);
|
this.#updateStaleness(id, false);
|
||||||
this.handleClockUpdate();
|
this.#handleClockUpdate();
|
||||||
this.destroyObserver(id);
|
this.#destroyObserver(id);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
handleClockUpdate() {
|
#handleClockUpdate() {
|
||||||
let observers = Object.values(this.observingStaleness).length > 0;
|
let observers = Object.values(this.#observingStaleness).length > 0;
|
||||||
|
|
||||||
if (observers && !this.watchingTheClock) {
|
if (observers && !this.#watchingTheClock) {
|
||||||
this.watchingTheClock = true;
|
this.#watchingTheClock = true;
|
||||||
this.openmct.time.on('clock', this.updateRealTime, this);
|
this.#openmct.time.on('clock', this.#updateRealTime, this);
|
||||||
} else if (!observers && this.watchingTheClock) {
|
} else if (!observers && this.#watchingTheClock) {
|
||||||
this.watchingTheClock = false;
|
this.#watchingTheClock = false;
|
||||||
this.openmct.time.off('clock', this.updateRealTime, this);
|
this.#openmct.time.off('clock', this.#updateRealTime, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateRealTime(clock) {
|
#updateRealTime(clock) {
|
||||||
this.isRealTime = clock !== undefined;
|
this.#isRealTime = clock !== undefined;
|
||||||
|
|
||||||
if (!this.isRealTime) {
|
if (!this.#isRealTime) {
|
||||||
Object.keys(this.observingStaleness).forEach((id) => {
|
Object.keys(this.#observingStaleness).forEach((id) => {
|
||||||
this.updateStaleness(id, false);
|
this.#updateStaleness(id, false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateStaleness(id, isStale) {
|
#updateStaleness(id, isStale) {
|
||||||
this.observingStaleness[id].isStale = isStale;
|
this.#observingStaleness[id].isStale = isStale;
|
||||||
this.observingStaleness[id].utc = Date.now();
|
this.#observingStaleness[id].utc = Date.now();
|
||||||
this.observingStaleness[id].callback({
|
this.#observingStaleness[id].callback({
|
||||||
isStale: this.observingStaleness[id].isStale,
|
isStale: this.#observingStaleness[id].isStale,
|
||||||
utc: this.observingStaleness[id].utc
|
utc: this.#observingStaleness[id].utc
|
||||||
});
|
});
|
||||||
this.emit('stalenessEvent', {
|
this.emit('stalenessEvent', {
|
||||||
id,
|
id,
|
||||||
isStale: this.observingStaleness[id].isStale
|
isStale: this.#observingStaleness[id].isStale
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
createObserver(id, callback) {
|
#createObserver(id, callback) {
|
||||||
this.observingStaleness[id] = {
|
this.#observingStaleness[id] = {
|
||||||
isStale: false,
|
isStale: false,
|
||||||
utc: Date.now()
|
utc: Date.now()
|
||||||
};
|
};
|
||||||
|
|
||||||
if (typeof callback === 'function') {
|
if (typeof callback === 'function') {
|
||||||
this.addCallbackToObserver(id, callback);
|
this.#addCallbackToObserver(id, callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
destroyObserver(id) {
|
#destroyObserver(id) {
|
||||||
delete this.observingStaleness[id];
|
if (this.#observingStaleness[id]) {
|
||||||
|
delete this.#observingStaleness[id];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
providingStaleness(domainObject) {
|
#providingStaleness(domainObject) {
|
||||||
return domainObject.telemetry?.staleness === true && this.isRealTime;
|
return domainObject.telemetry?.staleness === true && this.#isRealTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
getObjectKeyString(object) {
|
#getObjectKeyString(object) {
|
||||||
return this.openmct.objects.makeKeyString(object.identifier);
|
return this.#openmct.objects.makeKeyString(object.identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
addCallbackToObserver(id, callback) {
|
#addCallbackToObserver(id, callback) {
|
||||||
this.observingStaleness[id].callback = callback;
|
this.#observingStaleness[id].callback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
observerExists(id) {
|
#observerExists(id) {
|
||||||
return this.observingStaleness?.[id];
|
return this.#observingStaleness?.[id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -218,6 +218,7 @@ export default {
|
|||||||
this.stalenessSubscription[keystring].unsubscribe();
|
this.stalenessSubscription[keystring].unsubscribe();
|
||||||
this.stalenessSubscription[keystring].stalenessUtils.destroy();
|
this.stalenessSubscription[keystring].stalenessUtils.destroy();
|
||||||
this.handleStaleness(keystring, { isStale: false }, SKIP_CHECK);
|
this.handleStaleness(keystring, { isStale: false }, SKIP_CHECK);
|
||||||
|
delete this.stalenessSubscription[keystring];
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
handleStaleness(id, stalenessResponse, skipCheck = false) {
|
handleStaleness(id, stalenessResponse, skipCheck = false) {
|
||||||
|
@ -232,7 +232,9 @@ export default {
|
|||||||
this.stalenessSubscription[keyString].stalenessUtils = new StalenessUtils(this.openmct, domainObject);
|
this.stalenessSubscription[keyString].stalenessUtils = new StalenessUtils(this.openmct, domainObject);
|
||||||
|
|
||||||
this.openmct.telemetry.isStale(domainObject).then((stalenessResponse) => {
|
this.openmct.telemetry.isStale(domainObject).then((stalenessResponse) => {
|
||||||
this.hanldeStaleness(keyString, stalenessResponse);
|
if (stalenessResponse !== undefined) {
|
||||||
|
this.hanldeStaleness(keyString, stalenessResponse);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
const stalenessSubscription = this.openmct.telemetry.subscribeToStaleness(domainObject, (stalenessResponse) => {
|
const stalenessSubscription = this.openmct.telemetry.subscribeToStaleness(domainObject, (stalenessResponse) => {
|
||||||
this.hanldeStaleness(keyString, stalenessResponse);
|
this.hanldeStaleness(keyString, stalenessResponse);
|
||||||
@ -259,6 +261,7 @@ export default {
|
|||||||
keyString,
|
keyString,
|
||||||
isStale: false
|
isStale: false
|
||||||
});
|
});
|
||||||
|
delete this.stalenessSubscription[keyString];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
hanldeStaleness(keyString, stalenessResponse) {
|
hanldeStaleness(keyString, stalenessResponse) {
|
||||||
|
@ -83,6 +83,11 @@ export default class AllTelemetryCriterion extends TelemetryCriterion {
|
|||||||
if (!this.stalenessSubscription[id]) {
|
if (!this.stalenessSubscription[id]) {
|
||||||
this.stalenessSubscription[id] = {};
|
this.stalenessSubscription[id] = {};
|
||||||
this.stalenessSubscription[id].stalenessUtils = new StalenessUtils(this.openmct, telemetryObject);
|
this.stalenessSubscription[id].stalenessUtils = new StalenessUtils(this.openmct, telemetryObject);
|
||||||
|
this.openmct.telemetry.isStale(telemetryObject).then((stalenessResponse) => {
|
||||||
|
if (stalenessResponse !== undefined) {
|
||||||
|
this.handleStaleTelemetry(id, stalenessResponse);
|
||||||
|
}
|
||||||
|
});
|
||||||
this.stalenessSubscription[id].unsubscribe = this.openmct.telemetry.subscribeToStaleness(
|
this.stalenessSubscription[id].unsubscribe = this.openmct.telemetry.subscribeToStaleness(
|
||||||
telemetryObject,
|
telemetryObject,
|
||||||
(stalenessResponse) => {
|
(stalenessResponse) => {
|
||||||
|
@ -166,6 +166,7 @@ export default {
|
|||||||
this.stalenessSubscription[keystring].unsubscribe();
|
this.stalenessSubscription[keystring].unsubscribe();
|
||||||
this.stalenessSubscription[keystring].stalenessUtils.destroy();
|
this.stalenessSubscription[keystring].stalenessUtils.destroy();
|
||||||
this.handleStaleness(keystring, { isStale: false }, SKIP_CHECK);
|
this.handleStaleness(keystring, { isStale: false }, SKIP_CHECK);
|
||||||
|
delete this.stalenessSubscription[keystring];
|
||||||
},
|
},
|
||||||
handleStaleness(id, stalenessResponse, skipCheck = false) {
|
handleStaleness(id, stalenessResponse, skipCheck = false) {
|
||||||
if (skipCheck || this.stalenessSubscription[id].stalenessUtils.shouldUpdateStaleness(stalenessResponse, id)) {
|
if (skipCheck || this.stalenessSubscription[id].stalenessUtils.shouldUpdateStaleness(stalenessResponse, id)) {
|
||||||
|
@ -293,6 +293,7 @@ define([
|
|||||||
this.stalenessSubscription[keyString].unsubscribe();
|
this.stalenessSubscription[keyString].unsubscribe();
|
||||||
this.stalenessSubscription[keyString].stalenessUtils.destroy();
|
this.stalenessSubscription[keyString].stalenessUtils.destroy();
|
||||||
this.handleStaleness(keyString, { isStale: false }, SKIP_CHECK);
|
this.handleStaleness(keyString, { isStale: false }, SKIP_CHECK);
|
||||||
|
delete this.stalenessSubscription[keyString];
|
||||||
}
|
}
|
||||||
|
|
||||||
clearData() {
|
clearData() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user