コード例 #1
0
 public static void check() {
   for (String ctx : PersistenceContexts.list()) {
     try {
       DatabaseClusterMBean db = lookup(ctx, TimeUnit.SECONDS.toMillis(5));
       for (String host : db.getactiveDatabases()) {
         Host hostEntry = Hosts.lookup(host);
         if (hostEntry == null) {
           disable(host);
         } else if (!Hosts.contains(hostEntry.getGroupsId())) {
           Hosts.remove(host); // GRZE: this will clean up group state and de-activate db.
         }
       }
     } catch (NoSuchElementException ex) {
       LOG.error(ex, ex);
     }
     return;
   }
 }
コード例 #2
0
 static boolean enable(final Host host) {
   if (!host.hasDatabase() || Bootstrap.isShuttingDown()) {
     return false;
   } else if (!Hosts.contains(host.getGroupsId())) {
     Hosts.remove(host.getGroupsId());
     return false;
   } else {
     if (host.isLocalHost()) {
       if (SyncState.SYNCING.set()) {
         try {
           runDbStateChange(ActivateHostFunction.INSTANCE.apply(host));
           SyncState.SYNCED.set();
           return true;
         } catch (LockTimeoutException ex) {
           SyncState.NOTSYNCED.set();
           return false;
         } catch (Exception ex) {
           SyncState.NOTSYNCED.set();
           LOG.error(ex);
           Logs.extreme().error(ex, ex);
           return false;
         }
       } else if (!SyncState.SYNCING.isCurrent()) {
         try {
           runDbStateChange(ActivateHostFunction.INSTANCE.apply(host));
           return true;
         } catch (LockTimeoutException ex) {
           return false;
         } catch (Exception ex) {
           LOG.error(ex);
           Logs.extreme().error(ex, ex);
           return false;
         }
       } else {
         try {
           runDbStateChange(ActivateHostFunction.INSTANCE.apply(host));
           SyncState.SYNCED.set();
           return true;
         } catch (LockTimeoutException ex) {
           SyncState.NOTSYNCED.set();
           return false;
         } catch (Exception ex) {
           SyncState.NOTSYNCED.set();
           LOG.error(ex, ex);
           return false;
         }
       }
     } else if (!ActiveHostSet.ACTIVATED.get().contains(host.getDisplayName())) {
       try {
         runDbStateChange(ActivateHostFunction.INSTANCE.apply(host));
         return true;
       } catch (LockTimeoutException ex) {
         return false;
       } catch (Exception ex) {
         Logs.extreme().debug(ex);
         ActivateHostFunction.rollback(host, ex);
         return false;
       }
     } else {
       return ActiveHostSet.ACTIVATED.get().contains(host.getDisplayName());
     }
   }
 }