Author: cziegeler
Date: Thu Oct 28 08:31:36 2004
New Revision: 55866

Removed:
   cocoon/trunk/lib/core/excalibur-event-api-1.1.jar
   cocoon/trunk/lib/core/excalibur-event-impl-1.1.jar
Modified:
   cocoon/trunk/gump.xml
   cocoon/trunk/lib/jars.xml
   
cocoon/trunk/src/blocks/axis/java/org/apache/cocoon/webservices/system/System.java
   cocoon/trunk/src/java/org/apache/cocoon/Cocoon.java
   
cocoon/trunk/src/java/org/apache/cocoon/components/flow/ContinuationsManagerImpl.java
Log:
Remove dependency to excalibur event
Add own simple background thread for continuation handling

Modified: cocoon/trunk/gump.xml
==============================================================================
--- cocoon/trunk/gump.xml       (original)
+++ cocoon/trunk/gump.xml       Thu Oct 28 08:31:36 2004
@@ -61,8 +61,6 @@
     <depend project="excalibur-store"/>
     <depend project="excalibur-pool"/>
     <depend project="excalibur-logger"/>
-    <depend project="excalibur-event-api"/>
-    <depend project="excalibur-event-impl"/>
 
     <depend project="jakarta-regexp"/>
     <depend project="jakarta-servletapi-4"/>

Modified: cocoon/trunk/lib/jars.xml
==============================================================================
--- cocoon/trunk/lib/jars.xml   (original)
+++ cocoon/trunk/lib/jars.xml   Thu Oct 28 08:31:36 2004
@@ -58,29 +58,6 @@
   </file>
 
   <file>
-    <title>Excalibur Event</title>
-    <description>
-      This is the Excalibur Event package which includes event queues,
-      asynchronous command processing, and the interfaces to support
-      event based programming.
-    </description>
-    <used-by>Cocoon Flow</used-by>
-    <lib>core/excalibur-event-api-1.1.jar</lib>
-    <homepage>http://excalibur.apache.org/</homepage>
-  </file>
-  <file>
-    <title>Excalibur Event</title>
-    <description>
-      This is the Excalibur Event package which includes event queues,
-      asynchronous command processing, and the interfaces to support
-      event based programming.
-    </description>
-    <used-by>Cocoon Flow</used-by>
-    <lib>core/excalibur-event-impl-1.1.jar</lib>
-    <homepage>http://excalibur.apache.org/</homepage>
-  </file>
-
-  <file>
     <title>Excalibur I18n</title>
     <description>
       Part of Excalibur, it is a set of classes and patterns that

Modified: 
cocoon/trunk/src/blocks/axis/java/org/apache/cocoon/webservices/system/System.java
==============================================================================
--- 
cocoon/trunk/src/blocks/axis/java/org/apache/cocoon/webservices/system/System.java
  (original)
+++ 
cocoon/trunk/src/blocks/axis/java/org/apache/cocoon/webservices/system/System.java
  Thu Oct 28 08:31:36 2004
@@ -16,7 +16,8 @@
 package org.apache.cocoon.webservices.system;
 
 import java.util.Properties;
-import org.apache.excalibur.util.SystemUtil;
+
+import org.apache.commons.lang.SystemUtils;
 
 /**
  * Class which provides JVM system related SOAP services.
@@ -41,26 +42,7 @@
      * @return host architecture
      */
     public String getArchitecture() {
-        return SystemUtil.architecture();
-    }
-
-    /**
-     * <code>getCPUInfo</code> returns host CPU information.
-     *
-     * @return host CPU information
-     */
-    public String getCPUInfo() {
-        return SystemUtil.cpuInfo();
-    }
-
-    /**
-     * <code>getNumProcessors</code> returns the number of processors in
-     * this machine.
-     *
-     * @return number of processors
-     */
-    public int getNumProcessors() {
-        return SystemUtil.numProcessors();
+        return SystemUtils.OS_ARCH;
     }
 
     /**
@@ -69,7 +51,7 @@
      * @return host operating system
      */
     public String getOperatingSystem() {
-        return SystemUtil.operatingSystem();
+        return SystemUtils.OS_NAME;
     }
 
     /**
@@ -79,6 +61,6 @@
      * @return host operating system version
      */
     public String getOperatingSystemVersion() {
-        return SystemUtil.osVersion();
+        return SystemUtils.OS_VERSION;
     }
 }

