예제 #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 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);
 }
예제 #3
0
 public static void receive_switch(WebApp webapp, Client client)
     throws SearchLibException, NamingException, IOException {
   File trashDir = getTrashReceiveDir(client);
   File clientDir = client.getDirectory();
   if (trashDir.exists()) FileUtils.deleteDirectory(trashDir);
   Client newClient = null;
   List<Client> clientDepends = findDepends(client.getIndexName());
   lockClientDir(clientDir);
   try {
     lockClients(clientDepends);
     closeClients(clientDepends);
     try {
       client.trash(trashDir);
       getTempReceiveDir(client).renameTo(clientDir);
       File pathToMoveFile = new File(clientDir, PATH_TO_MOVE);
       if (pathToMoveFile.exists()) {
         for (String pathToMove : FileUtils.readLines(pathToMoveFile)) {
           File from = new File(trashDir, pathToMove);
           File to = new File(clientDir, pathToMove);
           FileUtils.moveFile(from, to);
         }
         if (!pathToMoveFile.delete())
           throw new IOException("Unable to delete the file: " + pathToMoveFile.getAbsolutePath());
       }
       newClient =
           ClientFactory.INSTANCE.newClient(
               clientDir, true, true, ClientFactory.INSTANCE.properties.getSilentBackupUrl());
       newClient.writeReplCheck();
     } finally {
       unlockClients(clientDepends);
     }
   } finally {
     unlockClientDir(clientDir, newClient);
   }
   PushEvent.eventClientSwitch.publish(client);
   FileUtils.deleteDirectory(trashDir);
 }