/**
   * Initialize log level overrides from debug options.
   *
   * <p>This may only be called during bootstrapping before any custom overrides are set. Your
   * milage may vary if called while the application is running.
   *
   * @throws Exception
   */
  void initializeLogLevelOverrides() throws Exception {
    // reset current overrides
    overriddenLogLevels.clear();

    // add a note to the status manager
    final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    final StatusManager sm = lc.getStatusManager();
    if (sm != null) {
      sm.add(new InfoStatus("Initializing log level overrides.", this));
    }

    // apply new overrides
    try {
      final Map<String, String> options =
          BootActivator.getInstance().getService(DebugOptions.class).getOptions();
      for (final Entry<String, String> e : options.entrySet()) {
        final String loggerName = getLoggerNameForDebugOption(e.getKey());
        if (loggerName != null) {
          if ((null != e.getValue()) && !"false".equalsIgnoreCase(e.getValue())) {
            setLogLevelOverride(loggerName, "DEBUG");
          }
        }
      }
    } catch (final ServiceNotAvailableException e) {
      // no debug options available (ignore)
    }
  }
예제 #2
0
  static synchronized void doStart() throws Exception {
    if (state != Status.STARTING) return;

    // do not start if running in production mode and not explicitly set
    final EnvironmentInfo info = BootActivator.getEnvironmentInfo();
    if (info.getProperty("gyrex.jmxrmi.skip") != null) return;

    // use defaults from
    // http://wiki.eclipse.org/Jetty/Tutorial/JMX#Enabling_JMXConnectorServer_for_Remote_Access
    String host = "localhost";
    int port = Platform.getInstancePort(1099);

    // allow port and host override through arguments
    if (info.getProperty(PROPERTY_PORT) != null) {
      try {
        port = Integer.parseInt(info.getProperty(PROPERTY_PORT));
      } catch (final Exception e) {
        throw new IllegalArgumentException(
            String.format("Invalid JMX port (%s).", info.getProperty(PROPERTY_PORT)), e);
      }
    }
    if (info.getProperty(PROPERTY_HOST) != null) {
      host = info.getProperty(PROPERTY_HOST);
    }

    // TODO: may want to support protected access using <instance-location>/etc/jmx/... files

    LOG.info("Enabling JMX remote connections on port {} (host {}).", new Object[] {port, host});

    final JMXServiceURL url =
        new JMXServiceURL("rmi", host, port, String.format("/jndi/rmi://%s:%d/jmxrmi", host, port));
    connectorServer =
        new ConnectorServer(url, null, "org.eclipse.gyrex.jmx:name=rmiconnectorserver");
    connectorServer.start();

    state = Status.STARTED;
  }