Author: nextgens
Date: 2006-05-21 15:30:05 +0000 (Sun, 21 May 2006)
New Revision: 8821

Modified:
   trunk/freenet/src/freenet/node/NodeUpdater.java
Log:
Workaround the UserAlert unregistering problem.

and NO, those alerts shouldn't be cancelable imho

Modified: trunk/freenet/src/freenet/node/NodeUpdater.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeUpdater.java     2006-05-21 15:13:29 UTC 
(rev 8820)
+++ trunk/freenet/src/freenet/node/NodeUpdater.java     2006-05-21 15:30:05 UTC 
(rev 8821)
@@ -97,15 +97,20 @@
 }

 class UpdatedVersionAvailableUserAlert implements UserAlert {
-       private boolean isValid=true;
+       private boolean isValid;
        private int version;

        UpdatedVersionAvailableUserAlert(int version){
                this.version=version;
+               isValid=false;
        }

+       public synchronized void set(int v){
+               version = v;
+       }
+       
        public boolean userCanDismiss() {
-               return true;
+               return false;
        }

        public String getTitle() {
@@ -126,7 +131,7 @@
        }

        public void isValid(boolean b){
-               if(userCanDismiss()) isValid=b;
+               isValid=b;
        }
 }

@@ -146,19 +151,22 @@

        public final boolean isAutoUpdateAllowed;

-       private UpdatedVersionAvailableUserAlert alert;
+       private final UpdatedVersionAvailableUserAlert alert;

        public NodeUpdater(Node n, boolean isAutoUpdateAllowed, FreenetURI URI) 
{
                super();
                this.URI = URI;
                this.node = n;
                this.currentVersion = Version.buildNumber();
-               this.availableVersion = Version.buildNumber();
+               this.availableVersion = currentVersion;
                this.hasBeenBlown = false;
                this.isRunning = true;
                this.isAutoUpdateAllowed = isAutoUpdateAllowed;
-               this.alert=null;

+               this.alert= new 
UpdatedVersionAvailableUserAlert(currentVersion);
+               alert.isValid(false);
+               node.alerts.register(alert);
+               
                FetcherContext ctx = 
n.makeClient((short)0).getFetcherContext();                
                ctx.allowSplitfiles = true;
                ctx.dontEnterImplicitArchives = false;
@@ -179,25 +187,17 @@
                }
        }

-       public void onFoundEdition(long l, USK key){
+       public synchronized void onFoundEdition(long l, USK key){
                // FIXME : Check if it has been blown
                int found = (int)key.suggestedEdition;

                if(found > availableVersion){
                        this.availableVersion = found;
-                       
-                       synchronized(this){
-                               Logger.normal(this, "Found a new version!, 
setting up a new UpdatedVersionAvailableUserAlert");
-                               
-                               if(alert != null){
-                                       System.out.println("unregistering 
"+alert.hashCode()+":"+alert);
-                                       node.alerts.unregister(alert);
-                               }
-                               alert = new 
UpdatedVersionAvailableUserAlert(availableVersion);
-                               System.out.println("registering 
"+alert.hashCode()+":"+alert);
-                               node.alerts.register(new 
UpdatedVersionAvailableUserAlert(availableVersion));
-                       }
-                       
+
+                       Logger.normal(this, "Found a new version!, setting up a 
new UpdatedVersionAviableUserAlert");
+                       alert.set(availableVersion);
+                       alert.isValid(true);
+
                        maybeUpdate();
                }
        }


Reply via email to