Example #1
0
  private boolean deployHandler(
      TransitModel model, String command, String path, String[] args, boolean waitFor) {
    Logger logger = getLogger();
    if (logger.isDebugEnabled()) {
      logger.debug("date: " + new Date());
      logger.debug("system: " + command);
      logger.debug("uri: " + path);
      logger.debug("args: [" + toString(args) + "]");
      logger.debug(
          "system classloader: ["
              + System.identityHashCode(ClassLoader.getSystemClassLoader())
              + "]");
    }
    Logger log = resolveLogger(logger, command);
    try {
      URI uri = new URI(path);
      Transit transit = Transit.getInstance(model);
      setupMonitors(transit, (Adapter) logger);

      Part part = Part.load(uri, true);
      m_plugin = part.instantiate(new Object[] {model, args, log});
    } catch (GeneralException e) {
      getLogger().error(e.getMessage());
      System.exit(1);
    } catch (Exception e) {
      Throwable cause = e.getCause();
      if ((null != cause) && (cause instanceof GeneralException)) {
        getLogger().error(cause.getMessage());
        System.exit(1);
      } else {
        getLogger().error(e.getMessage(), e.getCause());
        System.exit(1);
      }
    } catch (Throwable e) {
      final String error = "Deloyment failure." + "\nTarget: " + command + "\n   URI: " + path;
      getLogger().error(error, e);
      System.exit(1);
    }

    if (m_plugin instanceof Runnable) {
      getLogger().debug("starting " + m_plugin.getClass().getName());
      Thread thread = new Thread((Runnable) m_plugin);
      thread.start();
      setShutdownHook(thread);
      return true;
    } else {
      getLogger().debug("deployed " + m_plugin.getClass().getName());
      return waitFor;
    }
  }