コード例 #1
0
  public void initializeRegistry(IProcess process) {
    fProcess = process;
    processListener =
        new IDebugEventSetListener() {
          /** @see org.eclipse.debug.core.IDebugEventSetListener#handleDebugEvents(DebugEvent[]) */
          public void handleDebugEvents(DebugEvent[] events) {
            for (int i = 0; i < events.length; i++) {
              DebugEvent e = events[i];
              if (e.getSource() == fProcess && e.getKind() == DebugEvent.TERMINATE) {
                // We terminating too soon. Pop up a msg.
                IStreamsProxy stProxy = fProcess.getStreamsProxy();
                java.io.StringWriter s = new java.io.StringWriter();
                java.io.PrintWriter w = new java.io.PrintWriter(s);

                String msg =
                    MessageFormat.format(
                        ProxyRemoteMessages.Proxy_Terminated_too_soon_ERROR_, new Object[] {fName});
                w.println(msg);
                w.println(ProxyRemoteMessages.VM_TERMINATED_INFO_);
                w.println(ProxyRemoteMessages.VM_COMMAND_LINE);
                w.println(fProcess.getAttribute(IProcess.ATTR_CMDLINE));
                w.println(ProxyRemoteMessages.VM_TERMINATED_LINE1);
                w.println(stProxy.getErrorStreamMonitor().getContents());
                w.println(ProxyRemoteMessages.VM_TERMINATED_LINE2);
                w.println(stProxy.getOutputStreamMonitor().getContents());
                w.println(ProxyRemoteMessages.VM_TERMINATED_LINE3);
                w.close();

                DebugModeHelper dh = new DebugModeHelper();
                dh.displayErrorMessage(ProxyRemoteMessages.Proxy_Error_Title, msg);
                ProxyPlugin.getPlugin()
                    .getLogger()
                    .log(
                        new Status(
                            IStatus.WARNING,
                            ProxyPlugin.getPlugin().getBundle().getSymbolicName(),
                            0,
                            s.toString(),
                            null));
                processListener = null;
                DebugPlugin.getDefault().removeDebugEventListener(this);
                terminateRegistry();
                break;
              }
            }
          }
        };

    DebugPlugin.getDefault().addDebugEventListener(processListener);
  }
コード例 #2
0
  protected void registryTerminated(boolean wait) {
    if (processListener != null) {
      // Remove listener cause we are now going to terminate process and don't want premature
      // terminate notice.
      // Sometimes in shutdown we are called and the debug plugin may of already been shutdown. In
      // that case the db
      // will be null and there is nothing remove listener from.
      DebugPlugin db = DebugPlugin.getDefault();
      if (db != null) db.removeDebugEventListener(processListener);
      processListener = null;
    }

    Job tjob = null;
    if (waitRegistrationThread != null) {
      synchronized (waitRegistrationThread) {
        // Still waiting. close it out.
        WaitForRegistrationThread wThread = waitRegistrationThread;
        waitRegistrationThread = null;
        wThread.notifyAll();
      }
    }
    if (fServerPort != 0) {
      IREMConnection closeCon = null; // The connection we will use to close the remote vm.
      synchronized (fConnectionPool) {
        // Now we walk through all of the free connections and close them properly.
        Iterator itr = fConnectionPool.iterator();
        if (itr.hasNext()) closeCon = (IREMConnection) itr.next();
        while (itr.hasNext()) {
          IREMConnection con = (IREMConnection) itr.next();
          con.close();
        }
      }

      // Now we terminate the server.
      if (closeCon == null)
        try {
          closeCon =
              getFreeConnection(); // There weren't any free connections, so get a new one so that
                                   // we can close it.
        } catch (IllegalStateException e) {
          // Do nothing, don't want to stop termination just because we can't get a connection.
        }
      if (closeCon != null) {
        closeCon
            .terminateServer(); // We got a connection to terminate (process may of terminated
                                // early, so we would not have a conn then).
      }
      fConnectionPool.clear();
      fServerPort = 0;

      if (fProcess != null && !fRegistryController.inShutDown()) {
        tjob = new TerminateProcess(fProcess);
        tjob.setSystem(true);
        tjob.schedule();
        fProcess = null;
      }
    }

    if (fCallbackServer != null) {
      fCallbackServer.requestShutdown();
      fCallbackServer = null;
    }

    fConnectionPool.clear();
    fRegistryController.deregisterRegistry(fRegistryKey); // De-register this registry.

    if (wait && tjob != null) {
      try {
        tjob.join();
      } catch (InterruptedException e) {
        // It timed out, so we'll just go on.
      }
    }
  }