@Override
  protected void startNodeRegistration(Injector injector) {
    // Register this node.
    final NodeService nodeService = injector.getInstance(NodeService.class);
    final ServerStatus serverStatus = injector.getInstance(ServerStatus.class);
    final ActivityWriter activityWriter = injector.getInstance(ActivityWriter.class);
    nodeService.registerServer(
        serverStatus.getNodeId().toString(),
        configuration.isMaster(),
        configuration.getRestTransportUri());
    serverStatus.setLocalMode(isLocal());
    if (configuration.isMaster() && !nodeService.isOnlyMaster(serverStatus.getNodeId())) {
      LOG.warn(
          "Detected another master in the cluster. Retrying in {} seconds to make sure it is not "
              + "an old stale instance.",
          TimeUnit.MILLISECONDS.toSeconds(configuration.getStaleMasterTimeout()));
      try {
        Thread.sleep(configuration.getStaleMasterTimeout());
      } catch (InterruptedException e) {
        /* nope */
      }

      if (!nodeService.isOnlyMaster(serverStatus.getNodeId())) {
        // All devils here.
        String what =
            "Detected other master node in the cluster! Starting as non-master! "
                + "This is a mis-configuration you should fix.";
        LOG.warn(what);
        activityWriter.write(new Activity(what, Server.class));

        // Write a notification.
        final NotificationService notificationService =
            injector.getInstance(NotificationService.class);
        Notification notification =
            notificationService
                .buildNow()
                .addType(Notification.Type.MULTI_MASTER)
                .addSeverity(Notification.Severity.URGENT);
        notificationService.publishIfFirst(notification);

        configuration.setIsMaster(false);
      } else {
        LOG.warn("Stale master has gone. Starting as master.");
      }
    }
  }
 @Inject
 public NodeServiceImpl(final MongoConnection mongoConnection, final Configuration configuration) {
   super(mongoConnection);
   this.pingTimeout = TimeUnit.MILLISECONDS.toSeconds(configuration.getStaleMasterTimeout());
 }