@@ -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