You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2005/04/22 15:54:31 UTC

svn commit: r164239 - in /cocoon/trunk/src: java/org/apache/cocoon/components/flow/ java/org/apache/cocoon/generation/ webapp/samples/ webapp/stylesheets/system/

Author: reinhard
Date: Fri Apr 22 06:54:29 2005
New Revision: 164239

URL: http://svn.apache.org/viewcvs?rev=164239&view=rev
Log:
show continuations tree in status, fix small bug in StatusGenerator that produced not-wellformed XML

Added:
    cocoon/trunk/src/java/org/apache/cocoon/components/flow/WebContinuationDataBean.java
Modified:
    cocoon/trunk/src/java/org/apache/cocoon/components/flow/ContinuationsManager.java
    cocoon/trunk/src/java/org/apache/cocoon/components/flow/ContinuationsManagerImpl.java
    cocoon/trunk/src/java/org/apache/cocoon/generation/StatusGenerator.java
    cocoon/trunk/src/webapp/samples/samples.xml
    cocoon/trunk/src/webapp/samples/sitemap.xmap
    cocoon/trunk/src/webapp/stylesheets/system/status2html.xslt

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/flow/ContinuationsManager.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/flow/ContinuationsManager.java?rev=164239&r1=164238&r2=164239&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/flow/ContinuationsManager.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/flow/ContinuationsManager.java Fri Apr 22 06:54:29 2005
@@ -15,6 +15,8 @@
  */
 package org.apache.cocoon.components.flow;
 
+import java.util.List;
+
 /**
  * The interface of the Continuations manager.
  *
@@ -89,4 +91,9 @@
      * @see WebContinuation#display()
      */
     public void displayAllContinuations();
+    
+    /**
+     * Get a list of all continuations as <code>WebContinuationDataBean</code> objects. 
+     */
+    public List getWebContinuationsDataBeanList();
 }

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/flow/ContinuationsManagerImpl.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/flow/ContinuationsManagerImpl.java?rev=164239&r1=164238&r2=164239&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/flow/ContinuationsManagerImpl.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/flow/ContinuationsManagerImpl.java Fri Apr 22 06:54:29 2005
@@ -16,6 +16,7 @@
 package org.apache.cocoon.components.flow;
 
 import java.security.SecureRandom;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -45,6 +46,7 @@
 import org.apache.cocoon.environment.Request;
 import org.apache.cocoon.environment.Session;
 
