⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stopjbosstask.java

📁 一个java工作流引擎
💻 JAVA
字号:
package org.jbpm.ant;

import java.io.*;
import org.apache.tools.ant.*;

/**
 * This is an ant task that would shut down JBoss
 *
 * @author  jOptimus
 */
public class StopJBossTask extends Task {

  private static String SHUTDOWN_MESSAGE = "shutdown complete";
  private static String NOT_STARTED_MESSAGE = "failed to connect to";

  private static String FILE_SEPARATOR = System.getProperty("file.separator");

  private boolean log = false;

  /** Creates a new instance of StopJBossTask */
  public StopJBossTask() {
  }

  public void setLog(boolean log) {
    this.log = log;
  }

  public void execute() throws BuildException {
    try {
      Thread launcher = new Thread() {
        public void run() {
          try {
            String jbossHome = getProject().getProperty("jboss.home");
            String os = getProject().getProperty("os.name");

            String command = "";

            if (os.toLowerCase().indexOf("windows") != -1) {
              command = jbossHome + FILE_SEPARATOR + "bin" + FILE_SEPARATOR + "shutdown.bat -S ";
            } else if (os.toLowerCase().indexOf("linux") != -1) {
              command = jbossHome + FILE_SEPARATOR + "bin" + FILE_SEPARATOR + "shutdown.sh -S ";
            } else {
              throw new BuildException("os '" + os + "' not supported in stop jboss task");
            }
            log("stopping jboss with command '" + command + "'");
            Process process = Runtime.getRuntime().exec(command);
            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line = "";
            while ( ( line.toLowerCase().indexOf(SHUTDOWN_MESSAGE) == -1 )
                    && ( line.toLowerCase().indexOf(NOT_STARTED_MESSAGE) == -1 ) ) {
              line = reader.readLine();
              if (log) {
                log(line);
              }
            }
            log("jboss stopped");
          } catch (Throwable t) {
            t.printStackTrace();
          }
        }
      };

      launcher.start();
      launcher.join();
    } catch (Throwable t) {
      t.printStackTrace();
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -