Esempio n. 1
0
  /**
   * This is called when JPM runs in the background to start jobs
   *
   * @throws Exception
   */
  public void daemon() throws Exception {
    Runtime.getRuntime()
        .addShutdownHook(
            new Thread("Daemon shutdown") {
              public void run() {

                for (Service service : startedByDaemon) {
                  try {
                    reporter.error("Stopping " + service);
                    service.stop();
                    reporter.error("Stopped " + service);
                  } catch (Exception e) {
                    // Ignore
                  }
                }
              }
            });
    List<ServiceData> services = getServices();
    Map<String, ServiceData> map = new HashMap<String, ServiceData>();
    for (ServiceData d : services) {
      map.put(d.name, d);
    }
    List<ServiceData> start = new ArrayList<ServiceData>();
    Set<ServiceData> set = new HashSet<ServiceData>();
    for (ServiceData sd : services) {
      checkStartup(map, start, sd, set);
    }

    if (start.isEmpty()) reporter.warning("No services to start");

    for (ServiceData sd : start) {
      try {
        Service service = getService(sd.name);
        reporter.trace("Starting " + service);
        String result = service.start();
        if (result != null) reporter.error("Started error " + result);
        else startedByDaemon.add(service);
        reporter.trace("Started " + service);
      } catch (Exception e) {
        reporter.error("Cannot start daemon %s, due to %s", sd.name, e);
      }
    }

    while (true) {
      for (Service sd : startedByDaemon) {
        try {
          if (!sd.isRunning()) {
            reporter.error("Starting due to failure " + sd);
            String result = sd.start();
            if (result != null) reporter.error("Started error " + result);
          }
        } catch (Exception e) {
          reporter.error("Cannot start daemon %s, due to %s", sd, e);
        }
      }
      Thread.sleep(10000);
    }
  }
Esempio n. 2
0
  @Override
  public void log(ServiceReference sr, int level, String message, Throwable exception) {
    switch (level) {
      case LogService.LOG_ERROR:
        reporter.error("%s:%s: %s", sr, exception, message);
        return;

      case LogService.LOG_WARNING:
        reporter.warning("%s:%s: %s", sr, exception, message);
        return;

      default:
        reporter.trace("%s:%s: %s", sr, exception, message);
        return;
    }
  }
Esempio n. 3
0
  @Override
  public void log(int level, String message) {
    if (level > this.level) return;

    switch (level) {
      case LogService.LOG_ERROR:
        reporter.error("%s", message);
        return;

      case LogService.LOG_WARNING:
        reporter.warning("%s", message);
        return;

      default:
        reporter.trace("%s", message);
        return;
    }
  }