public synchronized void shutdown() {
    if (state != State.STARTED) {
      throw new IllegalStateException("Cannot shutdown manager in state: " + state);
    }
    state = State.SHUTTING_DOWN;

    counter = 0;

    if (driver != null) {
      aeron.close();

      TimedScheduler timer = Schedulers.timer();

      timer.schedule(new RetryShutdownTask(timer), retryShutdownMillis, TimeUnit.MILLISECONDS);
    }
  }
 @Override
 public void run() {
   if (canShutdownMediaDriver() || System.nanoTime() - startNs > shutdownTimeoutNs) {
     doShutdown();
   } else {
     timer.schedule(this, retryShutdownMillis, TimeUnit.MILLISECONDS);
   }
 }