コード例 #1
0
ファイル: Bootstrap.java プロジェクト: treejames/D3
  public void lanucher() {
    Set<Service> services = Sets.newLinkedHashSet();
    /** 节点管理服务 */
    GatewayServerStartService tcpService =
        (GatewayServerStartService) D3Context.getBean("gatewayServerStartService");
    services.add(tcpService);

    serviceManager = new ServiceManager(services);
    serviceManager.addListener(
        new Listener() {

          @Override
          public void failure(Service service) {}

          @Override
          public void healthy() {
            System.out.println("all service has been started");
          }

          @Override
          public void stopped() {}
        },
        MoreExecutors.sameThreadExecutor());
    serviceManager.startAsync();
  }
コード例 #2
0
  @Override
  protected void startCommand() {
    LOG.info(
        "Graylog " + commandName + " {} starting up. (JRE: {})",
        version,
        Tools.getSystemInformation());

    // Do not use a PID file if the user requested not to
    if (!isNoPidFile()) {
      savePidFile(getPidFile());
    }

    final ServerStatus serverStatus = injector.getInstance(ServerStatus.class);
    serverStatus.initialize();

    startNodeRegistration(injector);

    final ActivityWriter activityWriter;
    final ServiceManager serviceManager;
    try {
      activityWriter = injector.getInstance(ActivityWriter.class);
      serviceManager = injector.getInstance(ServiceManager.class);
    } catch (ProvisionException e) {
      LOG.error("Guice error", e);
      annotateProvisionException(e);
      System.exit(-1);
      return;
    } catch (Exception e) {
      LOG.error("Unexpected exception", e);
      System.exit(-1);
      return;
    }

    Runtime.getRuntime().addShutdownHook(new Thread(injector.getInstance(shutdownHook())));

    // propagate default size to input plugins
    MessageInput.setDefaultRecvBufferSize(configuration.getUdpRecvBufferSizes());

    // Start services.
    final ServiceManagerListener serviceManagerListener =
        injector.getInstance(ServiceManagerListener.class);
    serviceManager.addListener(serviceManagerListener);
    try {
      serviceManager.startAsync().awaitHealthy();
    } catch (Exception e) {
      try {
        serviceManager
            .stopAsync()
            .awaitStopped(configuration.getShutdownTimeout(), TimeUnit.MILLISECONDS);
      } catch (TimeoutException timeoutException) {
        LOG.error("Unable to shutdown properly on time. {}", serviceManager.servicesByState());
      }
      LOG.error("Graylog startup failed. Exiting. Exception was:", e);
      System.exit(-1);
    }
    LOG.info("Services started, startup times in ms: {}", serviceManager.startupTimes());

    activityWriter.write(new Activity("Started up.", Main.class));
    LOG.info("Graylog " + commandName + " up and running.");

    // Block forever.
    try {
      Thread.currentThread().join();
    } catch (InterruptedException e) {
      return;
    }
  }