On Wednesday 26 August 2009 21:04:40 Artefact2 wrote:
> On Tue, Aug 25, 2009 at 06:55:21PM +0100, Matthew Toseland wrote:
> > On Monday 24 August 2009 16:07:37 Artefact2 wrote:
> > > On Mon, Aug 24, 2009 at 04:08:04PM +0100, Matthew Toseland wrote:
> > > > 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 <artefact2 at gmail.com> 2009-08-23 20:51:48
> > > > Committer: Artefact2 <artefact2 at gmail.com> 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;
> > > > }
> > > > }
> > > >
> > >
> > > Well, when run() is called, I delete the old stored container from the
> > > database, I update the values of that container and I put that new
> > > container in the database. Maybe there is a way to simply update the
> > > container, but I don't know how to do it. My way works pretty nicely, but
> > > feel free to make any changes.
> >
> > You only need to store() it.
> > >
> > > I have two containers : latest and latestStored, because in some pages
> > > (statistics) we want to show the latest data, whether it has been stored
> > > or not.
> >
> > This will not work. The object will not be duplicated merely by putting it
> > into the database - that only happens with array members. The two objects
> > will remain identical and therefore the updates will be wrong if they rely
> > on comparing them.
>
> Well, only latestStored is actually stored in the database. Comparing
> them is reliable because I overrided the compare() function. At least,
> that's what I do and it works. There are probably lots of improvements,
> I'm not very familiar yet with db4o.
>
THEY ARE THE SAME OBJECT!!!!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 835 bytes
Desc: This is a digitally signed message part.
URL:
<https://emu.freenetproject.org/pipermail/devl/attachments/20090827/34e9df45/attachment.pgp>