[freenet-cvs] r14953 - trunk/freenet/src/freenet/node/fcp

nextgens at freenetproject.org nextgens at freenetproject.org
Mon Sep 3 23:19:14 UTC 2007


Author: nextgens
Date: 2007-09-03 23:19:14 +0000 (Mon, 03 Sep 2007)
New Revision: 14953

Modified:
   trunk/freenet/src/freenet/node/fcp/ClientGet.java
   trunk/freenet/src/freenet/node/fcp/ClientPutBase.java
   trunk/freenet/src/freenet/node/fcp/ClientRequest.java
Log:
indent

Modified: trunk/freenet/src/freenet/node/fcp/ClientGet.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientGet.java	2007-09-03 23:18:43 UTC (rev 14952)
+++ trunk/freenet/src/freenet/node/fcp/ClientGet.java	2007-09-03 23:19:14 UTC (rev 14953)
@@ -77,7 +77,7 @@
 			File returnFilename, File returnTempFilename) throws IdentifierCollisionException, NotAllowedException {
 		super(uri, identifier, verbosity, null, globalClient, prioClass,
 				(persistRebootOnly ? ClientRequest.PERSIST_REBOOT : ClientRequest.PERSIST_FOREVER),
-						null, true);
+				null, true);
 
 		fctx = new FetchContext(client.defaultFetchContext, FetchContext.IDENTICAL_MASK, false);
 		fctx.eventProducer.addEventListener(this);
@@ -124,11 +124,11 @@
 				ret.free();
 				throw e;
 			}
-		getter = new ClientGetter(this, client.core.requestStarters.chkFetchScheduler, client.core.requestStarters.sskFetchScheduler, uri, fctx, priorityClass, client.lowLevelClient, returnBucket, null);
-		if(persistenceType != PERSIST_CONNECTION) {
-			FCPMessage msg = persistentTagMessage();
-			client.queueClientRequestMessage(msg, 0);
-		}
+			getter = new ClientGetter(this, client.core.requestStarters.chkFetchScheduler, client.core.requestStarters.sskFetchScheduler, uri, fctx, priorityClass, client.lowLevelClient, returnBucket, null);
+			if(persistenceType != PERSIST_CONNECTION) {
+				FCPMessage msg = persistentTagMessage();
+				client.queueClientRequestMessage(msg, 0);
+			}
 	}
 
 	public ClientGet(FCPConnectionHandler handler, ClientGetMessage message) throws IdentifierCollisionException, MessageInvalidException {
@@ -147,12 +147,12 @@
 		// Has already been checked
 		fctx.maxOutputLength = message.maxSize;
 		fctx.maxTempLength = message.maxTempSize;
-		
+
 		if(message.allowedMIMETypes != null) {
 			fctx.allowedMIMETypes = new HashSet();
 			for(int i=0;i<message.allowedMIMETypes.length;i++) fctx.allowedMIMETypes.add(message.allowedMIMETypes[i]);
 		}
-		
+
 		this.returnType = message.returnType;
 		this.binaryBlob = message.binaryBlob;
 		Bucket ret = null;
@@ -194,16 +194,16 @@
 				ret.free();
 				throw e;
 			}
