Package freenet.client.async

Examples of freenet.client.async.ClientGetter


  }

  protected abstract void onStartFetching();

  public void maybeUpdate() {
    ClientGetter toStart = null;
    if(!manager.isEnabled())
      return;
    if(manager.isBlown())
      return;
    ClientGetter cancelled = null;
    synchronized(this) {
      if(logMINOR)
        Logger.minor(this, "maybeUpdate: isFetching=" + isFetching + ", isRunning=" + isRunning + ", availableVersion=" + availableVersion);
      if(!isRunning)
        return;
      if(isFetching && availableVersion == fetchingVersion)
        return;
      if(availableVersion <= fetchedVersion)
        return;
      if(fetchingVersion < minDeployVersion || fetchingVersion == currentVersion) {
        Logger.normal(this, "Cancelling previous fetch");
        cancelled = cg;
        cg = null;
      }
      fetchingVersion = availableVersion;

      if(availableVersion > currentVersion) {
        Logger.normal(this, "Starting the update process (" + availableVersion + ')');
        System.err.println("Starting the update process: found the update (" + availableVersion + "), now fetching it.");
      }
      if(logMINOR)
        Logger.minor(this, "Starting the update process (" + availableVersion + ')');
      // We fetch it
      try {
        if((cg == null) || cg.isCancelled()) {
          if(logMINOR)
            Logger.minor(this, "Scheduling request for " + URI.setSuggestedEdition(availableVersion));
          if(availableVersion > currentVersion)
            System.err.println("Starting " + jarName() + " fetch for " + availableVersion);
          tempBlobFile =
            File.createTempFile(blobFilenamePrefix + availableVersion + "-", ".fblob.tmp", manager.node.clientCore.getPersistentTempDir());
          FreenetURI uri = URI.setSuggestedEdition(availableVersion);
          uri = uri.sskForUSK();
          cg = new ClientGetter(this, 
            uri, ctx, RequestStarter.IMMEDIATE_SPLITFILE_PRIORITY_CLASS,
            null, new BinaryBlobWriter(new FileBucket(tempBlobFile, false, false, false, false)), null);
          toStart = cg;
        } else {
          System.err.println("Already fetching "+jarName() + " fetch for " + fetchingVersion + " want "+availableVersion);
        }
        isFetching = true;
      } catch(Exception e) {
        Logger.error(this, "Error while starting the fetching: " + e, e);
        isFetching = false;
      }
    }
    if(toStart != null)
      try {
        node.clientCore.clientContext.start(toStart);
      } catch(FetchException e) {
        Logger.error(this, "Error while starting the fetching: " + e, e);
        synchronized(this) {
          isFetching = false;
        }
      } catch (PersistenceDisabledException e) {
        // Impossible
      }
    if(cancelled != null)
      cancelled.cancel(core.clientContext);
  }
View Full Code Here


    isRunning = false;
  }

  void kill() {
    try {
      ClientGetter c;
      synchronized(this) {
        isRunning = false;
        USK myUsk = USK.create(URI.setSuggestedEdition(currentVersion));
        core.uskManager.unsubscribe(myUsk, this);
        c = cg;
        cg = null;
      }
      c.cancel(core.clientContext);
    } catch(Exception e) {
      Logger.minor(this, "Cannot kill NodeUpdater", e);
    }
  }
View Full Code Here

    initialMetadata = message.getInitialMetadata();
    getter = makeGetter(ret);
  }
 
  private ClientGetter makeGetter(Bucket ret) {
      return new ClientGetter(this,
                uri, fctx, priorityClass,
                binaryBlob ? new NullBucket() : ret, binaryBlob ? new BinaryBlobWriter(ret) : null, false, initialMetadata, extensionCheck);
  }
