forked from eclipse-theia/theia
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Refactors the plugin RPC protocol to make use of the new message-rpc introduced with eclipse-theia#11011/eclipse-theia#11228. - Refactor plugin-ext RpcProtocol API to reuse the new message-rpc protocol - Remove custom RPC message encoding and handling reuse message-rpc - Implement `QueuingChannelMultiplexer` 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 eclipse-theia#10684 Fixes eclipse-theia#9514 Contributed on behalf of STMicroelectronics
- Loading branch information
Showing
21 changed files
with
586 additions
and
561 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
87 changes: 87 additions & 0 deletions
87
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,87 @@ | ||
// ***************************************************************************** | ||
// 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'; | ||
import { ResponseError } from './rpc-message-encoder'; | ||
|
||
/** | ||
* 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); | ||
} | ||
} | ||
|
||
// Register custom msgPack extension for ResponseErrors. | ||
MsgPackExtensionManager.getInstance().registerExtensions({ | ||
class: ResponseError, | ||
tag: 1, | ||
serialize: (instance: ResponseError) => { | ||
const { code, data, message, name, stack } = instance; | ||
return { code, data, message, name, stack }; | ||
}, | ||
deserialize: data => { | ||
const error = new ResponseError(data.code, data.message, data.data); | ||
error.name = data.name; | ||
error.stack = data.stack; | ||
return error; | ||
} | ||
}); | ||
|
||
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
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.