Package org.codelibs.fess.helper
Class ProcessHelper
java.lang.Object
org.codelibs.fess.helper.ProcessHelper
Helper class for managing system processes in Fess.
This class provides functionality to start, stop, and manage external processes
such as crawler processes, with proper resource cleanup and lifecycle management.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intTimeout in seconds for process destructionprotected final ConcurrentHashMap<String, JobProcess> Map of running processes indexed by session IDprotected intTimeout in seconds for stream closing operations -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()Cleanup method called when the bean is destroyed.intdestroyProcess(String sessionId) Destroys the process associated with the given session ID.protected intdestroyProcess(String sessionId, JobProcess jobProcess) Internal method to destroy a specific JobProcess.Gets the set of session IDs for all currently running processes.booleanChecks if any processes are currently running.booleanisProcessRunning(String sessionId) Checks if the process with the given session ID is currently running.voidsendCommand(String sessionId, String command) Sends a command to the process associated with the given session ID.voidsetProcessDestroyTimeout(int processDestroyTimeout) Sets the timeout for process destruction.voidsetStreamCloseTimeout(int streamCloseTimeout) Sets the timeout for stream closing operations.startProcess(String sessionId, List<String> cmdList, Consumer<ProcessBuilder> pbCall) Starts a new process with the given session ID and command list.startProcess(String sessionId, List<String> cmdList, Consumer<ProcessBuilder> pbCall, int bufferSize, Consumer<String> outputCallback) Starts a new process with the given session ID, command list, buffer size, and output callback.
-
Field Details
-
runningProcessMap
Map of running processes indexed by session ID -
processDestroyTimeout
protected int processDestroyTimeoutTimeout in seconds for process destruction -
streamCloseTimeout
protected int streamCloseTimeoutTimeout in seconds for stream closing operations
-
-
Constructor Details
-
ProcessHelper
public ProcessHelper()Default constructor for ProcessHelper. Initializes the process management system with default timeout values.
-
-
Method Details
-
destroy
@PreDestroy public void destroy()Cleanup method called when the bean is destroyed. Stops all running processes and cleans up resources. -
startProcess
public JobProcess startProcess(String sessionId, List<String> cmdList, Consumer<ProcessBuilder> pbCall) Starts a new process with the given session ID and command list. Uses default buffer size and no output callback.- Parameters:
sessionId- unique identifier for the process sessioncmdList- list of command and arguments to executepbCall- callback to configure the ProcessBuilder- Returns:
- JobProcess representing the started process
-
startProcess
public JobProcess startProcess(String sessionId, List<String> cmdList, Consumer<ProcessBuilder> pbCall, int bufferSize, Consumer<String> outputCallback) Starts a new process with the given session ID, command list, buffer size, and output callback. This method is synchronized to ensure thread safety when managing processes.- Parameters:
sessionId- unique identifier for the process sessioncmdList- list of command and arguments to executepbCall- callback to configure the ProcessBuilderbufferSize- size of the buffer for process outputoutputCallback- callback to handle process output lines- Returns:
- JobProcess representing the started process
- Throws:
JobProcessingException- if the process cannot be started
-
destroyProcess
Destroys the process associated with the given session ID.- Parameters:
sessionId- unique identifier for the process session- Returns:
- exit code of the destroyed process, or -1 if the process was not found
-
isProcessRunning
public boolean isProcessRunning()Checks if any processes are currently running.- Returns:
- true if at least one process is running, false otherwise
-
isProcessRunning
Checks if the process with the given session ID is currently running.- Parameters:
sessionId- unique identifier for the process session- Returns:
- true if the process is running, false otherwise
-
destroyProcess
Internal method to destroy a specific JobProcess. Handles cleanup of streams, threads, and process termination.- Parameters:
sessionId- unique identifier for the process sessionjobProcess- the JobProcess to destroy- Returns:
- exit code of the destroyed process, or -1 if the process was null or could not be destroyed
-
getRunningSessionIdSet
Gets the set of session IDs for all currently running processes.- Returns:
- set of session IDs for running processes
-
setProcessDestroyTimeout
public void setProcessDestroyTimeout(int processDestroyTimeout) Sets the timeout for process destruction.- Parameters:
processDestroyTimeout- timeout in seconds for process destruction
-
setStreamCloseTimeout
public void setStreamCloseTimeout(int streamCloseTimeout) Sets the timeout for stream closing operations.- Parameters:
streamCloseTimeout- timeout in seconds for stream closing operations
-
sendCommand
Sends a command to the process associated with the given session ID. Uses finer-grained locking to avoid blocking other operations during I/O.- Parameters:
sessionId- unique identifier for the process sessioncommand- the command to send to the process- Throws:
JobNotFoundException- if no process is found for the given session IDJobProcessingException- if there's an error sending the command
-