Implementation:APIJSON APIJSON Demo AutoTestNodeProcessSupervisor
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Process_Management, Reliability, DevOps |
| Last Updated | 2026-10-14 00:00 GMT |
Overview
Concrete tool for managing the lifecycle of the Node.js APIAuto test runner process, providing automatic startup, health monitoring, crash recovery, and graceful shutdown provided by the APIJSON Demo server.
Description
The AutoTestNodeProcessSupervisor class is a Spring @Service that manages the Node.js process running the APIAuto test UI. It:
- Starts on application ready: Listens for
ApplicationReadyEventand starts the Node.js process after Spring Boot is fully initialized. - Health checking: Uses
@Scheduled(fixedDelay)to poll the Node.js HTTP endpoint every 30 seconds. If unreachable, it restarts the process. - Process management: Uses
ProcessBuilderto launch the Node.js process with configurable command, script, and working directory. Output is redirected to a log file. - Startup timeout: Waits up to
startupTimeoutMillis(default 60s) for the process to become reachable. If the process exits immediately or the timeout expires, an error is thrown. - Graceful shutdown:
@PreDestroyhook terminates the process on JVM shutdown. - Concurrency safety: Uses
synchronized(lock)with double-checkedisNodeServiceReachable()to prevent duplicate processes.
Usage
- Automatic lifecycle: Starts and monitors automatically — no manual invocation needed.
- Configuration: All parameters via
@Valueinjection fromapplication.yml. - Disabling: Set
apijson.auto-test.node.enabled=false.
Code Reference
Source Location
- Repository: APIJSON-Demo
- File: APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/java/apijson/boot/AutoTestNodeProcessSupervisor.java
Signature
@Service
public class AutoTestNodeProcessSupervisor {
@Value("${apijson.auto-test.node.command:node}") private String nodeCommand;
@Value("${apijson.auto-test.node.script:js/server.js}") private String nodeScript;
@Value("${apijson.auto-test.node.working-directory:src/main/resources/static/api}") private String nodeWorkingDirectory;
@Value("${apijson.auto-test.node.startup-timeout-millis:60000}") private long startupTimeoutMillis;
@EventListener(ApplicationReadyEvent.class)
public void startWhenApplicationReady();
@Scheduled(fixedDelayString = "${apijson.auto-test.node.health-check-interval-millis:30000}",
initialDelayString = "${apijson.auto-test.node.health-check-interval-millis:30000}")
public void keepAlive();
public void ensureRunning();
public boolean isNodeServiceReachable();
@PreDestroy
public void stopManagedProcess();
private void startProcess();
private void waitUntilReachable();
private Path resolveWorkingDirectory();
private Path prepareLogFile(Path workingDirectory);
}
Import
import apijson.boot.AutoTestNodeProcessSupervisor;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| nodeCommand | String | No | Node.js executable (default: "node") |
| nodeScript | String | No | Script path relative to working directory (default: "js/server.js") |
| nodeWorkingDirectory | String | No | Working directory (default: "src/main/resources/static/api") |
| startupTimeoutMillis | long | No | Max startup wait (default: 60000ms) |
Outputs
| Name | Type | Description |
|---|---|---|
| process | Process | Managed Node.js process with PID |
| logFilePath | Path | Log file at {workingDir}/logs/api-auto-node.log |
| isNodeServiceReachable | boolean | True if HTTP GET returns 2xx |
Usage Examples
application.yml Configuration
apijson:
auto-test:
node:
enabled: true
command: node
script: js/server.js
working-directory: src/main/resources/static/api
startup-timeout-millis: 60000
health-check-interval-millis: 30000
Manual Health Check
@Autowired
private AutoTestNodeProcessSupervisor supervisor;
// Check if Node.js is running
if (supervisor.isNodeServiceReachable()) {
System.out.println("APIAuto Node is healthy");
} else {
// Ensure it starts
supervisor.ensureRunning();
}
Related Pages
Implements Principle
- Principle:APIJSON_APIJSON_Demo_Process_Supervision
- Principle:APIJSON_APIJSON_Demo_Automated_Regression_Testing
Requires Environment
Uses Heuristic
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment