Author: nextgens
Date: 2008-08-17 10:15:25 +0000 (Sun, 17 Aug 2008)
New Revision: 21949

Modified:
   trunk/freenet/src/freenet/support/io/ArrayBucketFactory.java
   trunk/freenet/src/freenet/support/io/TempBucketFactory.java
Log:
Fix the build;

Commit the beginning of what will be the temporary bucket ageing code

Modified: trunk/freenet/src/freenet/support/io/ArrayBucketFactory.java
===================================================================
--- trunk/freenet/src/freenet/support/io/ArrayBucketFactory.java        
2008-08-17 10:12:46 UTC (rev 21948)
+++ trunk/freenet/src/freenet/support/io/ArrayBucketFactory.java        
2008-08-17 10:15:25 UTC (rev 21949)
@@ -11,11 +11,11 @@
 public class ArrayBucketFactory implements BucketFactory {
 
        public Bucket makeBucket(long size) throws IOException {
-               return new ArrayBucket();
+               return new ArrayBucket(size);
        }
 
        public void freeBucket(Bucket b) throws IOException {
-               // Do nothing
+               b.free();
        }
 
 }

Modified: trunk/freenet/src/freenet/support/io/TempBucketFactory.java
===================================================================
--- trunk/freenet/src/freenet/support/io/TempBucketFactory.java 2008-08-17 
10:12:46 UTC (rev 21948)
+++ trunk/freenet/src/freenet/support/io/TempBucketFactory.java 2008-08-17 
10:15:25 UTC (rev 21949)
@@ -1,3 +1,6 @@
+/* This code is part of Freenet. It is distributed under the GNU General
+ * Public License, version 2 (or at your option any later version). See
+ * http://www.gnu.org/ for further details of the GPL. */
 package freenet.support.io;
 
 import freenet.crypt.RandomSource;
@@ -6,32 +9,77 @@
 import freenet.support.api.Bucket;
 import freenet.support.api.BucketFactory;
 
-/*
- * This code is part of FProxy, an HTTP proxy server for Freenet. It is
- * distributed under the GNU Public Licence (GPL) version 2. See
- * http://www.gnu.org/ for further details of the GPL.
- */
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.Random;
 
 /**
  * Temporary Bucket Factory
- * 
- * @author giannij
  */
 public class TempBucketFactory implements BucketFactory {
+       public class TempBucket implements Bucket {
+               private Bucket currentBucket;
+               
+               public TempBucket(Bucket cur) {
+                       this.currentBucket = cur;
+               }
+               
+               public final void migrateToFileBucket() throws IOException {
+                       RAMBucket ramBucket = null;
+                       synchronized(this) {
+                               if(!isRAMBucket())
+                                       return;
 
+                               ramBucket = (RAMBucket) currentBucket;
+                               TempFileBucket tempFB = new 
TempFileBucket(filenameGenerator.makeRandomFilename(), filenameGenerator);
+                               BucketTools.copy(currentBucket, tempFB);
+                               currentBucket = tempFB;
+                       }
+                       ramBucket.free();
+               }
+               
+               public final synchronized boolean isRAMBucket() {
+                       return (currentBucket instanceof RAMBucket);
+               }
+
+               public synchronized OutputStream getOutputStream() throws 
IOException {
+                       return currentBucket.getOutputStream();
+               }
+
+               public synchronized InputStream getInputStream() throws 
IOException {
+                       return currentBucket.getInputStream();
+               }
+
+               public synchronized String getName() {
+                       return currentBucket.getName();
+               }
+
+               public synchronized long size() {
+                       return currentBucket.size();
+               }
+
+               public synchronized boolean isReadOnly() {
+                       return currentBucket.isReadOnly();
+               }
+
+               public synchronized void setReadOnly() {
+                       currentBucket.setReadOnly();
+               }
+
+               public synchronized void free() {
+                       currentBucket.free();
+               }
+       }
+
        private class RAMBucket extends ArrayBucket {
-               private final long size;
-               
                public RAMBucket(long size) {
-                       super("RAMBucket");
-                       this.size = size;
+                       super("RAMBucket", size);
                }
                
                @Override
                public void free() {
                        super.free();
-                       _hasFreed(size);
+                       _hasFreed(size());
                }
        }
        
@@ -45,8 +93,8 @@
        public long maxRAMBucketSize;
        public long maxRamUsed;
 
-       final RandomSource strongPRNG;
-       final Random weakPRNG;
+       private final RandomSource strongPRNG;
+       private final Random weakPRNG;
        private volatile boolean reallyEncrypt;
 
        // Storage accounting disabled by default.
@@ -111,7 +159,7 @@
         *                If it is not possible to create a temp bucket due to 
an
         *                I/O error
         */
-       public Bucket makeBucket(long size, float factor, long increment) 
throws IOException {
+       public TempBucket makeBucket(long size, float factor, long increment) 
throws IOException {
                Bucket realBucket = null;
                boolean isARAMBucket = false;
                
@@ -122,8 +170,11 @@
                        }
                }
                
+               // Do we want a RAMBucket or a FileBucket?
                realBucket = (isARAMBucket ? new RAMBucket(size) : new 
TempFileBucket(filenameGenerator.makeRandomFilename(), filenameGenerator));
+               // Do we want it to be encrypted?
+               realBucket = (!reallyEncrypt ? realBucket : new 
PaddedEphemerallyEncryptedBucket(realBucket, 1024, strongPRNG, weakPRNG));
                
-               return (!reallyEncrypt ? realBucket : new 
PaddedEphemerallyEncryptedBucket(realBucket, 1024, strongPRNG, weakPRNG));
+               return new TempBucket(realBucket);
        }
 }

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to