-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use binary message RPC protocol for plugin API (#11261)
Refactors the plugin RPC protocol to make use of the new message-rpc introduced with #11011/#11228. - Refactor plugin-ext RpcProtocol API to reuse the new message-rpc protocol - Remove custom RPC message encoding and handling reuse message-rpc - Implement `BatchingChannel` that queues messages and sends them accumulated on the next process.tick (replaces the old Multiplexer implementation) - Refactors proxy handlers and remote target handlers - Use `Channel` instead of `MessageConnection` for creating new instances of RPCProtocol - Refactor `RpcMessageEncoder`/`RpcMessageDecoder` to enable overwritting of already registered value encoders/decoders. - Add mode property to base `RpcProtocol` to enable switching from a bidirectional RPC protocol to a client-only or server-only variant. - Implement special message encoders and decoders for the plugin communication. (Replacement for the old `ObjectTransferrer` JSON replacers/revivers) - Adapt `HostedPluginServer` and `HostedPluginClient` API to send/receive messages in binary format instead of strings. This enables direct writethrough of the binary messages received from the hosted plugin process. - Adapt `hosted-plugin-process` and `plugin-host` to directly send binary messages via `IpcChannel`/`BinaryMessagePipe` - Remove incorrect (and unused) notification proxy identifiers and instantiation - NotificationExt was instantiated in the main context - There were unused notification proxy identifiers for main and ext in the wrong contexts Part of #10684 Fixes #9514 Contributed on behalf of STMicroelectronics
- Loading branch information
Showing
23 changed files
with
590 additions
and
574 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
packages/core/src/common/message-rpc/msg-pack-extension-manager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2022 STMicroelectronics and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0. | ||
// | ||
// This Source Code may also be made available under the following Secondary | ||
// Licenses when the conditions for such availability set forth in the Eclipse | ||
// Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
// with the GNU Classpath Exception which is available at | ||
// https://www.gnu.org/software/classpath/license.html. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
// ***************************************************************************** | ||
|
||
import { addExtension } from 'msgpackr'; | ||
|
||
/** | ||
* Handles the global registration of custom MsgPackR extensions | ||
* required for the default RPC communication. MsgPackR extensions | ||
* are installed globally on both ends of the communication channel. | ||
* (frontend-backend, pluginExt-pluginMain). | ||
* Is implemented as singleton as it is also used in plugin child processes which have no access to inversify. | ||
*/ | ||
export class MsgPackExtensionManager { | ||
private static readonly INSTANCE = new MsgPackExtensionManager(); | ||
public static getInstance(): MsgPackExtensionManager { | ||
return this.INSTANCE; | ||
} | ||
|
||
private extensions = new Map<number, MsgPackExtension>(); | ||
|
||
private constructor() { | ||
} | ||
|
||
registerExtensions(...extensions: MsgPackExtension[]): void { | ||
extensions.forEach(extension => { | ||
if (extension.tag < 1 || extension.tag > 100) { | ||
// MsgPackR reserves the tag range 1-100 for custom extensions. | ||
throw new Error(`MsgPack extension tag should be a number from 1-100 but was '${extension.tag}'`); | ||
} | ||
if (this.extensions.has(extension.tag)) { | ||
throw new Error(`Another MsgPack extension with the tag '${extension.tag}' is already registered`); | ||
} | ||
this.extensions.set(extension.tag, extension); | ||
addExtension({ | ||
Class: extension.class, | ||
type: extension.tag, | ||
write: extension.serialize, | ||
read: extension.deserialize | ||
}); | ||
}); | ||
} | ||
|
||
getExtension(tag: number): MsgPackExtension | undefined { | ||
return this.extensions.get(tag); | ||
} | ||
} | ||
|
||
export interface MsgPackExtension { | ||
class: Function, | ||
tag: number, | ||
serialize(instance: unknown): unknown, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
deserialize(serialized: any): unknown | ||
} | ||
|
||
export type Constructor<T> = new (...params: unknown[]) => T; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.