View Javadoc
1   /*
2    * Copyright 2012-2025 CodeLibs Project and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.codelibs.fess.job;
17  
18  /**
19   * Abstract base class for job executors that handle script execution within the job system.
20   * This class provides a framework for executing scripts and managing shutdown operations.
21   */
22  public abstract class JobExecutor {
23      /** Listener to handle shutdown events */
24      protected ShutdownListener shutdownListener;
25  
26      /**
27       * Default constructor.
28       */
29      public JobExecutor() {
30          // Default constructor
31      }
32  
33      /**
34       * Executes a script with the specified script type and content.
35       *
36       * @param scriptType the type of script to execute
37       * @param script the script content to execute
38       * @return the result of script execution
39       */
40      public abstract Object execute(String scriptType, String script);
41  
42      /**
43       * Initiates shutdown of the job executor.
44       * This method notifies the shutdown listener to perform cleanup operations.
45       */
46      public void shutdown() {
47          shutdownListener.onShutdown();
48      }
49  
50      /**
51       * Adds a shutdown listener to be notified when the executor is shutting down.
52       *
53       * @param listener the shutdown listener to add
54       */
55      public void addShutdownListener(final ShutdownListener listener) {
56          shutdownListener = listener;
57      }
58  
59      /**
60       * Interface for listening to shutdown events.
61       */
62      public interface ShutdownListener {
63          /**
64           * Called when the job executor is shutting down.
65           */
66          void onShutdown();
67      }
68  }