You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2006/08/28 15:15:14 UTC
svn commit: r437696 - in /tapestry/tapestry5/tapestry-core/trunk/src:
main/java/org/apache/tapestry/internal/services/
test/java/org/apache/tapestry/integration/app1/components/
test/resources/org/apache/tapestry/integration/app1/pages/
Author: hlship
Date: Mon Aug 28 06:15:11 2006
New Revision: 437696
URL: http://svn.apache.org/viewvc?rev=437696&view=rev
Log:
Add filter that checks for class and resource file updates.
Added:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/CheckForUpdatesFilter.java
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalModule.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/components/HelloWorld.java
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/Start.html
Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/CheckForUpdatesFilter.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/CheckForUpdatesFilter.java?rev=437696&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/CheckForUpdatesFilter.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/CheckForUpdatesFilter.java Mon Aug 28 06:15:11 2006
@@ -0,0 +1,75 @@
+// Copyright 2006 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.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry.internal.services;
+
+import java.io.IOException;
+
+import org.apache.tapestry.internal.annotations.Concurrent;
+import org.apache.tapestry.services.WebRequest;
+import org.apache.tapestry.services.WebRequestFilter;
+import org.apache.tapestry.services.WebRequestHandler;
+import org.apache.tapestry.services.WebResponse;
+
+/**
+ * Implements a barrier that periodically asks the
+ * {@link org.apache.tapestry.internal.services.UpdateListenerHub} to check for updates to files.
+ * The UpdateListenerHub is invoked from a write method, meaning that when it is called, all other
+ * threads will be blocked.
+ *
+ * @author Howard M. Lewis Ship
+ */
+@Concurrent
+public class CheckForUpdatesFilter implements WebRequestFilter
+{
+ private long _lastCheck = 0;
+
+ private long _checkInterval = 10; // ms
+
+ private final UpdateListenerHub _updateListenerHub;
+
+ public CheckForUpdatesFilter(UpdateListenerHub updateListenerHub)
+ {
+ _updateListenerHub = updateListenerHub;
+ }
+
+ @Concurrent.Read
+ public boolean service(WebRequest request, WebResponse response, WebRequestHandler handler)
+ throws IOException
+ {
+ if (System.currentTimeMillis() - _lastCheck >= _checkInterval)
+ runCheck();
+
+ return handler.service(request, response);
+ }
+
+ /** The write lock ensures that only a single thread is active, all others are blocked. */
+ @Concurrent.Write
+ private void runCheck()
+ {
+ // On a race condition, multiple threads may hit this method briefly. If we've already
+ // done a check, don't run it again.
+
+ if (System.currentTimeMillis() - _lastCheck < _checkInterval)
+ return;
+
+ // Fire the update event which will force a number of checks and then corresponding
+ // invalidation events.
+
+ _updateListenerHub.fireUpdateEvent();
+
+ _lastCheck = System.currentTimeMillis();
+ }
+
+}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalModule.java?rev=437696&r1=437695&r2=437696&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalModule.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalModule.java Mon Aug 28 06:15:11 2006
@@ -33,6 +33,7 @@
import org.apache.tapestry.services.ComponentClassTransformWorker;
import org.apache.tapestry.services.MarkupWriterFactory;
import org.apache.tapestry.services.TransformConstants;
+import org.apache.tapestry.services.WebRequestFilter;
/**
* @author Howard M. Lewis Ship
@@ -101,7 +102,9 @@
return new TemplateParserImpl();
}
- public PageElementFactory buildPageElementFactory(@InjectService("tapestry.ComponentClassResolver") ComponentClassResolver resolver)
+ public PageElementFactory buildPageElementFactory(
+ @InjectService("tapestry.ComponentClassResolver")
+ ComponentClassResolver resolver)
{
return new PageElementFactoryImpl(_componentInstantiatorSource, resolver);
}
@@ -190,5 +193,18 @@
MarkupWriterFactory markupWriterFactory)
{
return new PageResponseRendererImpl(markupWriterFactory);
+ }
+
+ /**
+ * Adds a filter that checks for updates to classes and other resources. It is ordered
+ * before:*.*.
+ */
+ @Contribute("tapestry.WebRequestHandler")
+ public void contributeWebRequestFilters(OrderedConfiguration<WebRequestFilter> configuration)
+ {
+ configuration.add(
+ "CheckForUpdates",
+ new CheckForUpdatesFilter(_updateListenerHub),
+ "before:*.*");
}
}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/components/HelloWorld.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/components/HelloWorld.java?rev=437696&r1=437695&r2=437696&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/components/HelloWorld.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/components/HelloWorld.java Mon Aug 28 06:15:11 2006
@@ -24,6 +24,14 @@
@RenderTag
void renderMessage(MarkupWriter writer)
{
- writer.write("Hello from this Tapestry 5 Component!");
+ writer.write("I Am HelloWorld");
+ }
+
+ @RenderTag
+ void renderExtra(MarkupWriter writer)
+ {
+ writer.element("strong");
+ writer.write("Yow!");
+ writer.end();
}
}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/Start.html
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/Start.html?rev=437696&r1=437695&r2=437696&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/Start.html (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/Start.html Mon Aug 28 06:15:11 2006
@@ -5,6 +5,7 @@
<body> This is the <span style="color:green">First Tapestry 5 Page, ever!</span>.
<p>
- And now, a message from our sponsor: <t:comp id="foo" type="HelloWorld"/>
+ Output from HelloWorld component:
+ <t:comp id="foo" type="HelloWorld"/>
</p></body>
</html>