Modified: cocoon/trunk/src/java/org/apache/cocoon/Cocoon.java
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/Cocoon.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/Cocoon.java Thu Oct 28 08:31:36 2004
@@ -37,7 +37,6 @@
 import org.apache.avalon.framework.context.Contextualizable;
 import org.apache.avalon.framework.context.DefaultContext;
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
-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;
@@ -57,10 +56,6 @@
 import org.apache.cocoon.util.ClassUtils;
 import org.apache.commons.lang.SystemUtils;
 
-import org.apache.excalibur.event.Queue;
-import org.apache.excalibur.event.command.CommandManager;
-import org.apache.excalibur.event.command.TPCThreadManager;
-import org.apache.excalibur.event.command.ThreadManager;
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceResolver;
 import org.apache.excalibur.source.impl.URLSource;
@@ -88,10 +83,6 @@
 
     static Cocoon instance;
 
-    private ThreadManager threads;
-
-    private CommandManager commands;
-
     /** The application context */
     private Context context;
 
@@ -168,32 +159,7 @@
     public void contextualize(Context context) throws ContextException {
         if (this.context == null) {
             this.context = new ComponentContext(context);
-
-            try {
-                DefaultContext setup = (DefaultContext) this.context;
-                this.threads = new TPCThreadManager();
-
-                Parameters params = new Parameters();
-                params.setParameter("threads-per-processor", "1");
-                params.setParameter("sleep-time", "100");
-                params.setParameter("block-timeout", "1000");
-                params.setParameter("force-shutdown", "true");
-                params.makeReadOnly();
-
-                ContainerUtil.enableLogging(this.threads, 
getLogger().getChildLogger("thread.manager"));
-                ContainerUtil.parameterize(this.threads, params);
-                ContainerUtil.initialize(this.threads);
-
-                this.commands = new CommandManager();
-                ContainerUtil.enableLogging(this.commands, 
getLogger().getChildLogger("thread.manager"));
-                this.threads.register(this.commands);
-
-                setup.put(Queue.ROLE, this.commands.getCommandSink());
-
-                setup.makeReadOnly();
-            } catch (Exception e) {
-                getLogger().error("Could not set up the Command Manager", e);
-            }
+            ((DefaultContext)this.context).makeReadOnly();
 
             this.classpath = (String)context.get(Constants.CONTEXT_CLASSPATH);
             this.workDir = (File)context.get(Constants.CONTEXT_WORK_DIR);
@@ -455,18 +421,10 @@
         System.setProperties(systemProps);
     }
 
-    /**
-     * Dispose this instance
+    /* (non-Javadoc)
+     * @see org.apache.avalon.framework.activity.Disposable#dispose()
      */
     public void dispose() {
-        if (this.commands != null && this.threads != null) {
-            this.threads.deregister(this.commands);
-        }
-        ContainerUtil.dispose(this.commands);
-        this.commands = null;
-        ContainerUtil.dispose(this.threads);
-        this.threads = null;
-
         if (this.serviceManager != null) {
             if (this.requestListener != null) {
                 this.serviceManager.release(this.requestListener);

Modified: 
cocoon/trunk/src/java/org/apache/cocoon/components/flow/ContinuationsManagerImpl.java
==============================================================================
--- 
cocoon/trunk/src/java/org/apache/cocoon/components/flow/ContinuationsManagerImpl.java
       (original)
+++ 
cocoon/trunk/src/java/org/apache/cocoon/components/flow/ContinuationsManagerImpl.java
       Thu Oct 28 08:31:36 2004
@@ -15,18 +15,6 @@
  */
 package org.apache.cocoon.components.flow;
 
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.context.Context;
-import org.apache.avalon.framework.context.ContextException;
-import org.apache.avalon.framework.context.Contextualizable;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.thread.ThreadSafe;
-
-import org.apache.excalibur.event.Queue;
-import org.apache.excalibur.event.Sink;
-import org.apache.excalibur.event.command.RepeatedCommand;
-
 import java.security.SecureRandom;
 import java.util.Collections;
 import java.util.HashMap;
@@ -38,6 +26,12 @@
 import java.util.SortedSet;
 import java.util.TreeSet;
 
+import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.thread.ThreadSafe;
+
 /**
  * The default implementation of [EMAIL PROTECTED] ContinuationsManager}.
  *
@@ -49,8 +43,7 @@
  */
 public class ContinuationsManagerImpl
         extends AbstractLogEnabled
-        implements ContinuationsManager, Configurable,
-                   ThreadSafe, Contextualizable {
+        implements ContinuationsManager, Configurable, Disposable, ThreadSafe {
 
     static final int CONTINUATION_ID_LENGTH = 20;
     static final String EXPIRE_CONTINUATIONS = "expire-continuations";
@@ -61,7 +54,7 @@
     protected SecureRandom random;
     protected byte[] bytes;
 
-    protected Sink m_commandSink;
+    protected ContinuationInterrupt interrupt;
 
     /**
      * How long does a continuation exist in memory since the last
@@ -103,26 +96,36 @@
         bytes = new byte[CONTINUATION_ID_LENGTH];
     }
 
-    /**
-     * Get the command sink so that we can be notified of changes
+    /* (non-Javadoc)
+     * @see 
org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
      */
-    public void contextualize(Context context) throws ContextException {
-        m_commandSink = (Sink) context.get(Queue.ROLE);
-    }
-
     public void configure(Configuration config) {
         this.defaultTimeToLive = config.getAttributeAsInteger("time-to-live", 
(3600 * 1000));
 
         final Configuration expireConf = config.getChild("expirations-check");
         try {
-            final ContinuationInterrupt interrupt = new 
ContinuationInterrupt(expireConf);
-            this.m_commandSink.enqueue(interrupt);
+            this.interrupt = new ContinuationInterrupt(expireConf);
+            Thread thread = new Thread(interrupt);
+            thread.setDaemon(true);
+            thread.setName("continuation-interrupt");
+            thread.start();
+            Thread.yield();
         } catch (Exception e) {
             getLogger().warn("Could not enqueue continuations expiration task. 
" +
                              "Continuations will not automatically expire.", 
e);
         }
     }
 
+    /* (non-Javadoc)
+     * @see org.apache.avalon.framework.activity.Disposable#dispose()
+     */
+    public void dispose() {
+        // stop the thread
+        if ( this.interrupt != null ) {
+            this.interrupt.doRun = false;
+        }
+    }
+    
     public WebContinuation createWebContinuation(Object kont,
                                                  WebContinuation parent,
                                                  int timeToLive,
@@ -353,47 +356,43 @@
     }
 
 
-    final class ContinuationInterrupt implements RepeatedCommand {
-        private final long m_interval;
-        private final long m_initialDelay;
+    final class ContinuationInterrupt implements Runnable {
+        private final long interval;
+        private final long initialDelay;
 
+        public boolean doRun;
+        
         /**
          * @param expireConf
          */
         public ContinuationInterrupt(Configuration expireConf) {
             // only periodic time triggers are supported
-            m_initialDelay =
-                    expireConf.getChild("offset", true).getValueAsLong(100);
-            m_interval =
-                    expireConf.getChild("period", true).getValueAsLong(100);
-        }
-
-        /**
-         * Repeat forever
-         */
-        public int getNumberOfRepeats() {
-            return -1;
-        }
-
-        /**
-         * Get the number of millis to wait between invocations
-         */
-        public long getRepeatInterval() {
-            return m_interval;
-        }
-
-        /**
-         * Get the number of millis to wait for the first invocation
-         */
-        public long getDelayInterval() {
-            return m_initialDelay;
+            this.initialDelay = expireConf.getChild("offset", 
true).getValueAsLong(100);
+            this.interval = expireConf.getChild("period", 
true).getValueAsLong(100);
         }
 
         /**
          * expire any continuations that need expiring.
          */
-        public void execute() throws Exception {
-            expireContinuations();
+        public void run() {
+            this.doRun = true;
+            if ( this.initialDelay > 0 ) {
+                // Sleep
+                try {
+                    Thread.sleep(this.initialDelay);
+                } catch (InterruptedException ignore) { 
+                    // ignore
+                }
+            }
+            while (doRun) {
+                expireContinuations();
+                // Sleep
+                try {
+                    Thread.sleep(this.interval);
+                } catch (InterruptedException ignore) { 
+                    // ignore
+                }
+            }
         }
     }
 }

Reply via email to