You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by bl...@apache.org on 2003/06/12 16:06:52 UTC

cvs commit: avalon-excalibur/event/src/java/org/apache/excalibur/event/command TPSPThreadManager.java

bloritsch    2003/06/12 07:06:52

  Modified:    event/src/java/org/apache/excalibur/event/command
                        TPSPThreadManager.java
  Log:
  Add DequeueInterceptor for the TPSPThreadManager--maybe we can get this one working soon.
  
  Revision  Changes    Path
  1.26      +63 -0     avalon-excalibur/event/src/java/org/apache/excalibur/event/command/TPSPThreadManager.java
  
  Index: TPSPThreadManager.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/event/src/java/org/apache/excalibur/event/command/TPSPThreadManager.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- TPSPThreadManager.java	22 Apr 2003 00:07:55 -0000	1.25
  +++ TPSPThreadManager.java	12 Jun 2003 14:06:52 -0000	1.26
  @@ -54,6 +54,10 @@
   import org.apache.commons.collections.StaticBucketMap;
   import org.apache.excalibur.event.EventHandler;
   import org.apache.excalibur.event.Source;
  +import org.apache.excalibur.event.DequeueInterceptor;
  +import org.apache.excalibur.event.Queue;
  +import org.apache.excalibur.event.impl.NullDequeueInterceptor;
  +import EDU.oswego.cs.dl.util.concurrent.PooledExecutor;
   
   /**
    * This is a <code>ThreadManager</code> which provides a threadpool per
  @@ -197,6 +201,65 @@
               {
                   handler.handleEvents( sources[ i ].dequeueAll() );
               }
  +        }
  +    }
  +
  +    public static final class SourceDequeueInterceptor implements DequeueInterceptor
  +    {
  +        private final Source m_source;
  +        private final PooledExecutor m_threadPool;
  +        private final int m_threshold;
  +        private final DequeueInterceptor m_parent;
  +
  +        public SourceDequeueInterceptor( Source source, PooledExecutor threadPool, int threshold )
  +        {
  +            if (source == null) throw new NullPointerException("source");
  +            if (threadPool == null) throw new NullPointerException("threadPool");
  +
  +            m_source = source;
  +            m_threadPool = threadPool;
  +            m_threshold = threshold;
  +            m_parent = (source instanceof Queue) ? ((Queue)source).getDequeueInterceptor()
  +                         : new NullDequeueInterceptor();
  +        }
  +
  +        /**
  +         * An operation executed before dequeing events from
  +         * the queue. The Source is passed in so the implementation
  +         * can determine to execute based on the queue properties.
  +         *
  +         * <p>
  +         *   This method is called once at the beginning of any <code>dequeue</code>
  +         *   method regardless of how many queue elements are dequeued.
  +         * </p>
  +         *
  +         * @since Feb 10, 2003
  +         *
  +         * @param context  The source from which the dequeue is performed.
  +         */
  +        public void before( Source context )
  +        {
  +            if (m_source.size() > m_threshold) m_threadPool.createThreads(1);
  +            m_parent.before(context);
  +        }
  +
  +        /**
  +         * An operation executed after dequeing events from
  +         * the queue. The Source is passed in so the implementation
  +         * can determine to execute based on the queue properties.
  +         *
  +         * <p>
  +         *   This method is called once at the end of any <code>dequeue</code>
  +         *   method regardless of how many queue elements are dequeued.
  +         * </p>
  +         *
  +         * @since Feb 10, 2003
  +         *
  +         * @param context  The source from which the dequeue is performed.
  +         */
  +        public void after( Source context )
  +        {
  +            m_parent.after(context);
           }
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org