-		getter = new ClientGetter(this, client.core.requestStarters.chkFetchScheduler, 
-				client.core.requestStarters.sskFetchScheduler, uri, fctx, priorityClass, 
-				client.lowLevelClient, binaryBlob ? new NullBucket() : returnBucket, 
-						binaryBlob ? returnBucket : null);
-		if(persistenceType != PERSIST_CONNECTION) {
-			FCPMessage msg = persistentTagMessage();
-			client.queueClientRequestMessage(msg, 0);
-			if(handler != null && (!handler.isGlobalSubscribed()))
-				handler.outputHandler.queue(msg);
-		}
+			getter = new ClientGetter(this, client.core.requestStarters.chkFetchScheduler, 
+					client.core.requestStarters.sskFetchScheduler, uri, fctx, priorityClass, 
+					client.lowLevelClient, binaryBlob ? new NullBucket() : returnBucket, 
+							binaryBlob ? returnBucket : null);
+			if(persistenceType != PERSIST_CONNECTION) {
+				FCPMessage msg = persistentTagMessage();
+				client.queueClientRequestMessage(msg, 0);
+				if(handler != null && (!handler.isGlobalSubscribed()))
+					handler.outputHandler.queue(msg);
+			}
 	}
 
 	/**
@@ -296,18 +296,18 @@
 			fctx.allowedMIMETypes = new HashSet();
 			for(int i=0;i<allowed.length;i++) fctx.allowedMIMETypes.add(allowed[i]);
 		}
-		
+
 		getter = new ClientGetter(this, client.core.requestStarters.chkFetchScheduler, 
 				client.core.requestStarters.sskFetchScheduler, uri, 
 				fctx, priorityClass, client.lowLevelClient, 
 				binaryBlob ? new NullBucket() : returnBucket, 
-				binaryBlob ? returnBucket : null);
+						binaryBlob ? returnBucket : null);
 
 		if(persistenceType != PERSIST_CONNECTION) {
 			FCPMessage msg = persistentTagMessage();
 			client.queueClientRequestMessage(msg, 0);
 		}
-		
+
 		if(finished){
 			if(succeeded) 
 				allDataPending = new AllDataMessage(returnBucket, identifier, global, startupTime, completionTime);
@@ -390,10 +390,10 @@
 				if(persistenceType == PERSIST_CONNECTION)
 					adm.setFreeOnSent();
 				dontFree = true;
-			/* 
-			 * } else if(returnType == ClientGetMessage.RETURN_TYPE_NONE) {
+				/* 
+				 * } else if(returnType == ClientGetMessage.RETURN_TYPE_NONE) {
 				// Do nothing
-			 */
+				 */
 			} else if(returnType == ClientGetMessage.RETURN_TYPE_DISK) {
 				// Write to temp file, then rename over filename
 				FileOutputStream fos = null;
@@ -496,7 +496,7 @@
 	}
 
 	public void onFailure(FetchException e, ClientGetter state) {
-        if(finished) return;
+		if(finished) return;
 		synchronized(this) {
 			succeeded = false;
 			getFailedMessage = new GetFailedMessage(e, identifier, global);
@@ -521,26 +521,26 @@
 	public void onGeneratedURI(FreenetURI uri, BaseClientPutter state) {
 		// Ignore
 	}
-    
-    public void requestWasRemoved() {
-        // 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);
-        }
-        // notify client that request was removed
-        FCPMessage msg = new PersistentRequestRemovedMessage(getIdentifier(), global);
-        client.queueClientRequestMessage(msg, 0);
 
-        freeData();
-        finish();
-    }
+	public void requestWasRemoved() {
+		// 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);
+		}
+		// notify client that request was removed
+		FCPMessage msg = new PersistentRequestRemovedMessage(getIdentifier(), global);
+		client.queueClientRequestMessage(msg, 0);
 
+		freeData();
+		finish();
+	}
+
 	public void receive(ClientEvent ce) {
 		// Don't need to lock, verbosity is final and finished is never unset.
 		if(finished) return;

Modified: trunk/freenet/src/freenet/node/fcp/ClientPutBase.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientPutBase.java	2007-09-03 23:18:43 UTC (rev 14952)
+++ trunk/freenet/src/freenet/node/fcp/ClientPutBase.java	2007-09-03 23:19:14 UTC (rev 14953)
@@ -30,7 +30,7 @@
 	private int VERBOSITY_SPLITFILE_PROGRESS = 1;
 	private int VERBOSITY_PUT_FETCHABLE = 256;
 	private int VERBOSITY_COMPRESSION_START_END = 512;
-	
+
 	// Stuff waiting for reconnection
 	/** Has the request succeeded? */
 	protected boolean succeeded;
@@ -48,12 +48,12 @@
 
 	/** Whether to force an early generation of the CHK */
 	protected final boolean earlyEncode;
-	
+
 	protected final FreenetURI publicURI;
-	
+
 	public final static String SALT = "Salt";
 	public final static String FILE_HASH = "FileHash";
-	
+
 	public ClientPutBase(FreenetURI uri, String identifier, int verbosity, FCPConnectionHandler handler, 
 			short priorityClass, short persistenceType, String clientToken, boolean global, boolean getCHKOnly,
 			boolean dontCompress, int maxRetries, boolean earlyEncode) throws MalformedURLException {
@@ -125,7 +125,7 @@
 			cancel();
 		// otherwise ignore
 	}
-	
+
 	public void onSuccess(BaseClientPutter state) {
 		synchronized(this) {
 			// Including this helps with certain bugs...
@@ -141,7 +141,7 @@
 	}
 
 	public void onFailure(InsertException e, BaseClientPutter state) {
-        if(finished) return;
+		if(finished) return;
 		synchronized(this) {
 			finished = true;
 			putFailedMessage = new PutFailedMessage(e, identifier, global);
@@ -161,25 +161,25 @@
 		}
 		trySendGeneratedURIMessage(null);
 	}
-    
-    public void requestWasRemoved() {
-        // if request is still running, send a PutFailed with code=cancelled
-        if( !finished ) {
-            synchronized(this) {
-                finished = true;
-                InsertException cancelled = new InsertException(InsertException.CANCELLED);
-                putFailedMessage = new PutFailedMessage(cancelled, identifier, global);
-            }
-            trySendFinalMessage(null);
-        }
-        // notify client that request was removed
-        FCPMessage msg = new PersistentRequestRemovedMessage(getIdentifier(), global);
-        client.queueClientRequestMessage(msg, 0);
 
-        freeData();
-        finish();
-    }
+	public void requestWasRemoved() {
+		// if request is still running, send a PutFailed with code=cancelled
+		if( !finished ) {
+			synchronized(this) {
+				finished = true;
+				InsertException cancelled = new InsertException(InsertException.CANCELLED);
+				putFailedMessage = new PutFailedMessage(cancelled, identifier, global);
+			}
+			trySendFinalMessage(null);
+		}
+		// notify client that request was removed
+		FCPMessage msg = new PersistentRequestRemovedMessage(getIdentifier(), global);
+		client.queueClientRequestMessage(msg, 0);
 
+		freeData();
+		finish();
+	}
+
 	public void receive(ClientEvent ce) {
 		if(finished) return;
 		if(ce instanceof SplitfileProgressEvent) {
@@ -215,9 +215,9 @@
 			trySendProgressMessage(msg, VERBOSITY_PUT_FETCHABLE, null);
 		}
 	}
-	
+
 	private void trySendFinalMessage(FCPConnectionOutputHandler handler) {
-		
+
 		FCPMessage msg;
 		synchronized (this) {
 			if(succeeded) {
@@ -226,7 +226,7 @@
 				msg = putFailedMessage;
 			}
 		}
-		
+
 		if(msg == null) {
 			Logger.error(this, "Trying to send null message on "+this, new Exception("error"));
 		} else {
@@ -258,7 +258,7 @@
 		else
 			client.queueClientRequestMessage(msg, verbosity);
 	}
-	
+
 	public void sendPendingMessages(FCPConnectionOutputHandler handler, boolean includePersistentRequest, boolean includeData, boolean onlyData) {
 		if(persistenceType == PERSIST_CONNECTION) {
 			Logger.error(this, "WTF? persistenceType="+persistenceType, new Exception("error"));
@@ -268,7 +268,7 @@
 			FCPMessage msg = persistentTagMessage();
 			handler.queue(msg);
 		}
-		
+
 		boolean generated = false;
 		FCPMessage msg = null;
 		boolean fin = false;
@@ -312,7 +312,7 @@
 		
 		return fs;
 	}
-	
+
 	protected abstract String getTypeName();
 
 	public synchronized double getSuccessFraction() {
@@ -324,7 +324,7 @@
 			return -1;
 	}
 
-	
+
 	public synchronized double getTotalBlocks() {
 		if(progressMessage != null) {
 			if(progressMessage instanceof SimpleProgressMessage)
@@ -333,7 +333,7 @@
 		} else
 			return -1;
 	}
-	
+
 	public synchronized double getMinBlocks() {
 		if(progressMessage != null) {
 			if(progressMessage instanceof SimpleProgressMessage)
@@ -342,7 +342,7 @@
 		} else
 			return -1;
 	}
-	
+
 	public synchronized double getFailedBlocks() {
 		if(progressMessage != null) {
 			if(progressMessage instanceof SimpleProgressMessage)
@@ -351,7 +351,7 @@
 		} else
 			return -1;
 	}
-	
+
 	public synchronized double getFatalyFailedBlocks() {
 		if(progressMessage != null) {
 			if(progressMessage instanceof SimpleProgressMessage)
@@ -360,7 +360,7 @@
 		} else
 			return -1;
 	}
-	
+
 	public synchronized double getFetchedBlocks() {
 		if(progressMessage != null) {
 			if(progressMessage instanceof SimpleProgressMessage)
@@ -369,12 +369,12 @@
 		} else
 			return -1;
 	}
-	
+
 	public synchronized boolean isTotalFinalized() {
 		if(!(progressMessage instanceof SimpleProgressMessage)) return false;
 		else return ((SimpleProgressMessage)progressMessage).isTotalFinalized();
 	}
-	
+
 	public synchronized String getFailureReason() {
 		if(putFailedMessage == null)
 			return null;
@@ -383,7 +383,7 @@
 			s += ": "+putFailedMessage.extraDescription;
 		return s;
 	}
-	
+
 	public void setVarsRestart() {
 		synchronized(this) {
 			finished = false;

Modified: trunk/freenet/src/freenet/node/fcp/ClientRequest.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientRequest.java	2007-09-03 23:18:43 UTC (rev 14952)
+++ trunk/freenet/src/freenet/node/fcp/ClientRequest.java	2007-09-03 23:19:14 UTC (rev 14953)
@@ -62,7 +62,7 @@
 		this.client = client;
 		this.startupTime = System.currentTimeMillis();
 	}
-	
+
 	public ClientRequest(FreenetURI uri2, String identifier2, int verbosity2, FCPConnectionHandler handler, 
 			short priorityClass2, short persistenceType2, String clientToken2, boolean global) {
 		this.uri = uri2;
@@ -113,16 +113,16 @@
 
 	/** Lost connection */
 	public abstract void onLostConnection();
-	
+
 	/** Send any pending messages for a persistent request e.g. after reconnecting */
 	public abstract void sendPendingMessages(FCPConnectionOutputHandler handler, boolean includePersistentRequest, boolean includeData, boolean onlyData);
 
 	// Persistence
-	
+
 	public static final short PERSIST_CONNECTION = 0;
 	public static final short PERSIST_REBOOT = 1;
 	public static final short PERSIST_FOREVER = 2;
-	
+
 	public static String persistenceTypeString(short type) {
 		switch(type) {
 		case PERSIST_CONNECTION:
@@ -223,13 +223,13 @@
 	}
 
 	protected abstract ClientRequester getClientRequest();
-	
+
 	/** Completed request dropped off the end without being acknowledged */
 	public void dropped() {
 		cancel();
 		freeData();
 	}
-	
+
 	/** Return the priority class */
 	public short getPriority(){
 		return priorityClass;
@@ -247,7 +247,7 @@
 			client.server.forceStorePersistentRequests();
 		client.finishedClientRequest(this);
 	}
-	
+
 	/**
 	 * Write a persistent request to disk.
 	 * @throws IOException 
@@ -261,14 +261,14 @@
 		SimpleFieldSet fs = getFieldSet();
 		fs.writeTo(w);
 	}
-	
+
 	/**
 	 * Get a SimpleFieldSet representing this request.
 	 */
 	public abstract SimpleFieldSet getFieldSet() throws IOException;
 
 	public abstract double getSuccessFraction();
-	
+
 	public abstract double getTotalBlocks();
 	public abstract double getMinBlocks();
 	public abstract double getFetchedBlocks();
@@ -281,7 +281,7 @@
 	 * Has the total number of blocks to insert been determined yet?
 	 */
 	public abstract boolean isTotalFinalized();
-	
+
 	public void onMajorProgress() {
 		if(persistenceType != ClientRequest.PERSIST_CONNECTION) {
 			if(client != null)
@@ -293,7 +293,7 @@
 	public abstract void start();
 
 	protected boolean started;
-	
+
 	public boolean isStarted() {
 		return started;
 	}
@@ -304,64 +304,64 @@
 
 	public abstract boolean restart();
 
-    protected abstract FCPMessage persistentTagMessage();
+	protected abstract FCPMessage persistentTagMessage();
 
-    /**
-     * Called after a ModifyPersistentRequest.
-     * Sends a PersistentRequestModified message to clients if any value changed. 
-     */
-    public void modifyRequest(String newClientToken, short newPriorityClass) {
+	/**
+	 * Called after a ModifyPersistentRequest.
+	 * Sends a PersistentRequestModified message to clients if any value changed. 
+	 */
+	public void modifyRequest(String newClientToken, short newPriorityClass) {
 
-        boolean clientTokenChanged = false;
-        boolean priorityClassChanged = false;
-        
-        if(newClientToken != null) {
-            if( clientToken != null ) {
-                if( !newClientToken.equals(clientToken) ) {
-                    this.clientToken = newClientToken; // token changed
-                    clientTokenChanged = true;
-                }
-            } else {
-                this.clientToken = newClientToken; // first time the token is set
-                clientTokenChanged = true;
-            }
-        }
+		boolean clientTokenChanged = false;
+		boolean priorityClassChanged = false;
 
-        if(newPriorityClass >= 0 && newPriorityClass != priorityClass) {
-            this.priorityClass = newPriorityClass;
-            getClientRequest().setPriorityClass(priorityClass);
-            priorityClassChanged = true;
-        }
+		if(newClientToken != null) {
+			if( clientToken != null ) {
+				if( !newClientToken.equals(clientToken) ) {
+					this.clientToken = newClientToken; // token changed
+					clientTokenChanged = true;
+				}
+			} else {
+				this.clientToken = newClientToken; // first time the token is set
+				clientTokenChanged = true;
+			}
+		}
 
-        if( clientTokenChanged || priorityClassChanged ) {
-            if(persistenceType != ClientRequest.PERSIST_CONNECTION) {
-                if(client != null) {
-                    client.server.forceStorePersistentRequests();
-                }
-            }
-        } else {
-            return; // quick return, nothing was changed
-        }
+		if(newPriorityClass >= 0 && newPriorityClass != priorityClass) {
+			this.priorityClass = newPriorityClass;
+			getClientRequest().setPriorityClass(priorityClass);
+			priorityClassChanged = true;
+		}
 
-        // this could become too complex with more parameters, but for now its ok
-        final PersistentRequestModifiedMessage modifiedMsg;
-        if( clientTokenChanged && priorityClassChanged ) {
-            modifiedMsg = new PersistentRequestModifiedMessage(identifier, global, priorityClass, clientToken);
-        } else if( priorityClassChanged ) {
-            modifiedMsg = new PersistentRequestModifiedMessage(identifier, global, priorityClass);
-        } else if( clientTokenChanged ) {
-            modifiedMsg = new PersistentRequestModifiedMessage(identifier, global, clientToken);
-        } else {
-            return; // paranoia, we should not be here if nothing was changed!
-        }
-        client.queueClientRequestMessage(modifiedMsg, 0);
-    }
+		if( clientTokenChanged || priorityClassChanged ) {
+			if(persistenceType != ClientRequest.PERSIST_CONNECTION) {
+				if(client != null) {
+					client.server.forceStorePersistentRequests();
+				}
+			}
+		} else {
+			return; // quick return, nothing was changed
+		}
 
-    /**
-     * Called after a RemovePersistentRequest. Send a PersistentRequestRemoved to the clients.
-     */
-    public abstract void requestWasRemoved();
-    
+		// this could become too complex with more parameters, but for now its ok
+		final PersistentRequestModifiedMessage modifiedMsg;
+		if( clientTokenChanged && priorityClassChanged ) {
+			modifiedMsg = new PersistentRequestModifiedMessage(identifier, global, priorityClass, clientToken);
+		} else if( priorityClassChanged ) {
+			modifiedMsg = new PersistentRequestModifiedMessage(identifier, global, priorityClass);
+		} else if( clientTokenChanged ) {
+			modifiedMsg = new PersistentRequestModifiedMessage(identifier, global, clientToken);
+		} else {
+			return; // paranoia, we should not be here if nothing was changed!
+		}
+		client.queueClientRequestMessage(modifiedMsg, 0);
+	}
+
+	/**
+	 * Called after a RemovePersistentRequest. Send a PersistentRequestRemoved to the clients.
+	 */
+	public abstract void requestWasRemoved();
+
 	/** Utility method for storing details of a possibly encrypted bucket. */
 	protected void bucketToFS(SimpleFieldSet fs, String name, boolean includeSize, Bucket data) {
 		SerializableToFieldSetBucket bucket = (SerializableToFieldSetBucket) data;




More information about the cvs mailing list