We should have a callback interface for plugins to notify when the node has 
finished startup...

On Friday 07 November 2008 23:28, xor at freenetproject.org wrote:
> Author: xor
> Date: 2008-11-07 23:28:39 +0000 (Fri, 07 Nov 2008)
> New Revision: 23396
> 
> Modified:
>    trunk/plugins/Freetalk/FTIdentityManager.java
>    trunk/plugins/Freetalk/FTMessageManager.java
>    trunk/plugins/Freetalk/WoT/FTIdentityManagerWoT.java
>    trunk/plugins/Freetalk/WoT/FTMessageManagerWoT.java
> Log:
> Proper threading.
> 
> Modified: trunk/plugins/Freetalk/FTIdentityManager.java
> ===================================================================
> --- trunk/plugins/Freetalk/FTIdentityManager.java     2008-11-07 22:37:11 UTC 
(rev 23395)
> +++ trunk/plugins/Freetalk/FTIdentityManager.java     2008-11-07 23:28:39 UTC 
(rev 23396)
> @@ -20,11 +20,9 @@
>       protected final ObjectContainer db;
>  
>       protected final Executor mExecutor;
> -     
> -     public boolean isRunning = true;
>  
>       public FTIdentityManager(ObjectContainer myDB, Executor myExecutor) {
> -             Logger.debug(this, "Starting identity manager...");
> +             Logger.debug(this, "Creating identity manager...");
>               db = myDB;
>               mExecutor = myExecutor;
>               mExecutor.execute(this, "FT Identity Manager");
> @@ -53,4 +51,6 @@
>       }
>       
>       public abstract void run();
> +     
> +     public abstract void terminate();
>  }
> 
> Modified: trunk/plugins/Freetalk/FTMessageManager.java
> ===================================================================
> --- trunk/plugins/Freetalk/FTMessageManager.java      2008-11-07 22:37:11 UTC 
(rev 23395)
> +++ trunk/plugins/Freetalk/FTMessageManager.java      2008-11-07 23:28:39 UTC 
(rev 23396)
> @@ -77,4 +77,6 @@
>       protected synchronized boolean shouldDownloadMessage(FreenetURI uri, 
FTIdentity author) {
>               return (get(uri) != null) || 
mIdentityManager.anyOwnIdentityWantsMessagesFrom(author);
>       }
> +     
> +     public abstract void terminate();
>  }
> 
> Modified: trunk/plugins/Freetalk/WoT/FTIdentityManagerWoT.java
> ===================================================================
> --- trunk/plugins/Freetalk/WoT/FTIdentityManagerWoT.java      2008-11-07 
> 22:37:11 
UTC (rev 23395)
> +++ trunk/plugins/Freetalk/WoT/FTIdentityManagerWoT.java      2008-11-07 
> 23:28:39 
UTC (rev 23396)
> @@ -30,6 +30,9 @@
>       private static final int THREAD_PERIOD = 5 * 60 * 1000;
>       
>       private WoT mWoT;
> +     
> +     private boolean isRunning = true;
> +     private Thread mThread;
>  
>       /**
>        * @param executor
> @@ -37,7 +40,7 @@
>       public FTIdentityManagerWoT(ObjectContainer myDB, Executor executor, 
> WoT 
newWoT) {
>               super(myDB, executor);
>               mWoT = newWoT;
> -             Logger.debug(this, "Identity manager started.");
> +             Logger.debug(this, "Identity manager created.");
>       }
>       
>       private void receiveIdentities() throws InvalidParameterException {
> @@ -117,6 +120,7 @@
>       @Override
>       public void run() {
>               Logger.debug(this, "Identity manager running.");
> +             mThread = Thread.currentThread();
>               
>               try {
>                       Logger.debug(this, "Waiting for the node to start 
> up...");
> @@ -143,4 +147,15 @@
>                       } catch (InterruptedException e) { }
>               }
>       }
> +     
> +     public void terminate() {
> +             Logger.debug(this, "Stopping the identity manager...");
> +             isRunning = false;
> +             mThread.interrupt();
> +             try {
> +                     mThread.join();
> +             }
> +             catch(InterruptedException e) { }
> +             Logger.debug(this, "Stopped the indentity manager.");
> +     }
>  }
> 
> Modified: trunk/plugins/Freetalk/WoT/FTMessageManagerWoT.java
> ===================================================================
> --- trunk/plugins/Freetalk/WoT/FTMessageManagerWoT.java       2008-11-07 
> 22:37:11 
UTC (rev 23395)
> +++ trunk/plugins/Freetalk/WoT/FTMessageManagerWoT.java       2008-11-07 
> 23:28:39 
UTC (rev 23396)
> @@ -7,6 +7,7 @@
>  
>  import plugins.Freetalk.FTBoard;
>  import plugins.Freetalk.FTMessageManager;
> +import plugins.WoT.exceptions.InvalidParameterException;
>  
>  import com.db4o.ObjectContainer;
>  
> @@ -17,7 +18,13 @@
>  
>  public class FTMessageManagerWoT extends FTMessageManager {
>       
> -     protected FTIdentityManagerWoT mIdentityManager;
> +     /* FIXME: This really has to be tweaked before release. I set it quite 
short for debugging */
> +     private static final int THREAD_PERIOD = 5 * 60 * 1000;
> +     
> +     private FTIdentityManagerWoT mIdentityManager;
> +     
> +     private boolean isRunning = true;
> +     private Thread mThread;
>  
>       public FTMessageManagerWoT(ObjectContainer myDB, Executor myExecutor, 
FTIdentityManagerWoT myIdentityManager) {
>               super(myDB, myExecutor, myIdentityManager);
> @@ -52,6 +59,33 @@
>       }
>       
>       public void run() {
> +             Logger.debug(this, "Message manager running.");
> +             mThread = Thread.currentThread();
>               
> +             try {
> +                     Logger.debug(this, "Waiting for the node to start 
> up...");
> +                     Thread.sleep((long) (3*60*1000 * (0.5f + 
> Math.random()))); /* Let the 
node start up */
> +             } catch (InterruptedException e) { }
> +             
> +             while(isRunning) {
> +                     Logger.debug(this, "Message manager loop running...");
> +
> +                     Logger.debug(this, "Message manager loop finished.");
> +
> +                     try {
> +                             Thread.sleep((long) (THREAD_PERIOD * (0.5f + 
> Math.random())));
> +                     } catch (InterruptedException e) { }
> +             }
>       }
> +     
> +     public void terminate() {
> +             Logger.debug(this, "Stopping the message manager..."); 
> +             isRunning = false;
> +             mThread.interrupt();
> +             try {
> +                     mThread.join();
> +             }
> +             catch(InterruptedException e) { }
> +             Logger.debug(this, "Stopped the message manager.");
> +     }
>  }
> 
> _______________________________________________
> 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: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: not available
URL: 
<https://emu.freenetproject.org/pipermail/devl/attachments/20081112/5aba5059/attachment.pgp>

Reply via email to