I don't understand this commit. You never create a new BandwidthStatsContainer 
(apart from in restore), so why do you delete it and then store it?

Author: Artefact2 <[email protected]>  2009-08-23 20:51:48
Committer: Artefact2 <[email protected]>  2009-08-23 20:51:48
Parent: 3995d18cbda6151ab4033644f5158dfa54a9aa5c (Implement compatibility 
infobox functions (for plugins).)
Child:  dfcfab2677ea2b6b60aba45d97ed432ba844d675 (Implement total uptime (see 
bug #0002292).)
Branch: remotes/origin/master
Follows: build01232
Precedes: 

    Remove delay in stats page for persistant statistics.

------------- src/freenet/client/async/PersistentStatsPutter.java -------------
similarity index 70%
rename from src/freenet/client/async/BandwidthStatsPutter.java
rename to src/freenet/client/async/PersistentStatsPutter.java
index 464ffe9..4f359f3 100644
@@ -1,91 +1,99 @@
 /* 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.client.async;
 
 import com.db4o.ObjectContainer;
 import com.db4o.ObjectSet;
 import freenet.node.Node;
 import freenet.support.BandwidthStatsContainer;
 
 /**
- * Add/alter the BandwidthStatsContainer contained in the database, so that
+ * Add/alter the containers contained in the database, so that
  * the upload/download statistics persist.
  * 
  * @author Artefact2
  */
-public class BandwidthStatsPutter implements DBJob {
+public class PersistentStatsPutter implements DBJob {
        public static final int OFFSET = 60000;
 
        private Node n;
        private long latestNodeBytesOut = 0;
        private long latestNodeBytesIn = 0;
-       private BandwidthStatsContainer latest = new BandwidthStatsContainer();
+       private BandwidthStatsContainer latestBW = new 
BandwidthStatsContainer();
+       private BandwidthStatsContainer latestBWStored = new 
BandwidthStatsContainer();
 
-       public BandwidthStatsPutter(Node n) {
+       public PersistentStatsPutter(Node n) {
                this.n = n;
        }
 
        /**
         * Initiates that putter by fetching the latest container stored.
         * This should be called only once.
         *
         * @param container Database to use.
         */
        public void restorePreviousData(ObjectContainer container) {
                BandwidthStatsContainer highestBSC = null;
 
                ObjectSet<BandwidthStatsContainer> result = 
container.query(BandwidthStatsContainer.class);
 
                // Fetch the latest BSC
                for(BandwidthStatsContainer bsc : result) {
                        if(highestBSC == null) {
                                highestBSC = bsc;
                                continue;
                        }
 
                        if(highestBSC.creationTime < bsc.creationTime) {
                                highestBSC = bsc;
                        }
                }
 
                if(highestBSC == null) {
                        highestBSC = new BandwidthStatsContainer();
                }
 
                // Cleanup old stored items
                // BUT we keep our last BSC in case of a node crash before a 
new one
                // gets written.
                for(BandwidthStatsContainer bsc : result) {
                        if(!bsc.equals(highestBSC)) {
                                container.delete(bsc);
                        }
                }
 
-               this.latest = highestBSC;
+               this.latestBWStored = highestBSC;
+               this.latestBW = this.latestBWStored;
 
                container.commit();
        }
 
        public BandwidthStatsContainer getLatestData() {
-               return this.latest;
+               return this.latestBW;
        }
 
-       public boolean run(ObjectContainer container, ClientContext context) {
-               container.delete(this.latest);
-
-               // Update our BW values
+       public void updateData() {
+               // Update our values
                // 0 : total bytes out, 1 : total bytes in
                long[] nodeBW = this.n.collector.getTotalIO();
-               this.latest.totalBytesOut += nodeBW[0] - 
this.latestNodeBytesOut;
-               this.latest.totalBytesIn += nodeBW[1] - this.latestNodeBytesIn;
-               this.latest.creationTime = System.currentTimeMillis();
+               this.latestBW.totalBytesOut += nodeBW[0] - 
this.latestNodeBytesOut;
+               this.latestBW.totalBytesIn += nodeBW[1] - 
this.latestNodeBytesIn;
+               this.latestBW.creationTime = System.currentTimeMillis();
                this.latestNodeBytesOut = nodeBW[0];
                this.latestNodeBytesIn = nodeBW[1];
+       }
 
-               container.store(this.latest);
+       public boolean run(ObjectContainer container, ClientContext context) {
+               container.delete(this.latestBWStored);
+
+               this.updateData();
+
+               container.store(this.latestBW);
                container.commit();
 
+               this.latestBWStored = this.latestBW;
+
                return false;
        }
 }

Attachment: signature.asc
Description: This is a digitally signed message part.

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

Reply via email to