コード例 #1
0
 @Override
 public boolean isInSafeMode(boolean useCache, String cluster) {
   if (useCache) {
     Long safeModeTimestamp = _safeModeMap.get(cluster);
     if (safeModeTimestamp == null) {
       return true;
     }
     return safeModeTimestamp < System.currentTimeMillis() ? false : true;
   }
   LOG.debug("trace isInSafeMode");
   try {
     String blurSafemodePath = ZookeeperPathConstants.getSafemodePath(cluster);
     Stat stat = _zk.exists(blurSafemodePath, false);
     if (stat == null) {
       return false;
     }
     byte[] data = _zk.getData(blurSafemodePath, false, stat);
     if (data == null) {
       return false;
     }
     long timestamp = Long.parseLong(new String(data));
     long waitTime = timestamp - System.currentTimeMillis();
     if (waitTime > 0) {
       return true;
     }
     return false;
   } catch (KeeperException e) {
     throw new RuntimeException(e);
   } catch (InterruptedException e) {
     throw new RuntimeException(e);
   }
 }
コード例 #2
0
 @Override
 public void action(List<String> clusters) {
   for (String cluster : clusters) {
     if (!tableWatchers.containsKey(cluster)) {
       WatchChildren clusterWatcher =
           new WatchChildren(_zk, ZookeeperPathConstants.getTablesPath(cluster))
               .watch(new Tables(cluster));
       tableWatchers.put(cluster, clusterWatcher);
       WatchNodeExistance watchNodeExistance =
           new WatchNodeExistance(_zk, ZookeeperPathConstants.getSafemodePath(cluster))
               .watch(new SafeExistance(cluster));
       safeModeWatchers.put(cluster, watchNodeExistance);
     }
   }
   List<String> clustersToCloseAndRemove = new ArrayList<String>(clusters);
   clustersToCloseAndRemove.removeAll(tableWatchers.keySet());
   for (String cluster : clustersToCloseAndRemove) {
     WatchChildren watcher = tableWatchers.remove(cluster);
     if (watcher == null) {
       LOG.error("Error watcher is null [" + cluster + "] ");
     } else {
       watcher.close();
     }
   }
 }
コード例 #3
0
 @Override
 public void action(Stat stat) {
   if (stat != null) {
     safeModeDataWatchers.put(
         cluster,
         new WatchNodeData(_zk, ZookeeperPathConstants.getSafemodePath(cluster))
             .watch(
                 new WatchNodeData.OnChange() {
                   @Override
                   public void action(byte[] data) {
                     if (data == null) {
                       _safeModeMap.put(cluster, null);
                     } else {
                       _safeModeMap.put(cluster, Long.parseLong(new String(data)));
                     }
                   }
                 }));
   }
 }