/** Wait for the server to die. */
  private void waitForDeath() throws CommandException {
    if (!programOpts.isTerse()) {
      // use stdout because logger always appends a newline
      System.out.print(Strings.get("StopInstance.waitForDeath") + " ");
    }
    long startWait = System.currentTimeMillis();
    boolean alive = true;
    int count = 0;

    while (!timedOut(startWait)) {
      if (!isRunning()) {
        alive = false;
        break;
      }
      try {
        Thread.sleep(100);
        if (!programOpts.isTerse() && count++ % 10 == 0) System.out.print(".");
      } catch (InterruptedException ex) {
        // don't care
      }
    }

    if (!programOpts.isTerse()) System.out.println();

    if (alive) {
      throw new CommandException(
          Strings.get("StopInstance.instanceNotDead", (CLIConstants.DEATH_TIMEOUT_MS / 1000)));
    }
  }
Esempio n. 2
0
 @Override
 public void execute(AdminCommandContext context) {
   Target targetUtil = habitat.getComponent(Target.class);
   Config newConfig = targetUtil.getConfig(target);
   if (newConfig != null) {
     config = newConfig;
   }
   report = context.getActionReport();
   try {
     final Protocols protocols = config.getNetworkConfig().getProtocols();
     final Protocol protocol = protocols.findProtocol(protocolName);
     validate(
         protocol,
         "create.http.fail.protocolnotfound",
         "The specified protocol {0} is not yet configured",
         protocolName);
     final Class<?> filterClass =
         Thread.currentThread().getContextClassLoader().loadClass(classname);
     if (!com.sun.grizzly.ProtocolFilter.class.isAssignableFrom(filterClass)) {
       report.setMessage(
           localStrings.getLocalString(
               "create.portunif.fail.notfilter",
               "{0} create failed.  Given class is not a ProtocolFilter: {1}",
               name,
               classname));
       report.setActionExitCode(ActionReport.ExitCode.FAILURE);
       return;
     }
     ProtocolChainInstanceHandler handler = getHandler(protocol);
     ProtocolChain chain = getChain(handler);
     ConfigSupport.apply(
         new SingleConfigCode<ProtocolChain>() {
           @Override
           public Object run(ProtocolChain param)
               throws PropertyVetoException, TransactionFailure {
             final List<ProtocolFilter> list = param.getProtocolFilter();
             for (ProtocolFilter filter : list) {
               if (name.equals(filter.getName())) {
                 throw new TransactionFailure(
                     String.format("A protocol filter named %s already exists.", name));
               }
             }
             final ProtocolFilter filter = param.createChild(ProtocolFilter.class);
             filter.setName(name);
             filter.setClassname(classname);
             list.add(filter);
             return null;
           }
         },
         chain);
   } catch (ValidationFailureException e) {
     return;
   } catch (Exception e) {
     e.printStackTrace();
     report.setMessage(
         localStrings.getLocalString(
             "create.portunif.fail",
             "{0} create failed: {1}",
             name,
             e.getMessage() == null ? "No reason given" : e.getMessage()));
     report.setActionExitCode(ActionReport.ExitCode.FAILURE);
     report.setFailureCause(e);
     return;
   }
 }