Return-Path: Delivered-To: apmail-xml-cocoon-dev-archive@xml.apache.org Received: (qmail 37899 invoked by uid 500); 8 Dec 2001 13:12:46 -0000 Mailing-List: contact cocoon-dev-help@xml.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: cocoon-dev@xml.apache.org Delivered-To: mailing list cocoon-dev@xml.apache.org Received: (qmail 37884 invoked from network); 8 Dec 2001 13:12:46 -0000 From: "Gerhard Froehlich" To: "cocoon-Dev" Subject: [PATCH] Added Resource Monitor in ProgramGeneratorImpl Date: Sat, 8 Dec 2001 14:12:40 +0100 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0003_01C17FF2.653E9D20" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Importance: Normal X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N ------=_NextPart_000_0003_01C17FF2.653E9D20 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hi, as promised I started to implement the Excalibur ActiveMonitor in Cocoon to increase our performance. I started at the ProgramGeneratorImpl and this Patch contains the first draft. Every 10sec the ActiveMonitor checks if the Sitemap has changed. Please review it and give me some feedback! Berin: How about a additional URIResource in the monitor package? Cheers Gerhard ----------------------------------------- All my life I wanted to be someone; I guess I should have been more specific. (Jane Wagner) ----------------------------------------- ------=_NextPart_000_0003_01C17FF2.653E9D20 Content-Type: application/octet-stream; name="patch.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="patch.diff" Index: src/org/apache/cocoon/cocoon.roles =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: = /home/cvspublic/xml-cocoon2/src/org/apache/cocoon/cocoon.roles,v retrieving revision 1.30 diff -u -r1.30 cocoon.roles --- src/org/apache/cocoon/cocoon.roles 2001/12/07 10:12:10 1.30 +++ src/org/apache/cocoon/cocoon.roles 2001/12/08 12:47:06 @@ -173,4 +173,8 @@ shorthand=3D"reader" = default-class=3D"org.apache.cocoon.sitemap.SitemapComponentSelector"/> =20 + + Index: = src/org/apache/cocoon/components/language/generator/ProgramGeneratorImpl.= java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: = /home/cvspublic/xml-cocoon2/src/org/apache/cocoon/components/language/gen= erator/ProgramGeneratorImpl.java,v retrieving revision 1.23 diff -u -r1.23 ProgramGeneratorImpl.java --- = src/org/apache/cocoon/components/language/generator/ProgramGeneratorImpl.= java 2001/10/30 15:38:21 1.23 +++ = src/org/apache/cocoon/components/language/generator/ProgramGeneratorImpl.= java 2001/12/08 12:47:09 @@ -8,6 +8,8 @@ =20 package org.apache.cocoon.components.language.generator; =20 +import org.apache.avalon.excalibur.monitor.FileResource; +import org.apache.avalon.excalibur.monitor.Monitor; import org.apache.avalon.framework.activity.Disposable; import org.apache.avalon.framework.component.*; import org.apache.avalon.framework.configuration.Configurable; @@ -31,9 +33,13 @@ import org.apache.cocoon.environment.Source; import org.apache.cocoon.environment.SourceResolver; import org.apache.cocoon.util.IOUtils; +import org.apache.cocoon.util.NetUtils; import org.xml.sax.InputSource; =20 +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeEvent; import java.io.File; +import java.net.URL; import java.net.MalformedURLException; =20 /** @@ -42,7 +48,8 @@ * @version CVS $Revision: 1.23 $ $Date: 2001/10/30 15:38:21 $ */ public class ProgramGeneratorImpl extends AbstractLoggable - implements ProgramGenerator, Contextualizable, Composable, = Configurable, ThreadSafe, Disposable { + implements ProgramGenerator, Contextualizable, Composable, = Configurable, ThreadSafe,=20 + Disposable, PropertyChangeListener { =20 /** The auto-reloading option */ protected boolean autoReload =3D false; @@ -77,6 +84,15 @@ /** Servlet Context Directory */ protected String contextDir; =20 + /** Resource monitoring */ + protected Monitor monitor; + + /** lastModified date */ + protected long lastModified; + + /** File resource */ + protected FileResource file; + /** Contextualize this class */ public void contextualize(Context context) throws ContextException = { if (this.workDir =3D=3D null) { @@ -111,6 +127,7 @@ this.markupSelector =3D = (ComponentSelector)this.manager.lookup(MarkupLanguage.ROLE + = "Selector"); this.languageSelector =3D = (ComponentSelector)this.manager.lookup(ProgrammingLanguage.ROLE + = "Selector"); this.classManager =3D = (ClassLoaderManager)this.manager.lookup(ClassLoaderManager.ROLE); + this.monitor =3D (Monitor) = this.manager.lookup(Monitor.ROLE); } catch (Exception e) { getLogger().warn("Could not lookup Component", e); } @@ -145,6 +162,15 @@ throws Exception { =20 Source source =3D resolver.resolve(fileName); + =20 + /** Monitoring the Sitemap source */ + URL url =3D new URL(source.getSystemId()); + getLogger().debug("Sitemap path=3D" + url.getFile()); + file =3D new FileResource(url.getFile()); + file.addPropertyChangeListener(this); + monitor.addResource(file); + getLogger().debug("lastModified date=3D" + = this.getLastModified()); + =20 try { // Set filenames StringBuffer contextFilename =3D new = StringBuffer(this.rootPackage.replace('.', File.separatorChar)); @@ -200,7 +226,7 @@ * be queried for changes!!! */ =20 - if (programInstance !=3D null && = programInstance.modifiedSince(source.getLastModified())) { + if (programInstance !=3D null && = programInstance.modifiedSince(this.getLastModified())) { // Release the component. release(programInstance); =20 @@ -363,5 +389,17 @@ this.manager.release((Component)this.repository); this.manager.release((Component)this.markupSelector); this.manager.release((Component)this.languageSelector); + } + + public void propertyChange(PropertyChangeEvent evt) { + setLastModified(((Long)evt.getNewValue()).longValue()); + } + + private void setLastModified(long _lastModified) { + lastModified =3D _lastModified; + } + + private long getLastModified() { + return lastModified; } } Index: webapp/cocoon.xconf =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/cvspublic/xml-cocoon2/webapp/cocoon.xconf,v retrieving revision 1.42 diff -u -r1.42 cocoon.xconf --- webapp/cocoon.xconf 2001/11/28 08:40:07 1.42 +++ webapp/cocoon.xconf 2001/12/08 12:47:16 @@ -434,6 +434,13 @@ --> =20 + + + + + =20