コード例 #1
0
 private static final Client getClient(File indexDirectory) throws SearchLibException {
   clientsLock.r.lock();
   try {
     Client client = CLIENTS.get(indexDirectory);
     if (client != null) return client;
   } finally {
     clientsLock.r.unlock();
   }
   int i = 60;
   while (isOldClient(indexDirectory) && i > 0) {
     ThreadUtils.sleepMs(500);
     i--;
   }
   if (i == 0) throw new SearchLibException("Time out while getting " + indexDirectory);
   clientsLock.w.lock();
   try {
     Client client = CLIENTS.get(indexDirectory);
     if (client != null) return client;
     client =
         ClientFactory.INSTANCE.newClient(
             indexDirectory, true, false, ClientFactory.INSTANCE.properties.getSilentBackupUrl());
     CLIENTS.put(indexDirectory, client);
     return client;
   } finally {
     clientsLock.w.unlock();
   }
 }
コード例 #2
0
 public static void eraseIndex(User user, String indexName)
     throws SearchLibException, NamingException, IOException {
   if (user != null && !user.isAdmin()) throw new SearchLibException("Operation not permitted");
   File indexDir = getIndexDirectory(indexName);
   Client client = null;
   synchronized (ClientCatalog.class) {
     clientsLock.r.lock();
     try {
       client = CLIENTS.get(indexDir);
     } finally {
       clientsLock.r.unlock();
     }
     if (client != null) {
       client.close();
       client.delete();
     } else FileUtils.deleteDirectory(indexDir);
     if (client != null) {
       clientsLock.w.lock();
       try {
         CLIENTS.remove(client.getDirectory());
       } finally {
         clientsLock.w.unlock();
       }
       PushEvent.eventClientSwitch.publish(client);
     }
   }
 }
コード例 #3
0
 public static final void closeIndex(String indexName) throws SearchLibException {
   Client client = null;
   clientsLock.w.lock();
   try {
     File indexDirectory = getIndexDirectory(indexName);
     client = CLIENTS.get(indexDirectory);
     if (client == null) return;
     Logging.info("Closing client " + indexName);
     client.close();
     CLIENTS.remove(indexDirectory);
   } finally {
     clientsLock.w.unlock();
   }
   if (client != null) PushEvent.eventClientSwitch.publish(client);
 }
コード例 #4
0
 private static void unlockClientDir(File clientDir, Client newClient) {
   clientsLock.w.lock();
   try {
     if (newClient != null) CLIENTS.put(clientDir, newClient);
     OLD_CLIENTS.remove(clientDir);
   } finally {
     clientsLock.w.unlock();
   }
 }
コード例 #5
0
 private static void lockClientDir(File clientDir) {
   clientsLock.w.lock();
   try {
     CLIENTS.remove(clientDir);
     OLD_CLIENTS.add(clientDir);
   } finally {
     clientsLock.w.unlock();
   }
 }
コード例 #6
0
 public static final long countAllDocuments() throws IOException, SearchLibException {
   long count = 0;
   clientsLock.r.lock();
   try {
     for (Client client : CLIENTS.values()) {
       if (client.isTrueReplicate()) continue;
       count += client.getStatistics().getNumDocs();
     }
   } finally {
     clientsLock.r.unlock();
   }
   return count;
 }
コード例 #7
0
 public static final void closeAll() {
   synchronized (ClientCatalog.class) {
     clientsLock.r.lock();
     try {
       for (Client client : CLIENTS.values()) {
         if (client == null) continue;
         Logging.info("OSS unloads index " + client.getIndexName());
         client.close();
       }
     } finally {
       clientsLock.r.unlock();
     }
     rendererResults.release();
   }
 }
コード例 #8
0
 private static List<Client> findDepends(String indexName) {
   clientsLock.r.lock();
   try {
     ArrayList<Client> list = new ArrayList<Client>();
     for (Client client : CLIENTS.values()) {
       IndexConfig indexConfig = client.getIndex().getIndexConfig();
       if (indexConfig.isMulti())
         if (indexConfig.isIndexMulti(indexName)) {
           list.add(client);
         }
     }
     return list;
   } finally {
     clientsLock.r.unlock();
   }
 }