All Downloads are FREE. Search and download functionalities are using the official Maven repository.

water.api.KillMinus3Handler Maven / Gradle / Ivy

There is a newer version: 3.8.2.9
Show newest version
package water.api;

import water.H2O;
import water.MRTask;
import water.exceptions.H2OIllegalArgumentException;

public class KillMinus3Handler extends Handler {
  @SuppressWarnings("unused") // called through reflection by RequestServer

  private static String getProcessId() throws Exception {
    // Note: may fail in some JVM implementations
    // therefore fallback has to be provided

    // something like '@', at least in SUN / Oracle JVMs
    final String jvmName = java.lang.management.ManagementFactory.getRuntimeMXBean().getName();
    final int index = jvmName.indexOf('@');

    if (index < 1) {
      // part before '@' empty (index = 0) / '@' not found (index = -1)
      throw new Exception ("Can't get process Id");
    }

    return Long.toString(Long.parseLong(jvmName.substring(0, index)));
  }

  public KillMinus3V3 killm3(int version, KillMinus3V3 u) {
      new MRTask((byte)(H2O.MIN_HI_PRIORITY - 1)) {
        @Override public void setupLocal() {
          try {
            String cmd = "/bin/kill -3 " + getProcessId();
            java.lang.Runtime.getRuntime().exec(cmd);
          } catch( java.io.IOException ioe ) {
            // Silently ignore if, e.g. /bin/kill does not exist on windows
          } catch (Exception xe) {
            xe.printStackTrace();
            throw new H2OIllegalArgumentException("");
          }
        }
      }.doAllNodes();
    return u;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy