// 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; }
/** * Create a ClientGet from a request serialized to a SimpleFieldSet. Can throw, and does minimal * verification, as is dealing with data supposedly serialized out by the node. * * @throws IOException * @throws FetchException */ public ClientGet(SimpleFieldSet fs, FCPClient client2, FCPServer server) throws IOException, FetchException { super(fs, client2); returnType = ClientGetMessage.parseValidReturnType(fs.get("ReturnType")); String f = fs.get("Filename"); if (f != null) targetFile = new File(f); else targetFile = null; f = fs.get("TempFilename"); if (f != null) tempFile = new File(f); else tempFile = null; boolean ignoreDS = Fields.stringToBool(fs.get("IgnoreDS"), false); boolean dsOnly = Fields.stringToBool(fs.get("DSOnly"), false); int maxRetries = Integer.parseInt(fs.get("MaxRetries")); fctx = new FetchContext(server.defaultFetchContext, FetchContext.IDENTICAL_MASK, false, null); fctx.eventProducer.addEventListener(this); // ignoreDS fctx.localRequestOnly = dsOnly; fctx.ignoreStore = ignoreDS; fctx.maxNonSplitfileRetries = maxRetries; fctx.maxSplitfileBlockRetries = maxRetries; binaryBlob = Fields.stringToBool(fs.get("BinaryBlob"), false); succeeded = Fields.stringToBool(fs.get("Succeeded"), false); if (finished) { if (succeeded) { foundDataLength = Long.parseLong(fs.get("FoundDataLength")); foundDataMimeType = fs.get("FoundDataMimeType"); SimpleFieldSet fs1 = fs.subset("PostFetchProtocolError"); if (fs1 != null) postFetchProtocolErrorMessage = new ProtocolErrorMessage(fs1); } else { getFailedMessage = new GetFailedMessage(fs.subset("GetFailed"), false); } } Bucket ret = null; if (returnType == ClientGetMessage.RETURN_TYPE_DISK) { if (succeeded) { ret = new FileBucket(targetFile, false, true, false, false, false); } else { ret = new FileBucket(tempFile, false, true, false, false, false); } } else if (returnType == ClientGetMessage.RETURN_TYPE_NONE) { ret = new NullBucket(); } else if (returnType == ClientGetMessage.RETURN_TYPE_DIRECT) { try { ret = SerializableToFieldSetBucketUtil.create( fs.subset("ReturnBucket"), server.core.random, server.core.persistentTempBucketFactory); if (ret == null) throw new CannotCreateFromFieldSetException("ret == null"); } catch (CannotCreateFromFieldSetException e) { Logger.error(this, "Cannot read: " + this + " : " + e, e); try { // Create a new temp bucket if (persistenceType == PERSIST_FOREVER) ret = server.core.persistentTempBucketFactory.makeBucket(fctx.maxOutputLength); else ret = server.core.tempBucketFactory.makeBucket(fctx.maxOutputLength); } catch (IOException e1) { Logger.error(this, "Cannot create bucket for temp storage: " + e, e); getter = null; returnBucket = null; throw new FetchException(FetchException.BUCKET_ERROR, e); } } } else { throw new IllegalArgumentException(); } if (succeeded) { if (foundDataLength < ret.size()) { Logger.error(this, "Failing " + identifier + " because lost data"); succeeded = false; } } if (ret == null) Logger.error( this, "Impossible: ret = null in SFS constructor for " + this, new Exception("debug")); returnBucket = ret; String[] allowed = fs.getAll("AllowedMIMETypes"); if (allowed != null) { fctx.allowedMIMETypes = new HashSet<String>(); for (String a : allowed) fctx.allowedMIMETypes.add(a); } getter = new ClientGetter( this, uri, fctx, priorityClass, lowLevelClient, binaryBlob ? new NullBucket() : returnBucket, binaryBlob ? returnBucket : null); if (finished && succeeded) allDataPending = new AllDataMessage( returnBucket, identifier, global, startupTime, completionTime, this.foundDataMimeType); }