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(); } }
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); }
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(); } }
private static void lockClientDir(File clientDir) { clientsLock.w.lock(); try { CLIENTS.remove(clientDir); OLD_CLIENTS.add(clientDir); } finally { clientsLock.w.unlock(); } }
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; }
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(); } }
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(); } }