Exemplo n.º 1
1
  /**
   * Start this server. If we manage an own HttpServer, then the HttpServer will be started as well.
   */
  public void start() {
    // URL as configured takes precedence
    String configUrl =
        NetworkUtil.replaceExpression(config.getJolokiaConfig().get(ConfigKey.DISCOVERY_AGENT_URL));
    jolokiaHttpHandler.start(
        lazy, configUrl != null ? configUrl : url, config.getAuthenticator() != null);

    if (httpServer != null) {
      // Starting our own server in an own thread group with a fixed name
      // so that the cleanup thread can recognize it.
      ThreadGroup threadGroup = new ThreadGroup("jolokia");
      threadGroup.setDaemon(false);

      Thread starterThread =
          new Thread(
              threadGroup,
              new Runnable() {
                @Override
                public void run() {
                  httpServer.start();
                }
              });
      starterThread.start();
      cleaner = new CleanupThread(httpServer, threadGroup);
      cleaner.start();
    }
  }
Exemplo n.º 2
0
  /**
   * Initialize this JolokiaServer with the given HttpServer. The calle is responsible for managing
   * (starting/stopping) the HttpServer.
   *
   * @param pServer server to use
   * @param pConfig configuration
   * @param pLazy whether the initialization should be done lazy or not
   */
  protected final void init(HttpServer pServer, JolokiaServerConfig pConfig, boolean pLazy) {
    config = pConfig;
    lazy = pLazy;

    // Create proper context along with handler
    final String contextPath = pConfig.getContextPath();
    jolokiaHttpHandler = new JolokiaHttpHandler(pConfig.getJolokiaConfig());
    HttpContext context = pServer.createContext(contextPath, jolokiaHttpHandler);

    // Add authentication if configured
    final Authenticator authenticator = pConfig.getAuthenticator();
    if (authenticator != null) {
      context.setAuthenticator(authenticator);
    }

    url = detectAgentUrl(pServer, pConfig, contextPath);
  }