View Full Code Here

    }
   
    private ClientGet(DataInputStream dis, RequestIdentifier reqID, ClientContext context, ChecksumChecker checker)
    throws IOException, StorageFormatException, ResumeFailedException {
        super(dis, reqID, context);
        ClientGetter getter = null;
        long magic = dis.readLong();
        if(magic != CLIENT_DETAIL_MAGIC)
            throw new StorageFormatException("Bad magic for request");
        int version = dis.readInt();
        if(version != CLIENT_DETAIL_VERSION)
            throw new StorageFormatException("Bad version "+version);
        String s = dis.readUTF();
        try {
            uri = new FreenetURI(s);
        } catch (MalformedURLException e) {
            throw new StorageFormatException("Bad URI");
        }
        short r = dis.readShort();
        try {
            returnType = ReturnType.getByCode(r);
        } catch (IllegalArgumentException e) {
            throw new StorageFormatException("Bad return type "+r);
        }
        if(returnType == ReturnType.DISK) {
            targetFile = new File(dis.readUTF());
        } else {
            targetFile = null;
        }
        binaryBlob = dis.readBoolean();
        FetchContext fctx = null;
        try {
            DataInputStream innerDIS =
                new DataInputStream(checker.checksumReaderWithLength(dis, context.tempBucketFactory, 65536));
            try {
                fctx = new FetchContext(innerDIS);
            } catch (IOException e) {
                Logger.error(this, "Unable to read fetch settings, will use default settings: "+e, e);
            } finally {
                innerDIS.close();
            }
        } catch (ChecksumFailedException e) {
            Logger.error(this, "Unable to read fetch settings, will use default settings");
        }
        if(fctx == null) {
            fctx = context.getDefaultPersistentFetchContext();
        }
        this.fctx = fctx;
        fctx.eventProducer.addEventListener(this);
        if(dis.readBoolean())
            extensionCheck = dis.readUTF();
        else
            extensionCheck = null;
        if(dis.readBoolean()) {
            initialMetadata = BucketTools.restoreFrom(dis, context.persistentFG, context.persistentFileTracker, context.getPersistentMasterSecret());
            // No way to recover if we don't have the initialMetadata.
        } else {
            initialMetadata = null;
        }
        if(finished) {
            succeeded = dis.readBoolean();
            readTransientProgressFields(dis);
            if(succeeded) {
                if(returnType == ReturnType.DIRECT) {
                    try {
                        DataInputStream innerDIS =
                            new DataInputStream(checker.checksumReaderWithLength(dis, context.tempBucketFactory, 65536));
                        try {
                            returnBucketDirect = BucketTools.restoreFrom(innerDIS, context.persistentFG, context.persistentFileTracker, context.getPersistentMasterSecret());
                        } catch (IOException e) {
                            Logger.error(this, "Failed to restore completed download-to-temp-space request, restarting instead");
                            returnBucketDirect = null;
                            succeeded = false;
                            finished = false;
                        } finally {
                            innerDIS.close();
                        }
                    } catch (ChecksumFailedException e) {
                        Logger.error(this, "Failed to restore completed download-to-temp-space request, restarting instead");
                        returnBucketDirect = null;
                        succeeded = false;
                        finished = false;
                    } catch (StorageFormatException e) {
                        Logger.error(this, "Failed to restore completed download-to-temp-space request, restarting instead");
                        returnBucketDirect = null;
                        succeeded = false;
                        finished = false;
                    }
                }
            } else {
                try {
                    DataInputStream innerDIS =
                        new DataInputStream(checker.checksumReaderWithLength(dis, context.tempBucketFactory, 65536));
                    try {
                        getFailedMessage = new GetFailedMessage(innerDIS, reqID, foundDataLength, foundDataMimeType);
                        started = true;
                    } catch (IOException e) {
                        Logger.error(this, "Unable to restore reason for failure, restarting request : "+e, e);
                        finished = false;
                        getFailedMessage = null;
                    } finally {
                        innerDIS.close();
                    }
                } catch (ChecksumFailedException e) {
                    Logger.error(this, "Unable to restore reason for failure, restarting request");
                    finished = false;
                    getFailedMessage = null;
                }
            }
        } else {
            getter = makeGetter(makeBucket(false));
            try {
                DataInputStream innerDIS =
                    new DataInputStream(checker.checksumReaderWithLength(dis, context.tempBucketFactory, 65536));
                try {
                    if(getter.resumeFromTrivialProgress(innerDIS, context)) {
                        readTransientProgressFields(innerDIS);
                    }
                } catch (IOException e) {
                    Logger.error(this, "Unable to restore splitfile, restarting: "+e);
                } finally {
View Full Code Here

      } catch (InsufficientDiskSpaceException e) {
          throw new FetchException(FetchExceptionMode.NOT_ENOUGH_DISK_SPACE);
      } catch (IOException e) {
        throw new FetchException(FetchExceptionMode.BUCKET_ERROR, "Cannot create temp file for "+filename+" in "+parent+" - disk full? permissions problem?");
      }
      getter = new ClientGetter(this, 
          chk, myCtx, RequestStarter.IMMEDIATE_SPLITFILE_PRIORITY_CLASS,
          new FileBucket(tempFile, false, false, false, false), null, null);
      myCtx.eventProducer.addEventListener(this);
      this.cb = cb;
      this.filename = filename;
View Full Code Here

        fetched = false;
        tempFile = null;
        return;
      }
      tempFile = tmp;
      cg = new ClientGetter(this, 
          uri, ctx, RequestStarter.IMMEDIATE_SPLITFILE_PRIORITY_CLASS,
          null, new BinaryBlobWriter(new FileBucket(tempFile, false, false, false, false)));
      fetched = false;
    }
  }
