예제 #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);
 }