private void monitorDnsChange(final SingleServerConfig cfg) {
    monitorFuture =
        GlobalEventExecutor.INSTANCE.scheduleWithFixedDelay(
            new Runnable() {
              @Override
              public void run() {
                try {
                  InetAddress master = currentMaster.get();
                  InetAddress now = InetAddress.getByName(cfg.getAddress().getHost());
                  if (!now.getHostAddress().equals(master.getHostAddress())) {
                    log.info(
                        "Detected DNS change. {} has changed from {} to {}",
                        cfg.getAddress().getHost(),
                        master.getHostAddress(),
                        now.getHostAddress());
                    if (currentMaster.compareAndSet(master, now)) {
                      changeMaster(
                          MAX_SLOT, cfg.getAddress().getHost(), cfg.getAddress().getPort());
                      log.info("Master has been changed");
                    }
                  }

                } catch (Exception e) {
                  log.error(e.getMessage(), e);
                }
              }
            },
            cfg.getDnsMonitoringInterval(),
            cfg.getDnsMonitoringInterval(),
            TimeUnit.MILLISECONDS);
  }
  private void scheduleClusterChangeCheck(final ClusterServersConfig cfg) {
    monitorFuture =
        GlobalEventExecutor.INSTANCE.schedule(
            new Runnable() {
              @Override
              public void run() {
                List<URI> nodes = new ArrayList<URI>();
                List<URI> slaves = new ArrayList<URI>();
                AtomicReference<Throwable> lastException = new AtomicReference<Throwable>();
                for (ClusterPartition partition : lastPartitions.values()) {
                  if (!partition.isMasterFail()) {
                    nodes.add(partition.getMasterAddress());
                  }

                  Set<URI> partitionSlaves = new HashSet<URI>(partition.getSlaveAddresses());
                  partitionSlaves.removeAll(partition.getFailedSlaveAddresses());
                  slaves.addAll(partitionSlaves);
                }
                // master nodes first
                nodes.addAll(slaves);

                checkClusterState(cfg, nodes.iterator(), lastException);
              }
            },
            cfg.getScanInterval(),
            TimeUnit.MILLISECONDS);
  }
 public Future<Boolean> addAsync(final V value) {
   final Promise<Boolean> promise = new DefaultPromise<Boolean>() {};
   GlobalEventExecutor.INSTANCE.execute(
       new Runnable() {
         @Override
         public void run() {
           try {
             boolean res = add(value);
             promise.setSuccess(res);
           } catch (Exception e) {
             promise.setFailure(e);
           }
         }
       });
   return promise;
 }