You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2007/06/24 03:41:31 UTC

svn commit: r550150 - in /tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services: CheckForUpdatesFilter.java InternalModule.java

Author: hlship
Date: Sat Jun 23 18:41:31 2007
New Revision: 550150

URL: http://svn.apache.org/viewvc?view=rev&rev=550150
Log:
TAPESTRY-1571: CheckForUpdatesFilter can cause deadlock

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/CheckForUpdatesFilter.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InternalModule.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/CheckForUpdatesFilter.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/CheckForUpdatesFilter.java?view=diff&rev=550150&r1=550149&r2=550150
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/CheckForUpdatesFilter.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/CheckForUpdatesFilter.java Sat Jun 23 18:41:31 2007
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 2007 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
 package org.apache.tapestry.internal.services;
 
 import java.io.IOException;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.tapestry.internal.util.Holder;
 import org.apache.tapestry.ioc.internal.util.ConcurrentBarrier;
@@ -36,6 +37,8 @@
 
     private final long _checkInterval;
 
+    private final long _updateTimeout;
+
     private final UpdateListenerHub _updateListenerHub;
 
     private final ConcurrentBarrier _barrier = new ConcurrentBarrier();
@@ -65,11 +68,14 @@
      *            invoked, at intervals, to spur the process of detecting changes
      * @param checkInterval
      *            interval, in milliseconds, between checks
+     * @param updateTimeout
+     *            time, in  milliseconds, to wait to obtain update lock.
      */
-    public CheckForUpdatesFilter(UpdateListenerHub updateListenerHub, long checkInterval)
+    public CheckForUpdatesFilter(UpdateListenerHub updateListenerHub, long checkInterval, long updateTimeout)
     {
         _updateListenerHub = updateListenerHub;
         _checkInterval = checkInterval;
+        _updateTimeout = updateTimeout;
     }
 
     public boolean service(final Request request, final Response response,
@@ -82,7 +88,7 @@
             public Boolean invoke()
             {
                 if (System.currentTimeMillis() - _lastCheck >= _checkInterval)
-                    _barrier.withWrite(_checker);
+                    _barrier.tryWithWrite(_checker, _updateTimeout, TimeUnit.MILLISECONDS);
 
                 // And, now, back to code within the read lock.
                 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InternalModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InternalModule.java?view=diff&rev=550150&r1=550149&r2=550150
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InternalModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InternalModule.java Sat Jun 23 18:41:31 2007
@@ -114,6 +114,7 @@
         // one second to make a change, save it, and switch back to the browser.
 
         configuration.add("tapestry.file-check-interval", "1000"); // 1 second
+        configuration.add("tapestry.file-check-update-timeout", "50"); // 50 milliseconds
         configuration.add("tapestry.supported-locales", "en");
         configuration.add("tapestry.default-cookie-max-age", "604800"); // One week
 
@@ -503,10 +504,13 @@
             @Symbol("tapestry.file-check-interval")
             long checkInterval,
 
+            @Symbol("tapestry.file-check-update-timeout")
+            long updateTimeout,
+
             LocalizationSetter localizationSetter)
     {
         configuration.add("CheckForUpdates", new CheckForUpdatesFilter(_updateListenerHub,
-                checkInterval), "before:*");
+                checkInterval, updateTimeout), "before:*");
 
         configuration.add("Localization", new LocalizationFilter(localizationSetter));
     }