/** Runner thread which actually launches the application. */
  public void run() {
    Throwable t = null;
    try {
      if (WrapperManager.isDebugEnabled()) {
        System.out.println(
            Main.getRes().getString("LoadedWrapperListener: invoking start main method"));
      }
      appMain(m_startMainArgs);
      if (WrapperManager.isDebugEnabled()) {
        System.out.println(
            Main.getRes().getString("LoadedWrapperListener: start main method completed"));
      }

      synchronized (this) {
        // Let the start() method know that the main method returned, in case it is
        //  still waiting.
        m_mainComplete = true;

        this.notifyAll();
      }

      return;
    } catch (Throwable e) {
      t = e;
    }

    // If we get here, then an error was thrown.  If this happened quickly
    // enough, the start method should be allowed to shut things down.
    System.out.println(Main.getRes().getString("Encountered an error running start main: {0}", t));
    t.printStackTrace();

    synchronized (this) {
      if (m_waitTimedOut) {
        // Shut down here.
        WrapperManager.stop(1);
        return; // Will not get here.
      } else {
        // Let start method handle shutdown.
        m_mainComplete = true;
        m_mainExitCode = new Integer(1);
        this.notifyAll();
        return;
      }
    }
  }
Example #2
0
 /** Create a new SHA-256 MessageDigest Either succeed or stop the node. */
 public static MessageDigest getMessageDigest() {
   try {
     MessageDigest md = null;
     synchronized (digests) {
       int x = digests.size();
       if (x == 0) md = null;
       else md = digests.remove(x - 1);
     }
     if (md == null) md = MessageDigest.getInstance("SHA-256", mdProvider);
     return md;
   } catch (NoSuchAlgorithmException e2) {
     // TODO: maybe we should point to a HOWTO for freejvms
     Logger.error(Node.class, "Check your JVM settings especially the JCE!" + e2);
     System.err.println("Check your JVM settings especially the JCE!" + e2);
     e2.printStackTrace();
   }
   WrapperManager.stop(NodeInitException.EXIT_CRAPPY_JVM);
   throw new RuntimeException();
 }
  /**
   * Called whenever the native wrapper code traps a system control signal against the Java process.
   * It is up to the callback to take any actions necessary. Possible values are:
   * WrapperManager.WRAPPER_CTRL_C_EVENT, WRAPPER_CTRL_CLOSE_EVENT, WRAPPER_CTRL_LOGOFF_EVENT, or
   * WRAPPER_CTRL_SHUTDOWN_EVENT
   *
   * @param event The system control signal.
   */
  public void controlEvent(int event) {
    if (WrapperManager.isControlledByNativeWrapper()) {
      if (WrapperManager.isDebugEnabled()) {
        System.out.println(
            Main.getRes()
                .getString("LoadedWrapperListener: controlEvent({0}) Ignored", new Integer(event)));
      }
      // Ignore the event as the native wrapper will handle it.
    } else {
      if (WrapperManager.isDebugEnabled()) {
        System.out.println(
            Main.getRes()
                .getString(
                    "LoadedWrapperListener: controlEvent({0}) Stopping", new Integer(event)));
      }

      // Not being run under a wrapper, so this isn't an NT service and should always exit.
      //  Handle the event here.
      WrapperManager.stop(0);
      // Will not get here.
    }
  }