Author: toad
Date: 2007-06-01 20:05:01 +0000 (Fri, 01 Jun 2007)
New Revision: 13456

Modified:
   trunk/freenet/src/freenet/io/comm/MessageFilter.java
Log:
Allow to make timeout relative to setTimeout() if that's what the caller wants, 
but default is relative to waitFor()

Modified: trunk/freenet/src/freenet/io/comm/MessageFilter.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/MessageFilter.java        2007-06-01 
19:52:49 UTC (rev 13455)
+++ trunk/freenet/src/freenet/io/comm/MessageFilter.java        2007-06-01 
20:05:01 UTC (rev 13456)
@@ -41,6 +41,9 @@
     private Vector _fieldList = new Vector(1,1);
     PeerContext _source;
     private long _timeout;
+    /** If true, timeouts are relative to the start of waiting, if false, they 
are relative to
+     * the creation of the filter */
+    private boolean _timeoutFromWait;
     private int _initialTimeout;
     private MessageFilter _or;
     private Message _message;
@@ -52,6 +55,7 @@
         setTimeout(DEFAULT_TIMEOUT);
         _matchesDroppedConnections = true; // on by default
         _matchesRestartedConnections = true; // also on by default
+        _timeoutFromWait = true;
     }

     public static MessageFilter create() {
@@ -60,7 +64,7 @@

     void onStartWaiting() {
        synchronized(this) {
-               if(_initialTimeout > 0)
+               if(_initialTimeout > 0 && _timeoutFromWait)
                        _timeout = System.currentTimeMillis() + _initialTimeout;
        }
        if(_or != null)
@@ -68,6 +72,17 @@
     }

     /**
+     * Set whether the timeout is relative to the creation of the filter, or 
the start of
+     * waitFor().
+     * @param b If true, the timeout is relative to the time at which 
setTimeout() was called,
+     * if false, it's relative to the start of waitFor().
+     */
+    public MessageFilter setTimeoutRelativeToCreation(boolean b) {
+       _timeoutFromWait = !b;
+       return this;
+    }
+    
+    /**
      * This filter will expire after the specificed amount of time. Note also 
that where two or more filters match the
      * same message, the one with the nearer expiry time will get priority
      *


Reply via email to