Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public shutdown() {
debugLog("ServerEngine#shutdown");
this.status = "shutdown";
this.setServerState(ServerState.Shutdown);
// delete any existing sessions
const tokens = Object.keys(this._sessions).map((key: string) => {
const session = this._sessions[key];
return session.authenticationToken;
});
// delete and close any orphan subscriptions
if (this._orphanPublishEngine) {
this._orphanPublishEngine.shutdown();
}
// xx console.log("xxxxxxxxx ServerEngine.shutdown must terminate "+ tokens.length," sessions");
tokens.forEach((token: any) => {
this.closeSession(token, true, "Terminated");
ServerEngine.prototype.shutdown = function () {
debugLog("ServerEngine#shutdown");
const engine = this;
engine.status = "shutdown";
engine.setServerState(ServerState.Shutdown);
// delete any existing sessions
const tokens = Object.keys(engine._sessions).map(function (key) {
const session = engine._sessions[key];
return session.authenticationToken;
});
// delete and close any orphan subscription
if (engine._orphanPublishEngine) {
engine._orphanPublishEngine.shutdown();
}
//xx console.log("xxxxxxxxx ServerEngine.shutdown must terminate "+ tokens.length," sessions");
tokens.forEach(function (token) {
if (!callback) {
callback = timeout;
timeout = 10; // 1 second
}
assert(_.isFunction(callback));
const self = this;
debugLog("OPCUAServer#shutdown (timeout = ", timeout, ")");
assert(self.engine);
if (!self.engine.serverStatus) {
// server may have been shot down already , or may have fail to start !!
const err = new Error("OPCUAServer#shutdown failure ! server doesn't seems to be started yet");
return callback(err);
}
self.engine.setServerState(ServerState.Shutdown);
self.registerServerManager.stop(function (err) {
debugLog("OPCUServer unregistered from discovery server",err);
setTimeout(function () {
self.engine.shutdown();
debugLog("OPCUAServer#shutdown: started");
OPCUABaseServer.prototype.shutdown.call(self, function (err) {
debugLog("OPCUAServer#shutdown: completed");
self.dispose();
callback(err);
});
}, timeout);
});