Esempio n. 1
0
 /** Stop all the services we provide. This is the opposite of {@link #daemonStart}. */
 void daemonStop(long time, TimeUnit unit) {
   shutdownSemaphore.release();
   try {
     synchronized (this) {
       if (primaryServer == null) {
         return; // Already stopped.
       }
       config.removeConfigModificationListener(configModListener);
       gsa.stop(time, unit);
       try {
         gsa.getAdaptor().destroy();
       } finally {
         gsa.teardown();
       }
     }
   } finally {
     boolean interrupted = false;
     while (true) {
       try {
         shutdownSemaphore.acquire();
         break;
       } catch (InterruptedException ex) {
         interrupted = true;
       }
     }
     if (interrupted) {
       Thread.currentThread().interrupt();
     }
   }
 }
Esempio n. 2
0
  private synchronized void realDaemonStart() throws IOException, InterruptedException {
    AdaptorContext context = gsa.setup(primaryServer, dashboardServer, null);

    long sleepDurationMillis = 8000;
    // An hour.
    long maxSleepDurationMillis = 60 * 60 * 1000;
    // Loop until 1) the adaptor starts successfully, 2) an unrecoverable
    // StartupException is thrown, 3) stop() is called, or 4) Thread.interrupt()
    // is called on this thread (which we don't do).
    // Retrying to start the adaptor is helpful in cases where it needs
    // initialization data from a repository that is temporarily down; if the
    // adaptor is running as a service, we don't want to stop starting simply
    // because another computer is down while we start (which would easily be
    // the case after a power failure).
    while (true) {
      try {
        gsa.tryToPutVersionIntoConfig();
        String adaptorType = gsa.getAdaptor().getClass().getName();
        log.log(Level.INFO, "about to init {0}", adaptorType);
        gsa.getAdaptor().init(context);
        break;
      } catch (InterruptedException ex) {
        throw ex;
      } catch (StartupException ex) {
        throw ex;
      } catch (Exception ex) {
        log.log(Level.WARNING, "Failed to initialize adaptor", ex);
        if (shutdownSemaphore.tryAcquire(sleepDurationMillis, TimeUnit.MILLISECONDS)) {
          shutdownSemaphore.release();
          // Shutdown initiated.
          return;
        }
        sleepDurationMillis = Math.min(sleepDurationMillis * 2, maxSleepDurationMillis);
        gsa.ensureLatestConfigLoaded();
      }
    }

    config.addConfigModificationListener(configModListener);
    gsa.start(new ShutdownHook());
  }