/**
  * Handle notification of the creation of a new classloader.
  *
  * @param logger the logging channel
  * @param label the classloader label
  * @param category the classloader category
  * @param classloader the new classloader to report
  */
 private static void classloaderConstructed(
     Logger logger, String label, Category category, ClassLoader classloader) {
   if (logger.isTraceEnabled()) {
     int id = System.identityHashCode(classloader);
     StringBuffer buffer = new StringBuffer();
     buffer.append("new ");
     buffer.append(category.toString());
     buffer.append(" classloader for " + label);
     buffer.append("\n           id: " + id);
     ClassLoader parent = classloader.getParent();
     if (null != parent) {
       int pid = System.identityHashCode(parent);
       buffer.append("\n      extends: " + pid);
     }
     if (classloader instanceof URLClassLoader) {
       URLClassLoader loader = (URLClassLoader) classloader;
       URL[] urls = loader.getURLs();
       if (urls.length == 1) {
         buffer.append("\n     contains: 1 entry");
       } else {
         buffer.append("\n     contains: " + urls.length + " entries");
       }
       for (int i = 0; i < urls.length; i++) {
         URL url = urls[i];
         buffer.append("\n         [" + (i + 1) + "] " + url.toString());
       }
     }
     logger.trace(buffer.toString());
   }
 }
Example #2
0
 private Logger resolveLogger(Logger logger, String command) {
   String partition = System.getProperty("dpml.station.partition", null);
   if (null != partition) {
     return new LoggingAdapter(partition);
   } else {
     return logger.getChildLogger(command);
   }
 }
Example #3
0
 /** Run the dispatch thread. */
 public void run() {
   try {
     m_listener.applianceChanged(m_event);
   } catch (Throwable e) {
     final String error = "Event distatch error.";
     m_logger.error(error, e);
   }
 }
Example #4
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;
    }
  }