Exemple #1
0
  protected void createDirs(File target) throws FMFileManagerException {

    if (clone) {

      return;
    }

    deleteDirs();

    File parent = target.getParentFile();

    if (!parent.exists()) {

      List new_dirs = new ArrayList();

      File current = parent;

      while (current != null && !current.exists()) {

        new_dirs.add(current);

        current = current.getParentFile();
      }

      created_dirs_leaf = target;
      created_dirs = new ArrayList();

      if (FileUtil.mkdirs(parent)) {

        created_dirs = new_dirs;

        /*
        for (int i=created_dirs.size()-1;i>=0;i--){

        	System.out.println( "created " + created_dirs.get(i));
        }
        */
      } else {
        // had some reports of this exception being thrown when starting a torrent
        // double check in case there's some parallel creation being triggered somehow

        try {
          Thread.sleep(RandomUtils.nextInt(1000));

        } catch (Throwable e) {
        }

        FileUtil.mkdirs(parent);

        if (parent.isDirectory()) {

          created_dirs = new_dirs;

        } else {

          throw (new FMFileManagerException("Failed to create parent directory '" + parent + "'"));
        }
      }
    }
  }
 protected void accept_loop() {
   while (isRunning()) {
     try {
       SocketChannel client_channel = server_channel.accept();
       last_accept_time = SystemTime.getCurrentTime();
       client_channel.configureBlocking(false);
       listener.newConnectionAccepted(server_channel, client_channel);
     } catch (AsynchronousCloseException e) {
       /* is thrown when stop() is called */
     } catch (Throwable t) {
       Debug.out(t);
       try {
         Thread.sleep(500);
       } catch (Exception e) {
         e.printStackTrace();
       }
     }
   }
 }
Exemple #3
0
  protected void deleteFile(TranscodeFileImpl file, boolean delete_contents, boolean remove)
      throws TranscodeException {
    if (file.isDeleted()) {

      return;
    }

    if (delete_contents) {

      File f = file.getCacheFile();

      int time = 0;

      while (f.exists() && !f.delete()) {

        if (time > 3000) {

          log("Failed to remove file '" + f.getAbsolutePath() + "'");

          break;

        } else {

          try {
            Thread.sleep(500);

          } catch (Throwable e) {

          }

          time += 500;
        }
      }
    }

    if (remove) {

      try {
        // fire the listeners FIRST as this gives listeners a chance to extract data
        // from the file before it is deleted (otherwise operations fail with 'file has been
        // deleted'

        for (TranscodeTargetListener l : listeners) {

          try {
            l.fileRemoved(file);

          } catch (Throwable e) {

            Debug.out(e);
          }
        }

        synchronized (this) {
          if (device_files == null) {

            loadDeviceFile();

          } else {

            device_files_last_mod = SystemTime.getMonotonousTime();
          }

          device_files.remove(file.getKey());

          device_files_dirty = true;
        }

      } catch (Throwable e) {

        throw (new TranscodeException("Delete failed", e));
      }
    }
  }