Class ProcessHelper

java.lang.Object
org.codelibs.fess.helper.ProcessHelper

public class ProcessHelper extends Object
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 Details

    • runningProcessMap

      protected final ConcurrentHashMap<String,JobProcess> runningProcessMap
      Map of running processes indexed by session ID
    • processDestroyTimeout

      protected int processDestroyTimeout
      Timeout in seconds for process destruction
    • streamCloseTimeout

      protected int streamCloseTimeout
      Timeout 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 session
      cmdList - list of command and arguments to execute
      pbCall - 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 session
      cmdList - list of command and arguments to execute
      pbCall - callback to configure the ProcessBuilder
      bufferSize - size of the buffer for process output
      outputCallback - callback to handle process output lines
      Returns:
      JobProcess representing the started process
      Throws:
      JobProcessingException - if the process cannot be started
    • destroyProcess

      public int destroyProcess(String sessionId)
      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

      public boolean isProcessRunning(String sessionId)
      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

      protected int destroyProcess(String sessionId, JobProcess jobProcess)
      Internal method to destroy a specific JobProcess. Handles cleanup of streams, threads, and process termination.
      Parameters:
      sessionId - unique identifier for the process session
      jobProcess - the JobProcess to destroy
      Returns:
      exit code of the destroyed process, or -1 if the process was null or could not be destroyed
    • getRunningSessionIdSet

      public Set<String> 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

      public void sendCommand(String sessionId, String command)
      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 session
      command - the command to send to the process
      Throws:
      JobNotFoundException - if no process is found for the given session ID
      JobProcessingException - if there's an error sending the command