View Full Code Here

      Logger.error(this, "Not starting revocation checker: key already blown!");
      return false;
    }
    boolean wasRunning = false;
    logMINOR = Logger.shouldLog(LogLevel.MINOR, this);
    ClientGetter cg = null;
    try {
      ClientGetter toCancel = null;
      synchronized(this) {
        if(aggressive && !wasAggressive) {
          // Ignore old one.
          toCancel = revocationGetter;
          if(logMINOR) Logger.minor(this, "Ignoring old request, because was low priority");
          revocationGetter = null;
          if(toCancel != null) wasRunning = true;
        }
        wasAggressive = aggressive;
        if(revocationGetter != null &&
            !(revocationGetter.isCancelled() || revocationGetter.isFinished()))  {
          if(logMINOR) Logger.minor(this, "Not queueing another revocation fetcher yet, old one still running");
          reset = false;
          wasRunning = false;
        } else {
          if(reset) {
            if(logMINOR) Logger.minor(this, "Resetting DNF count from "+revocationDNFCounter, new Exception("debug"));
            revocationDNFCounter = 0;
          } else {
            if(logMINOR) Logger.minor(this, "Revocation count "+revocationDNFCounter);
          }
          if(logMINOR) Logger.minor(this, "fetcher="+revocationGetter);
          if(revocationGetter != null && logMINOR) Logger.minor(this, "revocation fetcher: cancelled="+revocationGetter.isCancelled()+", finished="+revocationGetter.isFinished());
          // Client startup may not have completed yet.
          manager.node.clientCore.getPersistentTempDir().mkdirs();
          cg = revocationGetter = new ClientGetter(this,
              manager.getRevocationURI(), ctxRevocation,
              aggressive ? RequestStarter.MAXIMUM_PRIORITY_CLASS : RequestStarter.IMMEDIATE_SPLITFILE_PRIORITY_CLASS,
              null, new BinaryBlobWriter(new ArrayBucket()), null);
          if(logMINOR) Logger.minor(this, "Queued another revocation fetcher (count="+revocationDNFCounter+")");
        }
      }
      if(toCancel != null)
        toCancel.cancel(core.clientContext);
      if(cg != null) {
        core.clientContext.start(cg);
        if(logMINOR) Logger.minor(this, "Started revocation fetcher");
      }
      return wasRunning;
View Full Code Here

          context.maxNonSplitfileRetries = -1;
          context.maxSplitfileBlockRetries = -1;
        }
        FetchWaiter fw = new FetchWaiter(node.nonPersistentClientBulk);

        get = new ClientGetter(fw, uri, context, PluginManager.PRIO, null, null, null);
        try {
          node.clientCore.clientContext.start(get);
        } catch (PersistenceDisabledException e) {
          // Impossible
        }
View Full Code Here

    FetchContext alteredFctx = new FetchContext(fctx, FetchContext.IDENTICAL_MASK);
    alteredFctx.maxOutputLength = fctx.maxTempLength = maxSize;
    alteredFctx.eventProducer.addEventListener(this);
    waiters = new ArrayList<FProxyFetchWaiter>();
    results = new ArrayList<FProxyFetchResult>();
    getter = new ClientGetter(this, uri, alteredFctx, FProxyToadlet.PRIORITY, null, null, null);
  }
View Full Code Here

  @Override
  public FetchResult fetch(FreenetURI uri) throws FetchException {
    if(uri == null) throw new NullPointerException();
    FetchContext context = getFetchContext();
    FetchWaiter fw = new FetchWaiter(this);
    ClientGetter get = new ClientGetter(fw, uri, context, priorityClass, null, null, null);
    try {
      core.clientContext.start(get);
    } catch (PersistenceDisabledException e) {
      // Impossible
    }
View Full Code Here

TOP

Related Classes of freenet.client.async.ClientGetter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.