Class ExecJob

java.lang.Object
org.codelibs.fess.job.ExecJob
Direct Known Subclasses:
CrawlJob, GenerateThumbnailJob, PythonJob, SuggestJob

public abstract class ExecJob extends Object
Abstract base class for executable jobs in the Fess search engine. This class provides common functionality for job execution including process management, logging configuration, JVM options, and timeout handling.

Subclasses must implement the abstract methods to define specific job behavior and execution type identification.

Version:
1.0
  • Field Details

    • jobExecutor

      protected JobExecutor jobExecutor
      The job executor responsible for running this job
    • sessionId

      protected String sessionId
      Unique session identifier for this job execution
    • useLocalFesen

      protected boolean useLocalFesen
      Flag indicating whether to use local Fesen instance
    • logFilePath

      protected String logFilePath
      Path to the log file for this job execution
    • logLevel

      protected String logLevel
      Log level for this job execution
    • logSuffix

      protected String logSuffix
      Suffix to append to log file names
    • jvmOptions

      protected List<String> jvmOptions
      List of JVM options to apply when executing the job
    • lastaEnv

      protected String lastaEnv
      Lasta environment configuration
    • timeout

      protected int timeout
      Timeout in seconds for job execution (-1 means no timeout)
    • processTimeout

      protected boolean processTimeout
      Flag indicating whether the process has timed out
  • Constructor Details

    • ExecJob

      protected ExecJob()
      Default constructor for ExecJob. Initializes default values for job configuration.
  • Method Details

    • execute

      public abstract String execute()
      Executes the job and returns the result as a string. This method contains the main business logic for the specific job implementation.
      Returns:
      the execution result message or summary
    • getExecuteType

      protected abstract String getExecuteType()
      Returns the execution type identifier for this job. This type is used for classpath construction, configuration, and logging purposes.
      Returns:
      the execution type (e.g., "crawler", "suggest", etc.)
    • execute

      public String execute(JobExecutor jobExecutor)
      Executes the job with the specified job executor. This method sets the job executor and then calls the abstract execute method.
      Parameters:
      jobExecutor - the job executor to use for execution
      Returns:
      the execution result message or summary
    • jobExecutor

      public ExecJob jobExecutor(JobExecutor jobExecutor)
      Sets the job executor for this job.
      Parameters:
      jobExecutor - the job executor to set
      Returns:
      this ExecJob instance for method chaining
    • sessionId

      public ExecJob sessionId(String sessionId)
      Sets the session ID for this job execution.
      Parameters:
      sessionId - the unique session identifier
      Returns:
      this ExecJob instance for method chaining
    • logFilePath

      public ExecJob logFilePath(String logFilePath)
      Sets the log file path for this job execution.
      Parameters:
      logFilePath - the path to the log file
      Returns:
      this ExecJob instance for method chaining
    • logLevel

      public ExecJob logLevel(String logLevel)
      Sets the log level for this job execution.
      Parameters:
      logLevel - the log level (e.g., DEBUG, INFO, WARN, ERROR)
      Returns:
      this ExecJob instance for method chaining
    • logSuffix

      public ExecJob logSuffix(String logSuffix)
      Sets the log suffix for this job execution. The suffix is trimmed and whitespace is replaced with underscores.
      Parameters:
      logSuffix - the suffix to append to log file names
      Returns:
      this ExecJob instance for method chaining
    • timeout

      public ExecJob timeout(int timeout)
      Sets the timeout for this job execution.
      Parameters:
      timeout - the timeout in seconds (-1 for no timeout)
      Returns:
      this ExecJob instance for method chaining
    • useLocalFesen

      public ExecJob useLocalFesen(boolean useLocalFesen)
      Sets whether to use local Fesen instance.
      Parameters:
      useLocalFesen - true to use local Fesen, false otherwise
      Returns:
      this ExecJob instance for method chaining
    • remoteDebug

      public ExecJob remoteDebug()
      Enables remote debugging for this job execution. Adds JVM options for remote debugging on localhost:8000.
      Returns:
      this ExecJob instance for method chaining
    • gcLogging

      public ExecJob gcLogging()
      Enables garbage collection logging for this job execution. Configures JVM options for comprehensive GC logging with rotation.
      Returns:
      this ExecJob instance for method chaining
    • jvmOptions

      public ExecJob jvmOptions(String... options)
      Adds JVM options for this job execution.
      Parameters:
      options - the JVM options to add
      Returns:
      this ExecJob instance for method chaining
    • lastaEnv

      public ExecJob lastaEnv(String env)
      Sets the Lasta environment configuration.
      Parameters:
      env - the Lasta environment string
      Returns:
      this ExecJob instance for method chaining
    • addSystemProperty

      protected void addSystemProperty(List<String> cmdList, String name, String defaultValue, String appendValue)
      Adds a system property to the command list. If the property exists in the system, it uses that value with optional append value. Otherwise, it uses the default value if provided.
      Parameters:
      cmdList - the command list to add the property to
      name - the property name
      defaultValue - the default value to use if property doesn't exist
      appendValue - the value to append to the property value
    • addFessConfigProperties

      protected void addFessConfigProperties(List<String> cmdList)
      Adds all Fess configuration properties to the command list. Properties starting with the Fess config prefix are included.
      Parameters:
      cmdList - the command list to add properties to
    • addFessSystemProperties

      protected void addFessSystemProperties(List<String> cmdList)
      Adds all Fess system properties to the command list. Properties starting with the Fess system property prefix are included.
      Parameters:
      cmdList - the command list to add properties to
    • addFessCustomSystemProperties

      protected void addFessCustomSystemProperties(List<String> cmdList, String regex)
      Adds custom system properties that match the given regex pattern to the command list.
      Parameters:
      cmdList - the command list to add properties to
      regex - the regular expression pattern to match property names
    • deleteTempDir

      protected void deleteTempDir(File ownTmpDir)
      Deletes the specified temporary directory. Logs a warning if the directory cannot be deleted.
      Parameters:
      ownTmpDir - the temporary directory to delete
    • appendJarFile

      protected void appendJarFile(String cpSeparator, StringBuilder buf, File libDir, String basePath)
      Appends JAR files from the specified directory to the classpath buffer.
      Parameters:
      cpSeparator - the classpath separator to use
      buf - the StringBuilder to append to
      libDir - the directory containing JAR files
      basePath - the base path to prepend to JAR file names
    • createTimeoutTask

      protected org.codelibs.core.timer.TimeoutTask createTimeoutTask()
      Creates a timeout task for this job execution. If timeout is not set or is <= 0, returns null.
      Returns:
      the timeout task, or null if no timeout is configured
    • createSystemProperties

      protected void createSystemProperties(List<String> cmdList, File propFile)
      Creates and stores system properties to the specified file. Includes system properties and job runtime information if available.
      Parameters:
      cmdList - the command list (used as comment in properties file)
      propFile - the file to store properties to
      Throws:
      org.lastaflute.di.exception.IORuntimeException - if an I/O error occurs
    • getLogName

      protected String getLogName(String logPrefix)
      Generates a log name using the specified prefix, execution type, and suffix.
      Parameters:
      logPrefix - the prefix for the log name
      Returns:
      the generated log name