Beispiel #1
0
  @Override
  public void requestWasRemoved(ObjectContainer container, ClientContext context) {
    // if request is still running, send a GetFailed with code=cancelled
    if (!finished) {
      synchronized (this) {
        succeeded = false;
        finished = true;
        FetchException cancelled = new FetchException(FetchException.CANCELLED);
        getFailedMessage = new GetFailedMessage(cancelled, identifier, global);
      }
      trySendDataFoundOrGetFailed(null, container);
    }
    // notify client that request was removed
    FCPMessage msg = new PersistentRequestRemovedMessage(getIdentifier(), global);
    if (persistenceType != PERSIST_CONNECTION) {
      if (persistenceType == PERSIST_FOREVER) container.activate(client, 1);
      client.queueClientRequestMessage(msg, 0, container);
    }

    freeData(container);

    if (persistenceType == PERSIST_FOREVER) {
      container.activate(fctx, 1);
      if (fctx.allowedMIMETypes != null) {
        container.activate(fctx.allowedMIMETypes, 5);
        container.delete(fctx.allowedMIMETypes);
      }
      fctx.removeFrom(container);
      getter.removeFrom(container, context);
      if (targetFile != null) container.delete(targetFile);
      if (tempFile != null) container.delete(tempFile);
      if (getFailedMessage != null) {
        container.activate(getFailedMessage, 5);
        getFailedMessage.removeFrom(container);
      }
      if (postFetchProtocolErrorMessage != null) {
        container.activate(postFetchProtocolErrorMessage, 5);
        postFetchProtocolErrorMessage.removeFrom(container);
      }
      if (allDataPending != null) {
        container.activate(allDataPending, 5);
        allDataPending.removeFrom(container);
      }
      if (progressPending != null) {
        container.activate(progressPending, 5);
        progressPending.removeFrom(container);
      }
    }
    super.requestWasRemoved(container, context);
  }
Beispiel #2
0
  // This is distinct from the ClientGetMessage code, as later on it will be radically
  // different (it can store detailed state).
  @Override
  public synchronized SimpleFieldSet getFieldSet() {
    SimpleFieldSet fs = new SimpleFieldSet(false); // we will need multi-level later...
    fs.putSingle("Type", "GET");
    fs.putSingle("URI", uri.toString(false, false));
    fs.putSingle("Identifier", identifier);
    fs.putSingle("Verbosity", Integer.toString(verbosity));
    fs.putSingle("PriorityClass", Short.toString(priorityClass));
    fs.putSingle("ReturnType", ClientGetMessage.returnTypeString(returnType));
    fs.putSingle("Persistence", persistenceTypeString(persistenceType));
    fs.putSingle("ClientName", client.name);
    if (targetFile != null) fs.putSingle("Filename", targetFile.getPath());
    if (tempFile != null) fs.putSingle("TempFilename", tempFile.getPath());
    if (clientToken != null) fs.putSingle("ClientToken", clientToken);
    fs.putSingle("IgnoreDS", Boolean.toString(fctx.ignoreStore));
    fs.putSingle("DSOnly", Boolean.toString(fctx.localRequestOnly));
    fs.putSingle("MaxRetries", Integer.toString(fctx.maxNonSplitfileRetries));
    fs.putSingle("Finished", Boolean.toString(finished));
    fs.putSingle("Succeeded", Boolean.toString(succeeded));
    if (fctx.allowedMIMETypes != null)
      fs.putOverwrite(
          "AllowedMIMETypes",
          (String[]) fctx.allowedMIMETypes.toArray(new String[fctx.allowedMIMETypes.size()]));
    if (finished) {
      if (succeeded) {
        fs.putSingle("FoundDataLength", Long.toString(foundDataLength));
        fs.putSingle("FoundDataMimeType", foundDataMimeType);
        if (postFetchProtocolErrorMessage != null) {
          fs.put("PostFetchProtocolError", postFetchProtocolErrorMessage.getFieldSet());
        }
      } else {
        if (getFailedMessage != null) {
          fs.put("GetFailed", getFailedMessage.getFieldSet(false));
        }
      }
    }
    // Return bucket
    if (returnType == ClientGetMessage.RETURN_TYPE_DIRECT
        && !(succeeded == false && returnBucket == null)) {
      bucketToFS(fs, "ReturnBucket", false, returnBucket);
    }
    fs.putSingle("Global", Boolean.toString(client.isGlobalQueue));
    fs.put("BinaryBlob", binaryBlob);
    fs.put("StartupTime", startupTime);
    if (finished) fs.put("CompletionTime", completionTime);

    return fs;
  }
Beispiel #3
0
 @Override
 public boolean restart(ObjectContainer container, ClientContext context) {
   if (!canRestart()) return false;
   FreenetURI redirect;
   synchronized (this) {
     finished = false;
     redirect = getFailedMessage == null ? null : getFailedMessage.redirectURI;
     if (persistenceType == PERSIST_FOREVER && getFailedMessage != null)
       getFailedMessage.removeFrom(container);
     this.getFailedMessage = null;
     if (persistenceType == PERSIST_FOREVER && allDataPending != null)
       allDataPending.removeFrom(container);
     this.allDataPending = null;
     if (persistenceType == PERSIST_FOREVER && postFetchProtocolErrorMessage != null)
       postFetchProtocolErrorMessage.removeFrom(container);
     this.postFetchProtocolErrorMessage = null;
     if (persistenceType == PERSIST_FOREVER && progressPending != null)
       progressPending.removeFrom(container);
     this.progressPending = null;
     started = false;
   }
   if (persistenceType == PERSIST_FOREVER) container.store(this);
   try {
     if (getter.restart(redirect, container, context)) {
       synchronized (this) {
         if (redirect != null) {
           if (persistenceType == PERSIST_FOREVER) uri.removeFrom(container);
           this.uri = redirect;
         }
         started = true;
       }
       if (persistenceType == PERSIST_FOREVER) container.store(this);
     }
     return true;
   } catch (FetchException e) {
     onFailure(e, null, container);
     return false;
   }
 }