示例#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
 private static Set<String> listDatabases(
     final String clusterName, final boolean active, final Optional<Integer> weight) {
   final Set<String> databases = Sets.newLinkedHashSet();
   try {
     final DatabaseClusterMBean cluster = lookup(clusterName, 0);
     final Iterable<String> databaseIds =
         active ? cluster.getactiveDatabases() : cluster.getinactiveDatabases();
     for (final String databaseId : databaseIds)
       try {
         final DriverDatabaseMBean database = lookupDatabase(clusterName, databaseId);
         if (!weight.isPresent() || database.getweight() == weight.get()) {
           databases.add(databaseId);
         }
       } catch (NoSuchElementException e) {
         // ignore database
       }
   } catch (NoSuchElementException e) {
     // no databases
   } catch (Exception e) {
     LOG.error(e, e);
   }
   return databases;
 }