-
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.
Integrate new message-rpc prototype into core messaging API (extensio…
…ns) (#11011) Refactors and improves the prototype of a faster JSON-RPC protocol initially contributed by @tsmaeder (See also #10781). The encoding approach used in the initial POC has some performance drawbacks when encoding plain JSON objects. We refactored the protocol to improve the performance for JSON objects whilst maintaining the excellent performance for encoding objects that contain binary data. Integrates the new message-rpc prototype into the core messaging API (replacing vscode-ws-jsonrpc). This has major impacts on the Messaging API as we no longer expose a `Connection` object (which was provided by vscode-ws-jsonrpc) and directly rely on a generic transport `Channel` implementation instead. - Introduce `Channel` as the main transport concept for messages (instead of the dedicated `Connection` from vscode-jsonrpc) - Replace usage of `vscode-ws-jsonrpc` with a custom binary RPC protocol. - Remove 'vscode-ws-jsonrpc' depdency from "@theia/core/shared". - Refactor all connection providers to use the new binary protocol. - Ensure that the `RemoteFileSystemProvider` API uses `Uint8Arrays` over plain number arrays. This enables direct serialization as buffers and reduces the overhead of unnecessarily converting from and to `Uint8Arrays`. - Refactor terminal widget and terminal backend contribution so that the widgets communicates with the underlying terminal process using the new rpc protocol. - Rework the IPC bootstrap protocol so that it uses a binary pipe for message transmission instead of the `ipc` pipe which only supports string encoding. - Extend the `JsonRpcProxyFactory` with an optional `RpcConnectionFactory` that enables adopter to creates proxies with a that use a custom `RpcProtocol`/`RpcConnection`. The plugin API still uses its own RPC protocol implementation. This will be addressed in a follow-up PR. (See #11093) Contributed on behalf of STMicroelectronics. Closes #10684 Co-authored-by: Thomas Mäder <[email protected]>
- Loading branch information
Showing
51 changed files
with
2,254 additions
and
631 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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2021 Red Hat, Inc. 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 { assert, expect, spy, use } from 'chai'; | ||
import * as spies from 'chai-spies'; | ||
import { Uint8ArrayReadBuffer, Uint8ArrayWriteBuffer } from './uint8-array-message-buffer'; | ||
import { ChannelMultiplexer, ForwardingChannel, MessageProvider } from './channel'; | ||
|
||
use(spies); | ||
|
||
/** | ||
* A pipe with two channels at each end for testing. | ||
*/ | ||
export class ChannelPipe { | ||
readonly left: ForwardingChannel = new ForwardingChannel('left', () => this.right.onCloseEmitter.fire({ reason: 'Left channel has been closed' }), () => { | ||
const leftWrite = new Uint8ArrayWriteBuffer(); | ||
leftWrite.onCommit(buffer => { | ||
this.right.onMessageEmitter.fire(() => new Uint8ArrayReadBuffer(buffer)); | ||
}); | ||
return leftWrite; | ||
}); | ||
readonly right: ForwardingChannel = new ForwardingChannel('right', () => this.left.onCloseEmitter.fire({ reason: 'Right channel has been closed' }), () => { | ||
const rightWrite = new Uint8ArrayWriteBuffer(); | ||
rightWrite.onCommit(buffer => { | ||
this.left.onMessageEmitter.fire(() => new Uint8ArrayReadBuffer(buffer)); | ||
}); | ||
return rightWrite; | ||
}); | ||
} | ||
describe('Message Channel', () => { | ||
describe('Channel multiplexer', () => { | ||
it('should forward messages to intended target channel', async () => { | ||
const pipe = new ChannelPipe(); | ||
|
||
const leftMultiplexer = new ChannelMultiplexer(pipe.left); | ||
const rightMultiplexer = new ChannelMultiplexer(pipe.right); | ||
const openChannelSpy = spy(() => { | ||
}); | ||
|
||
rightMultiplexer.onDidOpenChannel(openChannelSpy); | ||
leftMultiplexer.onDidOpenChannel(openChannelSpy); | ||
|
||
const leftFirst = await leftMultiplexer.open('first'); | ||
const leftSecond = await leftMultiplexer.open('second'); | ||
|
||
const rightFirst = rightMultiplexer.getOpenChannel('first'); | ||
const rightSecond = rightMultiplexer.getOpenChannel('second'); | ||
|
||
assert.isNotNull(rightFirst); | ||
assert.isNotNull(rightSecond); | ||
|
||
const leftSecondSpy = spy((buf: MessageProvider) => { | ||
const message = buf().readString(); | ||
expect(message).equal('message for second'); | ||
}); | ||
|
||
leftSecond.onMessage(leftSecondSpy); | ||
|
||
const rightFirstSpy = spy((buf: MessageProvider) => { | ||
const message = buf().readString(); | ||
expect(message).equal('message for first'); | ||
}); | ||
|
||
rightFirst!.onMessage(rightFirstSpy); | ||
|
||
leftFirst.getWriteBuffer().writeString('message for first').commit(); | ||
rightSecond!.getWriteBuffer().writeString('message for second').commit(); | ||
|
||
expect(leftSecondSpy).to.be.called(); | ||
expect(rightFirstSpy).to.be.called(); | ||
|
||
expect(openChannelSpy).to.be.called.exactly(4); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.