Skip to content

Commit 9611b89

Browse files
authored
#101 Model Server Launcher extensibility (#102)
Implement the suggested extensibility hooks for subclasses to selectively override Java server and/or Node server launching. Also, because it's a related subject, fix the port assignment for the Java server in the two-server scenario allowing for subclasses also to override that. Fixes #101. Fixes #100. Contributed on behalf of STMicroelectronics. Signed-off-by: Christian W. Damus <cdamus.ext@eclipsesource.com>
1 parent d3d99a6 commit 9611b89

2 files changed

Lines changed: 55 additions & 6 deletions

File tree

packages/modelserver-theia/src/node/launch-options.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ export interface LaunchOptions {
1515
serverPort: number;
1616
hostname: string;
1717
jarPath?: string;
18+
/**
19+
* Additional arguments, besides those implied by other options, passed to server main entrypoint.
20+
*/
1821
additionalArgs?: string[];
22+
/**
23+
* Arguments passed to the Java Virtual Machine, not to the server application `main` entrypoint.
24+
*/
25+
vmArgs?: string[];
1926

2027
/**
2128
* For a configuration including the `modelserver-node`, launch options

packages/modelserver-theia/src/node/model-server-backend-contribution.ts

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,26 @@ export class DefaultModelServerLauncher implements ModelServerLauncher, BackendA
5555

5656
protected doStartServer(): void {
5757
// Note that the existence of the jarPath was previously checked
58-
let args = ['-jar', this.launchOptions.jarPath!, '--port', `${this.launchOptions.serverPort}`];
58+
let args = ['-jar', this.launchOptions.jarPath!, '--port', `${this.resolveJavaServerPort(this.launchOptions)}`];
59+
if (this.launchOptions.vmArgs) {
60+
args = [...this.launchOptions.vmArgs, ...args];
61+
}
5962
if (this.launchOptions.additionalArgs) {
6063
args = [...args, ...this.launchOptions.additionalArgs];
6164
}
6265
this.spawnProcessAsync('java', args);
6366
}
6467

68+
/**
69+
* Resolve the TCP port number that the Java server should be configured to listen on.
70+
*
71+
* @param options the launch options
72+
* @returns the most appropriate port number to configure the Java server process to listen on
73+
*/
74+
protected resolveJavaServerPort(options: LaunchOptions): number {
75+
return options.serverPort ?? DEFAULT_LAUNCH_OPTIONS.serverPort;
76+
}
77+
6578
protected validateLaunch(): boolean {
6679
if (!this.launchOptions.jarPath) {
6780
this.logError('Could not start model server. No path to executable is specified');
@@ -132,15 +145,23 @@ export class DefaultModelServerNodeLauncher extends DefaultModelServerLauncher {
132145
}
133146

134147
protected doStartServer(): void {
135-
// Launch the Java server
148+
this.startJavaServer();
149+
this.startNodeServer();
150+
}
151+
152+
protected startJavaServer(): void {
153+
// Launch the Java server as per superclass behavior
136154
super.doStartServer();
155+
}
137156

138-
// Then launch the Node server
157+
protected resolveJavaServerPort(options: LaunchOptions): number {
158+
return this.resolveUpstreamPort(options);
159+
}
139160

161+
protected startNodeServer(): void {
140162
// Note that validation previously asserted the existence of the `modelServerNode` property
141-
const upstreamPort =
142-
this.launchOptions.modelServerNode!.upstreamPort ?? DEFAULT_MODELSERVER_NODE_LAUNCH_OPTIONS.modelServerNode.upstreamPort;
143-
const port = this.launchOptions.serverPort;
163+
const upstreamPort = this.resolveUpstreamPort(this.launchOptions);
164+
const port = this.resolveNodeServerPort(this.launchOptions);
144165

145166
// Note that the existence of the jsPath was previously checked
146167
let args = [this.launchOptions.modelServerNode!.jsPath!, '--port', `${port}`, '--upstream', `${upstreamPort}`];
@@ -149,4 +170,25 @@ export class DefaultModelServerNodeLauncher extends DefaultModelServerLauncher {
149170
}
150171
this.spawnProcessAsync('node', args);
151172
}
173+
174+
/**
175+
* Resolve the TCP port number that the Node server should be configured to address its upstream Java server.
176+
*
177+
* @param options the launch options
178+
* @returns the most appropriate port number to configure the Node server process to connect to for the upstream Java server
179+
*/
180+
protected resolveUpstreamPort(options: LaunchOptions): number {
181+
// Note that validation previously asserted the existence of the `modelServerNode` property
182+
return options.modelServerNode!.upstreamPort ?? DEFAULT_MODELSERVER_NODE_LAUNCH_OPTIONS.modelServerNode.upstreamPort;
183+
}
184+
185+
/**
186+
* Resolve the TCP port number that the Node server should be configured to listen on.
187+
*
188+
* @param options the launch options
189+
* @returns the most appropriate port number to configure the Node server process to listen on
190+
*/
191+
protected resolveNodeServerPort(options: LaunchOptions): number {
192+
return options.serverPort ?? DEFAULT_MODELSERVER_NODE_LAUNCH_OPTIONS.serverPort;
193+
}
152194
}

0 commit comments

Comments
 (0)