Notify on connection events

Implement notification to plugins for disconnect request, connect, drop,
and close.  This allows plugins to properly handle slaves and the master
server shutting down without sending messages that will get lost.
This commit is contained in:
Hornwitser committed 2020-05-08 23:49:28 +02:00
1 parent b8b8c44083
commit c35b6de70e
13 files changed
+278 -31

No files matched your search

+28
View File
@@ -360,6 +360,18 @@ class Instance extends link.Link{
}
}
async masterConnectionEventEventHandler(message) {
for (let pluginInstance of this.plugins.values()) {
pluginInstance.onMasterConnectionEvent(message.data.event);
}
}
async prepareMasterDisconnectRequestHandler() {
for (let pluginInstance of this.plugins.values()) {
await pluginInstance.onPrepareMasterDisconnect();
}
}
async getMetricsRequestHandler() {
let results = []
if (this._running) {
@@ -582,6 +594,14 @@ class Slave extends link.Link {
this.instanceConnections = new Map();
this.instanceInfos = new Map();
for (let event of ["connect", "drop", "close"]) {
this.connector.on(event, () => {
for (let instanceConnection of this.instanceConnections.values()) {
link.messages.masterConnectionEvent.send(instanceConnection, { event });
}
});
}
}
async _findNewInstanceDir(name) {
@@ -770,6 +790,14 @@ class Slave extends link.Link {
await this.updateInstances();
}
async prepareDisconnectRequestHandler(message, request) {
for (let instanceConnection of this.instanceConnections.values()) {
await link.messages.prepareMasterDisconnect.send(instanceConnection);
}
this.connector.setClosing();
return await super.prepareDisconnectRequestHandler(message, request);
}
/**
* Stops all instances and closes the connection
*/