示例#1
0
  /**
   * Starts the download component.
   *
   * @throws SmartFrogException in case of error in starting
   * @throws RemoteException in case of network/emi error
   */
  @Override
  public synchronized void sfStart() throws SmartFrogException, RemoteException {
    super.sfStart();
    log = sfGetApplicationLog();
    String url = "NOT YET SET";
    String localFile = "NOT YET SET";
    try {
      url = (String) sfResolve(ATTR_URL);
      localFile = FileSystem.lookupAbsolutePath(this, ATTR_LOCALFILE, null, null, true, null);

      int blocksize = ((Integer) sfResolve(ATTR_BLOCKSIZE)).intValue();
      int maxCacheAge = -1;
      maxCacheAge = sfResolve(ATTR_MAX_CACHE_AGE, maxCacheAge, false);
      if (sfLog().isInfoEnabled()) {
        sfLog().info(" Downloading '" + url + "' to '" + localFile + "'. Blocksize: " + blocksize);
      }
      File target = new File(localFile);
      bind(target);
      download(url, target, blocksize, maxCacheAge);
      if (sfLog().isInfoEnabled()) {
        sfLog().info(" Download complete. File in: " + target);
      }

      new ComponentHelper(this)
          .sfSelfDetachAndOrTerminate(null, "Download completed. File in: " + target, null, null);

    } catch (Exception e) {
      String errStr = ERROR_IN_DOWNLOAD + url + " to " + localFile;
      if (log.isErrorEnabled()) {
        log.error(errStr, e);
      }
      throw SmartFrogLifecycleException.forward(errStr, e, this);
    }
  }
示例#2
0
 /**
  * delete the file if needed
  *
  * @param status termination status
  */
 @Override
 public synchronized void sfTerminateWith(TerminationRecord status) {
   super.sfTerminateWith(status);
   deleteFileIfNeeded();
 }