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);
     }
   }
 }
 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);
 }
 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();
   }
 }
 public static void receive_merge(WebApp webapp, Client client)
     throws SearchLibException, IOException {
   File tempDir = getTempReceiveDir(client);
   File clientDir = client.getDirectory();
   Client newClient = null;
   lockClientDir(clientDir);
   try {
     client.close();
     new ReplicationMerge(tempDir, clientDir);
     newClient =
         ClientFactory.INSTANCE.newClient(
             clientDir, true, true, ClientFactory.INSTANCE.properties.getSilentBackupUrl());
     newClient.writeReplCheck();
   } finally {
     unlockClientDir(clientDir, newClient);
   }
   PushEvent.eventClientSwitch.publish(client);
   FileUtils.deleteDirectory(tempDir);
 }
 private static void closeClients(List<Client> clients) {
   if (clients == null) return;
   for (Client client : clients) client.close();
 }