I don't understand the hasNodeStarted code...

On Sun, Sep 24, 2006 at 11:08:38AM +0000, nextgens at freenetproject.org wrote:
> Author: nextgens
> Date: 2006-09-24 11:08:34 +0000 (Sun, 24 Sep 2006)
> New Revision: 10507
> 
> Modified:
>    trunk/freenet/src/freenet/config/FreenetFilePersistentConfig.java
>    trunk/freenet/src/freenet/node/Node.java
> Log:
> Cleaner design for FreenetFilePersistentConfig : we don't need the node 
> object at all in fact
> 
> Modified: trunk/freenet/src/freenet/config/FreenetFilePersistentConfig.java
> ===================================================================
> --- trunk/freenet/src/freenet/config/FreenetFilePersistentConfig.java 
> 2006-09-24 10:44:38 UTC (rev 10506)
> +++ trunk/freenet/src/freenet/config/FreenetFilePersistentConfig.java 
> 2006-09-24 11:08:34 UTC (rev 10507)
> @@ -3,13 +3,39 @@
>  import java.io.File;
>  import java.io.IOException;
>  
> -import freenet.node.Node;
> +import freenet.node.Ticker;
>  import freenet.support.Logger;
>  
>  public class FreenetFilePersistentConfig extends FilePersistentConfig {
> -
> -     private Node node;
>       private boolean isWritingConfig = false;
> +     private boolean hasNodeStarted = false;
> +     private Ticker ticker;
> +     public final Runnable thread = new Runnable() {
> +             public void run() {
> +                     while(!hasNodeStarted){
> +                             synchronized (this) {
> +                                             hasNodeStarted = true;
> +                                             try{
> +                                                     wait(100);
> +                                             } catch (InterruptedException 
> e) {
> +                                                     hasNodeStarted = false; 
> +                                             }
> +                             }
> +                     }
> +                     
> +                     try {
> +                             innerStore();
> +                     } catch (IOException e) {
> +                             String err = "Cannot store config: "+e;
> +                             Logger.error(this, err, e);
> +                             System.err.println(err);
> +                             e.printStackTrace();
> +                     }
> +                     synchronized (storeSync) {
> +                             isWritingConfig = false;
> +                     }
> +             }
> +     };
>       
>       public FreenetFilePersistentConfig(File f) throws IOException {
>               super(f);
> @@ -23,39 +49,18 @@
>                       }
>               }
>               synchronized(storeSync) {
> -                     if(isWritingConfig || node == null){
> +                     if(isWritingConfig || ticker == null){
>                               Logger.normal(this, "Already writing the config 
> file to disk or the node object hasn't been set : refusing to proceed");
>                               return;
>                       }
>                       isWritingConfig = true;
>  
> -                     node.ps.queueTimedJob(new Runnable() {
> -                             public void run() {
> -                                     try{
> -                                             while(!node.isHasStarted())
> -                                                     Thread.sleep(1000);
> -                                     }catch (InterruptedException e) {}
> -                                     try {
> -                                             innerStore();
> -                                     } catch (IOException e) {
> -                                             String err = "Cannot store 
> config: "+e;
> -                                             Logger.error(this, err, e);
> -                                             System.err.println(err);
> -                                             e.printStackTrace();
> -                                     }
> -                                     synchronized (storeSync) {
> -                                             isWritingConfig = false;
> -                                     }
> -                             }
> -                     }, 0);
> +                     ticker.queueTimedJob(thread, 0);
>               }
>       }
>       
> -     public void setNode(Node n){
> -             if(node != null){
> -                     Logger.error(this, "The node object has already been 
> initialized! it's likely to be a bug.");
> -                     return;
> -             }
> -             this.node = n;
> +     public void finishedInit(Ticker ticker) {
> +             super.finishedInit();
> +             this.ticker = ticker;
>       }
>  }
> 
> Modified: trunk/freenet/src/freenet/node/Node.java
> ===================================================================
> --- trunk/freenet/src/freenet/node/Node.java  2006-09-24 10:44:38 UTC (rev 
> 10506)
> +++ trunk/freenet/src/freenet/node/Node.java  2006-09-24 11:08:34 UTC (rev 
> 10507)
> @@ -1404,9 +1404,11 @@
>               this.clientCore.start(config);
>               
>               // After everything has been created, write the config file 
> back to disk.
> -             config.finishedInit();
> -             config.setNode(this);
> +             config.finishedInit(this.ps);
>               config.store();
> +             synchronized (config.thread) {
> +                     config.thread.notify(); 
> +             }
>               
>               // Process any data in the extra peer data directory
>               peers.readExtraPeerData();
> 
> _______________________________________________
> cvs mailing list
> cvs at freenetproject.org
> http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: 
<https://emu.freenetproject.org/pipermail/devl/attachments/20060925/082874b5/attachment.pgp>

Reply via email to