public synchronized void flush() throws IOException {
   // Flush all proxies
   Iterator iter = this.alternateProxies.iterator();
   while (iter.hasNext()) {
     AbstractProxy proxy = (AbstractProxy) iter.next();
     proxy.flush();
   }
   this.proxy.flush();
   Logger.defaultLogger().info("Flush completed.");
   Logger.defaultLogger()
       .info("" + this.alternateProxies.size() + " alternate proxies are currently active.");
 }
 protected void disconnect() {
   Logger.defaultLogger().info("Disconnecting all proxies ...");
   Logger.defaultLogger().fine("Disconnecting main proxy ...");
   this.proxy.disconnect();
   Iterator iter = this.alternateProxies.iterator();
   int i = 0;
   while (iter.hasNext()) {
     Logger.defaultLogger().fine("Disconnecting proxy #" + ++i + " ...");
     AbstractProxy px = (AbstractProxy) iter.next();
     px.disconnect();
   }
 }
  public File[] listFiles(File file) {
    String owner = this.buildNewOwnerId("listFiles");
    AbstractProxy proxy = (AbstractProxy) this.getAvailableProxy(owner);
    FictiveFile[] files = null;
    File[] returned = null;
    try {
      files = proxy.listFiles(this.translateToRemote(file));
      returned = new File[files.length];
      for (int i = 0; i < files.length; i++) {
        returned[i] =
            new FictiveFile(
                translateToLocal(files[i].getRemotePath()),
                files[i].getRemotePath(),
                files[i].length(),
                files[i].isDirectory(),
                files[i].exists(),
                files[i].lastModified());
      }
    } catch (RemoteConnectionException e) {
      Logger.defaultLogger().error(e);
      throw new UnexpectedConnectionException(e);
    } finally {
      this.releaseProxy(proxy, owner);
    }

    return returned;
  }
  public boolean delete(File file) {
    removeLocalInputFile(file);

    String owner = this.buildNewOwnerId("delete");
    AbstractProxy proxy = this.getAvailableProxy(owner);
    boolean res = false;
    try {
      FileCacheableInformations infos = this.getInformations(file);
      if (infos.isExists()) {
        if (infos.isDirectory()) {
          res = proxy.deleteDir(this.translateToRemote(file));
        } else {
          res = proxy.deleteFile(this.translateToRemote(file));
        }
      } else {
        res = true;
      }
    } catch (RemoteConnectionException e) {
      Logger.defaultLogger()
          .error("Error caught while deleting " + FileSystemManager.getDisplayPath(file), e);
      throw new UnexpectedConnectionException(e);
    } finally {
      this.releaseProxy(proxy, owner);
    }

    return res;
  }
  private void fillTargetData(AbstractTarget target) {
    AbstractIncrementalFileSystemMedium medium =
        (AbstractIncrementalFileSystemMedium) target.getMedium();
    File[] archives = new File[0];
    try {
      Logger.defaultLogger()
          .info(
              "Looking for archives in "
                  + medium.getFileSystemPolicy().getDisplayableParameters(true),
              "Physical View");
      archives = medium.listArchives(null, null, true);
    } catch (Throwable e) {
      this.application.handleException(e);
    }

    if (archives == null) {
      archives = new File[0];
    }

    medium.checkArchivesEncoding(archives);

    for (int i = archives.length - 1; i >= 0; i--) {
      TableItem item = new TableItem(table, SWT.NONE);
      item.setData(archives[i]);

      try {
        Manifest manifest = ArchiveManifestCache.getInstance().getManifest(medium, archives[i]);

        String prp = null;
        if (manifest != null) {
          item.setText(1, Utils.formatDisplayDate(manifest.getDate()));
          initText(item, 0, manifest);
          prp = manifest.getStringProperty(ManifestKeys.OPTION_BACKUP_SCHEME);
        }

        if ((prp != null && prp.equals(AbstractTarget.BACKUP_SCHEME_FULL)) || i == 0) {
          item.setImage(0, ArecaImages.ICO_FS_FOLDER_FULL);
        } else if (prp != null && prp.equals(AbstractTarget.BACKUP_SCHEME_DIFFERENTIAL)) {
          item.setImage(0, ArecaImages.ICO_FS_FOLDER_DIFFERENTIAL);
        } else {
          item.setImage(0, ArecaImages.ICO_FS_FOLDER);
        }
        initSize(item, 2, archives[i], medium);
      } catch (ApplicationException e) {
        application.handleException(e);
      }
    }

    /*
    if (archives.length == 0) {
    	showViewMessage();
    } else {
    	removeViewMessage();
    }
    */
  }
  protected synchronized AbstractProxy getAvailableProxy(String owner) {
    if (this.proxy.acquireLock(owner)) {
      return proxy;
    } else {
      Iterator iter = this.alternateProxies.iterator();
      while (iter.hasNext()) {
        AbstractProxy alternateProxy = (AbstractProxy) iter.next();
        if (alternateProxy.acquireLock(owner)) {
          return alternateProxy;
        }
      }

      if (this.alternateProxies.size() == maxProxies) {
        Logger.defaultLogger()
            .error(
                "Maximum number of proxies ("
                    + maxProxies
                    + ") reached - Unable to create another proxy",
                "getAvailableProxy");
        Logger.defaultLogger().info("Main Proxy : " + this.proxy.getOwnerId());
        Iterator piter = this.alternateProxies.iterator();
        while (piter.hasNext()) {
          AbstractProxy px = (AbstractProxy) piter.next();
          Logger.defaultLogger().info("Alternate Proxy : " + px.getOwnerId());
        }
        return null;
      } else {
        Logger.defaultLogger()
            .info(
                "Creating a new proxy on "
                    + this.proxy.toString()
                    + " : "
                    + +(this.alternateProxies.size() + 1)
                    + " th.");
        AbstractProxy newProxy = this.proxy.cloneProxy();
        newProxy.acquireLock(owner);
        this.alternateProxies.add(newProxy);
        return newProxy;
      }
    }
  }
  public static void main(String[] args) {

    try {
      checkJavaVersion();
      ArecaConfiguration.initialize();

      VersionCheckWindow check = new VersionCheckWindow();
      check.setBlockOnOpen(true);
      check.open();
      Display.getCurrent().dispose();
    } catch (Throwable e) {
      e.printStackTrace();
      Logger.defaultLogger().error("Unexpected error", e);
    }
  }
  public boolean mkdir(File file) {
    String owner = this.buildNewOwnerId("mkdir");
    AbstractProxy proxy = this.getAvailableProxy(owner);
    boolean res = false;
    try {
      res = proxy.mkdir(this.translateToRemote(file));
    } catch (RemoteConnectionException e) {
      Logger.defaultLogger()
          .error("Error creating directory : " + FileSystemManager.getDisplayPath(file));
      throw new UnexpectedConnectionException(e);
    } finally {
      this.releaseProxy(proxy, owner);
    }

    return res;
  }
  public void newRow(char type, String key, String trace, ProcessContext context)
      throws IOException, FileMetaDataSerializationException, TaskCancelledException {
    if (key != null) {
      if (previousEntryKey != null) {
        if (FilePathComparator.instance().compare(key, previousEntryKey) <= 0) {
          Logger.defaultLogger()
              .error(
                  "Error detected in trace file: invalid entry order. "
                      + previousEntryKey
                      + " / "
                      + key);
          throw new IllegalStateException("Error detected while checking archive metadata.");
        }
      }

      previousEntryKey = key;
    }
  }
 public void unmount() throws IOException {
   Logger.defaultLogger().info("Unmounting driver : " + this.getClass().getName());
   this.flush();
   disconnect();
 }