Package com.google.dataconnector.util

Examples of com.google.dataconnector.util.ShutdownManager


        this.frameReceiver = new FrameReceiver();
        this.frameReceiver.setInputStream(getInputStream());
        this.calls = new ConcurrentHashMap<String, SdcClientCall>();

        BlockingQueue<FrameInfo> sendQueue = new LinkedBlockingQueue<SdcFrame.FrameInfo>();
        ShutdownManager shutdownManager = new ShutdownManager();
        this.frameSender = new FrameSender(sendQueue, shutdownManager);
        this.frameSender.setOutputStream(getOutputStream());
    }
View Full Code Here


  public static void main(final String[] args) {
    // Bootstrap logging system
    PropertyConfigurator.configure(getBootstrapLoggingProperties());

    final Injector injector = ClientGuiceModule.getInjector();
    final ShutdownManager shutdownManager = injector.getInstance(ShutdownManager.class);
    // Add shutdown hook to call shutdown if control c or OS SIGTERM is received.
    Runtime.getRuntime().addShutdownHook(new Thread() {
      @Override
      public void run() {
        shutdownManager.shutdownAll();
      }
    });

    // Starts the client in a loop that exponentially backs off.
    while (true) {
      try {
        // Only try to back-off if we have unsuccessful connections.
        if (unsuccessfulAttempts > 0) {
          long backOffTime = (long) Math.min(
              MAX_BACKOFF_TIME, Math.pow(2, unsuccessfulAttempts) * 1000L);
          try {
            // Sleep for the amount of time needed.
            Thread.sleep(backOffTime);
          } catch (InterruptedException e) {
            LOG.error("Interrupted while trying to exponentially back off. Exiting.");
            break;
          }
          LOG.info("Starting agent after " + unsuccessfulAttempts + " unsuccessful attempts." +
              " Next connect in " + backOffTime + " milliseconds.");
        } else if (unsuccessfulAttempts == -1) {
          // We are being told to quit probably because we were only configured to start once.
          break;
        }
        injector.getInstance(Client.class).parseFlagsValidateAndConnect(args);
      } catch (Exception e) { // This is an outside server loop. Catch everything.
        LOG.error("Agent died.", e);
        shutdownManager.shutdownAll();
      }
    }
  }
View Full Code Here

TOP

Related Classes of com.google.dataconnector.util.ShutdownManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.