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

svn commit: r161499 - in cocoon/trunk/src: java/org/apache/cocoon/components/store/impl/CocoonStoreJanitor.java webapp/WEB-INF/xconf/cocoon-core.xconf

Author: vgritsenko
Date: Fri Apr 15 09:36:03 2005
New Revision: 161499

URL: http://svn.apache.org/viewcvs?view=rev&rev=161499
Log:
Add thread-pool configuration to CocoonStoreJanitor (default: daemon).
Change runnable manager default thread pool block policy to ABORT
(if pool is exausted we don't want the only scheduling thread get busy by executing tasks)

Modified:
    cocoon/trunk/src/java/org/apache/cocoon/components/store/impl/CocoonStoreJanitor.java
    cocoon/trunk/src/webapp/WEB-INF/xconf/cocoon-core.xconf

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/store/impl/CocoonStoreJanitor.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/store/impl/CocoonStoreJanitor.java?view=diff&r1=161498&r2=161499
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/store/impl/CocoonStoreJanitor.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/store/impl/CocoonStoreJanitor.java Fri Apr 15 09:36:03 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * 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.
@@ -15,12 +15,16 @@
  */
 package org.apache.cocoon.components.store.impl;
 
-import org.apache.avalon.framework.CascadingRuntimeException;
+import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.component.Component;
+import org.apache.avalon.framework.parameters.ParameterException;
+import org.apache.avalon.framework.parameters.Parameterizable;
+import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.Serviceable;
-import org.apache.cocoon.components.thread.RunnableManager;
 
+import org.apache.cocoon.components.thread.RunnableManager;
 
 /**
  * The CocoonStoreJanitor class just subclasses the {@link StoreJanitorImpl} to
@@ -30,14 +34,19 @@
  * @author <a href="mailto:giacomo.at.apache.org">Giacomo Pati</a>
  * @version $Id$
  */
-public class CocoonStoreJanitor
-    extends StoreJanitorImpl
-    implements Serviceable
-{
+public class CocoonStoreJanitor extends StoreJanitorImpl
+                                implements Parameterizable, Serviceable, Disposable, Component {
+
     //~ Instance fields --------------------------------------------------------
 
+    /** Name of the thread pool to use. Defaults to 'daemon'. */
+    private String threadPool;
+
     /** Our {@link ServiceManager} */
-    private ServiceManager m_serviceManager;
+    private ServiceManager serviceManager;
+
+    /** Our {@link RunnableManager} */
+    private RunnableManager runnableManager;
 
     /** Flags to ignore memory bursts in the startup */
     private boolean m_firstRun = true;
@@ -47,45 +56,55 @@
 
     //~ Methods ----------------------------------------------------------------
 
+    public void parameterize(Parameters params) throws ParameterException {
+        super.parameterize(params);
+        this.threadPool = params.getParameter("thread-pool", "daemon");
+    }
+
+    /**
+     * Get the <code>RunnableManager</code>
+     *
+     * @param serviceManager The <code>ServiceManager</code>
+     * @throws ServiceException If RunnableManager is not available
+     */
+    public void service(final ServiceManager serviceManager)
+    throws ServiceException {
+        this.serviceManager = serviceManager;
+        this.runnableManager = (RunnableManager) serviceManager.lookup(RunnableManager.ROLE);
+    }
+
+    /**
+     * Release <code>RunnableManager</code>
+     */
+    public void dispose() {
+        this.serviceManager.release(this.runnableManager);
+        this.runnableManager = null;
+        this.serviceManager = null;
+    }
+
     /**
      * The "checker" thread checks if memory is running low in the jvm.
      */
-    public void run(  )
-    {
-        // ignoring memory bursts in the first two invokations
-        if( m_firstRun || m_secondRun )
-        {
-            super.inUse = super.memoryInUse(  );
+    public void run() {
+        // Ignoring memory bursts in the first two invokations
+        if (m_firstRun || m_secondRun) {
+            super.inUse = super.memoryInUse();
             m_secondRun = m_firstRun;
             m_firstRun = false;
         }
 
-        super.checkMemory(  );
+        super.checkMemory();
 
         // Relaunch
-        relaunch( super.interval );
-    }
-
-    /**
-     * Get the <code>ServiceManager</code>
-     *
-     * @param serviceManager The <code>ServiceManager</code>
-     *
-     * @throws ServiceException Should not happen
-     */
-    public void service( final ServiceManager serviceManager )
-        throws ServiceException
-    {
-        m_serviceManager = serviceManager;
+        relaunch(super.interval);
     }
 
     /**
      * Start this instance using a default thread from the
      * <code>RunnableManager</code>
      */
-    public void start(  )
-    {
-        relaunch( 0 );
+    public void start() {
+        relaunch(0);
     }
 
     /**
@@ -93,28 +112,9 @@
      * the<code>RunnableManager</code> with a delay
      *
      * @param delay the delay to apply before next run
-     *
-     * @throws CascadingRuntimeException in case we cannot get a
-     *         <code>RunnableManager</code>
      */
-    private void relaunch( final long delay )
-    {
-        try
-        {
-            if( getLogger(  ).isDebugEnabled(  ) )
-            {
-                getLogger(  ).debug( "(Re-)Start CocoonStoreJaitor" );
-            }
-
-            final RunnableManager runnableManager =
-                (RunnableManager)m_serviceManager.lookup( RunnableManager.ROLE );
-            runnableManager.execute( this, delay, 0 );
-            m_serviceManager.release( runnableManager );
-        }
-        catch( final ServiceException se )
-        {
-            throw new CascadingRuntimeException( "Cannot lookup RunnableManager",
-                                                 se );
-        }
+    private void relaunch(final long delay) {
+        getLogger().debug("(Re-)Start CocoonStoreJaitor");
+        this.runnableManager.execute(this.threadPool, this, delay, 0);
     }
 }

Modified: cocoon/trunk/src/webapp/WEB-INF/xconf/cocoon-core.xconf
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/webapp/WEB-INF/xconf/cocoon-core.xconf?view=diff&r1=161498&r2=161499
==============================================================================
--- cocoon/trunk/src/webapp/WEB-INF/xconf/cocoon-core.xconf (original)
+++ cocoon/trunk/src/webapp/WEB-INF/xconf/cocoon-core.xconf Fri Apr 15 09:36:03 2005
@@ -503,6 +503,11 @@
         | If not specified, defaults to false.
         +-->
     <parameter name="invokegc" value="false"/>
+    <!--+
+        | Name of the thread pool to use.
+        | If not specified, defaults to 'daemon'.
+        +-->
+    <parameter name="thread-pool" value="daemon"/>
 
     <!--+
         | What should be the priority of the cleanup thread?
@@ -675,7 +680,7 @@
         <max-pool-size>5</max-pool-size>
         <min-pool-size>5</min-pool-size>
         <keep-alive-time-ms>60000</keep-alive-time-ms>
-        <block-policy>RUN</block-policy>
+        <block-policy>ABORT</block-policy>
         <shutdown-graceful>false</shutdown-graceful>
         <shutdown-wait-time-ms>-1</shutdown-wait-time-ms>
       </thread-pool>