+
 /**
  * The default implementation of {@link ContinuationsManager}. <br/>There are
  * two modes of work: <br/>
@@ -181,6 +183,17 @@
 
         return wk;
     }
+    
+    /**
+     * Get a list of all web continuations (data only)
+     */
+    public List getWebContinuationsDataBeanList() {
+        List beanList = new ArrayList();
+        for(Iterator it = this.forest.iterator(); it.hasNext();) {
+            beanList.add(new WebContinuationDataBean((WebContinuation) it.next()));
+        }
+        return beanList;
+    }
 
     public WebContinuation lookupWebContinuation(String id, String interpreterId) {
         // REVISIT: Is the following check needed to avoid threading issues:
@@ -480,7 +493,7 @@
      * A holder for WebContinuations. When bound to session notifies the
      * continuations manager of session invalidation.
      */
-    private class WebContinuationsHolder implements HttpSessionBindingListener {
+    public class WebContinuationsHolder implements HttpSessionBindingListener {
         private final static String CONTINUATIONS_HOLDER = 
                                        "o.a.c.c.f.SCMI.WebContinuationsHolder";
 

Added: cocoon/trunk/src/java/org/apache/cocoon/components/flow/WebContinuationDataBean.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/flow/WebContinuationDataBean.java?rev=164239&view=auto
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/flow/WebContinuationDataBean.java (added)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/flow/WebContinuationDataBean.java Fri Apr 22 06:54:29 2005
@@ -0,0 +1,93 @@
+/*
+ * Copyright 1999-2005 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.cocoon.components.flow;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Access to continuation data for monitoring applications
+ */
+public class WebContinuationDataBean {
+
+    private static final String TYPE_JAVAFLOW = "javaflow";
+    private static final String TYPE_FLOWSCRIPT = "flowscript";
+    private static final String HAS_EXPIRED_NO = "no";
+    private static final String HAS_EXPIRED_YES = "yes";
+
+    private WebContinuation wc;
+    private SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
+    private List _children = new ArrayList();
+
+    public WebContinuationDataBean(WebContinuation wc) {
+        this.wc = wc;
+        for (Iterator it = wc.getChildren().iterator(); it.hasNext();) {
+            WebContinuationDataBean child = new WebContinuationDataBean(
+                    (WebContinuation) it.next());
+            this._children.add(child);
+        }
+    }
+
+    public String getId() {
+        return wc.getId();
+    }
+
+    public String getLastAccessTime() {
+        return formatter.format(new Date(wc.getLastAccessTime()));
+    }
+
+    public String getInterpreterId() {
+        return wc.getInterpreterId();
+    }
+
+    public String getTimeToLiveInMinutes() {
+        return Long.toString(wc.getTimeToLive() / 1000 / 60);
+    }
+
+    public String getTimeToLive() {
+        return Long.toString(wc.getTimeToLive());
+    }
+
+    public String getExpireTime() {
+        return formatter.format(new Date(wc.getLastAccessTime()
+                + wc.getTimeToLive()));
+    }
+
+    public String hasExpired() {
+        if ((wc.getLastAccessTime() + wc.getTimeToLive()) < System
+                .currentTimeMillis()) {
+            return HAS_EXPIRED_YES;
+        }
+        return HAS_EXPIRED_NO;
+
+    }
+
+    public String getType() {
+        if (wc.getUserObject().getClass().getName().indexOf(
+                "FOM_WebContinuation") > 0) {
+            return TYPE_FLOWSCRIPT;
+        }
+        return TYPE_JAVAFLOW;
+    }
+
+    public List get_children() {
+        return this._children;
+    }
+
+}

Modified: cocoon/trunk/src/java/org/apache/cocoon/generation/StatusGenerator.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/generation/StatusGenerator.java?rev=164239&r1=164238&r2=164239&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/generation/StatusGenerator.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/generation/StatusGenerator.java Fri Apr 22 06:54:29 2005
@@ -15,6 +15,7 @@
  */
 package org.apache.cocoon.generation;
 
+import java.io.IOException;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.text.DateFormat;
@@ -27,11 +28,24 @@
 import java.util.Properties;
 import java.util.StringTokenizer;
 
+import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.cocoon.Constants;
+<<<<<<< .mine
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.components.flow.ContinuationsManager;
+import org.apache.cocoon.components.flow.WebContinuationDataBean;
+import org.apache.cocoon.configuration.Settings;
+=======
+>>>>>>> .r164238
 import org.apache.cocoon.core.Core;
+<<<<<<< .mine
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.generation.ServiceableGenerator;
+=======
 import org.apache.cocoon.core.Settings;
+>>>>>>> .r164238
 import org.apache.commons.lang.SystemUtils;
 import org.apache.excalibur.store.Store;
 import org.apache.excalibur.store.StoreJanitor;
@@ -60,7 +74,7 @@
  *     cocoon-version CDATA #IMPLIED
  * &gt;
  *
- * &lt;!ELEMENT group (group|value)*&gt;
+ * &lt;!ELEMENT group (group|value|cont)*&gt;
  * &lt;!ATTLIST group
  *     name CDATA #IMPLIED
  * &gt;
@@ -79,9 +93,10 @@
  * @author <a href="mailto:g-froehlich@gmx.de">Gerhard Froehlich</a>
  * @version $Id$
  */
-public class StatusGenerator 
-    extends ServiceableGenerator {
+public class StatusGenerator extends ServiceableGenerator {
 
+    private static final String SHOW_CONTINUATIONS_INFO = "show-cont";    
+    
     /**
      * The StoreJanitor used to get cache statistics
      */
@@ -89,22 +104,31 @@
     protected Store store_persistent;
 
     /**
+     * The ContinuationManager
+     */
+    protected ContinuationsManager continuationsManager;
+    
+    /**
+     * add infos about continuations?
+     */
+    protected boolean showContinuationsInformation = false;
+    
+    /**
      * The XML namespace for the output document.
      */
-    protected static final String namespace =
-        "http://apache.org/cocoon/status/2.0";
+    protected static final String namespace =  "http://apache.org/cocoon/status/2.0";
 
     /**
      * The XML namespace for xlink
      */
-    protected static final String xlinkNamespace =
-        "http://www.w3.org/1999/xlink";
+    protected static final String xlinkNamespace = "http://www.w3.org/1999/xlink";
 
     /**
      * The namespace prefix for xlink namespace
      */
     protected static final String xlinkPrefix = "xlink";
 
+
     /**
      * Set the current <code>ServiceManager</code> instance used by this
      * <code>Serviceable</code>.
@@ -122,11 +146,13 @@
         } else {
             getLogger().info("Persistent Store is not available. Sorry no cache statistics about it.");
         }
+        if(this.manager.hasService(ContinuationsManager.ROLE)) {
+            continuationsManager = (ContinuationsManager) this.manager.lookup(ContinuationsManager.ROLE);
+        } else {
+            getLogger().info("ContinuationsManager is not available. Sorry no overview of created continuations");
+        }
     }
 
-    /* (non-Javadoc)
-     * @see org.apache.avalon.framework.activity.Disposable#dispose()
-     */
     public void dispose() {
         if (this.manager != null) {
             this.manager.release(this.store_persistent);
@@ -136,6 +162,13 @@
         }
         super.dispose();
     }
+    
+    
+    public void setup(SourceResolver resolver, Map objectModel, String src, Parameters parameters) 
+        throws ProcessingException, SAXException, IOException {
+        super.setup(resolver, objectModel, src, parameters);
+        this.showContinuationsInformation = parameters.getParameterAsBoolean(SHOW_CONTINUATIONS_INFO, false);
+    }
 
     /** Generate the status information in XML format.
      * @throws SAXException
@@ -181,16 +214,44 @@
         atts.addAttribute(namespace, "host", "host", "CDATA", localHost);
         atts.addAttribute(namespace, "cocoon-version", "cocoon-version", "CDATA", Constants.VERSION);
         this.xmlConsumer.startElement(namespace, "statusinfo", "statusinfo", atts);
-
+        
+        if(this.showContinuationsInformation) {
+            genContinuationsTree();        
+        }  
         genSettings();
         genVMStatus();
-
         genProperties();
-
+      
         // End root element.
         this.xmlConsumer.endElement(namespace, "statusinfo", "statusinfo");
     }
 
+    private void genContinuationsTree() throws SAXException {
+        startGroup("Continuations");
+        List continuationsAsDataBeansList = this.continuationsManager.getWebContinuationsDataBeanList();
+        for(Iterator it = continuationsAsDataBeansList.iterator(); it.hasNext();) {
+            displayContinuation((WebContinuationDataBean) it.next());
+        }
+        endGroup();
+    }
+    
+
+    private void displayContinuation(WebContinuationDataBean wc) throws SAXException {
+        AttributesImpl ai = new AttributesImpl(); 
+        ai.addAttribute(namespace, "id", "id", "CDATA", wc.getId());
+        ai.addAttribute(namespace, "interpreter", "interpreter", "CDATA", wc.getInterpreterId());
+        ai.addAttribute(namespace, "expire-time", "expire-time", "CDATA", wc.getExpireTime());
+        ai.addAttribute(namespace, "time-to-live", "time-to-live", "CDATA", wc.getTimeToLive());
+        ai.addAttribute(namespace, "last-access-time", "last-access-time", "CDATA", wc.getLastAccessTime());   
+
+        this.xmlConsumer.startElement(namespace, "cont", "cont", ai);
+        List children = wc.get_children();
+        for (int i = 0; i < children.size(); i++) {
+            displayContinuation((WebContinuationDataBean) children.get(i));
+        }        
+        this.xmlConsumer.endElement(namespace, "cont", "cont");
+    }       
+    
     private void genVMStatus() throws SAXException {
         AttributesImpl atts = new AttributesImpl();
 
@@ -234,7 +295,7 @@
 
         // BEGIN Cache
         if (this.storejanitor != null) {
-            startGroup("Store-Janitor");
+            startGroup("Store-Janitorrrr");
 
             // For each element in StoreJanitor
             Iterator i = this.storejanitor.iterator();
@@ -356,6 +417,9 @@
         this.addValue(Settings.KEY_SHOWTIME, s.isShowTime());
         this.addValue(Settings.KEY_HIDE_SHOWTIME, s.isHideShowTime());
         this.addValue(Settings.KEY_LAZY_MODE, s.isLazyMode());
+        
+        this.endGroup();
+        
     }
 
     private void genProperties() throws SAXException {

Modified: cocoon/trunk/src/webapp/samples/samples.xml
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/webapp/samples/samples.xml?rev=164239&r1=164238&r2=164239&view=diff
==============================================================================
--- cocoon/trunk/src/webapp/samples/samples.xml (original)
+++ cocoon/trunk/src/webapp/samples/samples.xml Fri Apr 22 06:54:29 2005
@@ -113,6 +113,14 @@
       This page shows the current internal status of cocoon, along with
       information on the cache and the object stores.
     </sample>
+    <sample name="Status Page (with continuations)" href="status-with-continuations.html">
+      This page shows the current internal status of cocoon, along with
+      information on the cache and the object stores and the continuations.
+    </sample>    
+    <sample name="Status Page (with continuations - XML)" href="status-with-continuations.xml">
+      This page shows the current internal status of cocoon, along with
+      information on the cache and the object stores and the continuations.
+    </sample>        
     <sample name="Clear Cache" href="clearcache.html">
       Empties the Cocoon in-memory cache.
     </sample>

Modified: cocoon/trunk/src/webapp/samples/sitemap.xmap
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/webapp/samples/sitemap.xmap?rev=164239&r1=164238&r2=164239&view=diff
==============================================================================
--- cocoon/trunk/src/webapp/samples/sitemap.xmap (original)
+++ cocoon/trunk/src/webapp/samples/sitemap.xmap Fri Apr 22 06:54:29 2005
@@ -137,12 +137,27 @@
       </map:match>
 
       <map:match pattern="status.html">
-        <map:generate src="status" type="status"/>
+        <map:generate type="status"/>
         <map:transform src="context://stylesheets/system/status2html.xslt">
           <map:parameter name="contextPath" value="{request:contextPath}"/>
         </map:transform>
         <map:serialize/>
       </map:match>
+
+      <map:match pattern="status-with-continuations.xml">
+        <map:generate type="status">
+					<map:parameter name="show-cont" value="true"/>
+        </map:generate>
+        <map:serialize type="xml"/>
+      </map:match>     
+      
+      <map:match pattern="status-with-continuations.html">
+        <map:generate src="cocoon:/status-with-continuations.xml"/>
+        <map:transform src="context://stylesheets/system/status2html.xslt">
+          <map:parameter name="contextPath" value="{request:contextPath}"/>
+        </map:transform>
+        <map:serialize/>
+      </map:match>      
 
       <map:match pattern="clearcache.html">
         <map:act type="clear-cache">

Modified: cocoon/trunk/src/webapp/stylesheets/system/status2html.xslt
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/webapp/stylesheets/system/status2html.xslt?rev=164239&r1=164238&r2=164239&view=diff
==============================================================================
--- cocoon/trunk/src/webapp/stylesheets/system/status2html.xslt (original)
+++ cocoon/trunk/src/webapp/stylesheets/system/status2html.xslt Fri Apr 22 06:54:29 2005
@@ -47,6 +47,25 @@
     <h2><xsl:value-of select="@status:name"/></h2>
     <ul><xsl:apply-templates select="status:value"/></ul>
     <xsl:apply-templates select="status:group"/>
+    <xsl:if test="status:cont">
+    	<ul>
+    		<xsl:apply-templates select="status:cont"/>    	
+    	</ul>
+    </xsl:if>
+  </xsl:template>
+  
+  <xsl:template match="status:cont">
+  	<li>
+  		<xsl:for-each select="@*">
+  			<span class="description"><xsl:value-of select="name()"/>:<xsl:text> </xsl:text> </span><xsl:value-of select="."/>
+  			<xsl:if test="position() != last()">, </xsl:if>
+  		</xsl:for-each>
+  	</li>
+    <xsl:if test="status:cont">
+    	<ul>
+    		<xsl:apply-templates select="status:cont"/>    	
+    	</ul>  	
+    </xsl:if>
   </xsl:template>
 
   <xsl:template match="status:value">