directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 22476 - in incubator/directory/eve/branches/consolidation/frontend: . src/java/org/apache/eve/seda src/test/org/apache/eve/seda
Date Fri, 02 Jul 2004 14:25:07 GMT
Author: akarasulu
Date: Fri Jul  2 07:25:06 2004
New Revision: 22476

Modified:
   incubator/directory/eve/branches/consolidation/frontend/project.xml
   incubator/directory/eve/branches/consolidation/frontend/src/java/org/apache/eve/seda/DefaultStage.java
   incubator/directory/eve/branches/consolidation/frontend/src/java/org/apache/eve/seda/LoggingStageMonitor.java
   incubator/directory/eve/branches/consolidation/frontend/src/java/org/apache/eve/seda/StageMonitor.java
   incubator/directory/eve/branches/consolidation/frontend/src/java/org/apache/eve/seda/StageMonitorAdapter.java
   incubator/directory/eve/branches/consolidation/frontend/src/test/org/apache/eve/seda/DefaultStageTest.java
Log:
Commit changes ...

 o fixed failing test due to missing event lost when stoping stage
 o cleaned up logging a little since I had to use it
 o added extra monitor method to monitor predicate additions
 


Modified: incubator/directory/eve/branches/consolidation/frontend/project.xml
==============================================================================
--- incubator/directory/eve/branches/consolidation/frontend/project.xml	(original)
+++ incubator/directory/eve/branches/consolidation/frontend/project.xml	Fri Jul  2 07:25:06
2004
@@ -57,13 +57,6 @@
       </dependency>
         
       <dependency>
-        <groupId>log4j</groupId>
-        <artifactId>log4j</artifactId>
-        <version>1.2.7</version>
-        <url>http://logging.apache.org/log4j/docs</url>
-      </dependency>
-
-      <dependency>
         <groupId>regexp</groupId>
         <artifactId>regexp</artifactId>
         <version>1.2</version>

Modified: incubator/directory/eve/branches/consolidation/frontend/src/java/org/apache/eve/seda/DefaultStage.java
==============================================================================
--- incubator/directory/eve/branches/consolidation/frontend/src/java/org/apache/eve/seda/DefaultStage.java
(original)
+++ incubator/directory/eve/branches/consolidation/frontend/src/java/org/apache/eve/seda/DefaultStage.java
Fri Jul  2 07:25:06 2004
@@ -76,12 +76,14 @@
 
 
     /**
-     * @see org.apache.eve.seda.Stage#
+     * @see org.apache.eve.seda.Stage#addPredicate(
+     *          org.apache.eve.seda.EnqueuePredicate)
      * addPredicate(org.apache.eve.seda.EnqueuePredicate)
      */
     public void addPredicate( EnqueuePredicate predicate )
     {
         config.getPredicates().add( predicate ) ;
+        monitor.predicateAdded( this, predicate ) ;
     }
     
     
@@ -95,13 +97,23 @@
 
 
     /**
+     * Enqueue's an event onto the event queue of this stage if the stage
+     * predicates permit the operation and the stage has started.  The event
+     * enqueue is rejected if the stage has not started.
+     *
      * @see org.apache.eve.seda.Stage#enqueue(java.util.EventObject)
      */
     public void enqueue( final EventObject event )
     {
         boolean isAccepted = true ;
-        
-        for ( int ii = 0; ii < config.getPredicates().size() && isAccepted ; 
+
+        if ( ! hasStarted.booleanValue() )
+        {
+            monitor.enqueueRejected( this, event ) ;
+            return ;
+        }
+
+        for ( int ii = 0; ii < config.getPredicates().size() && isAccepted ;
             ii++ ) 
         {
             EnqueuePredicate test = 
@@ -144,24 +156,29 @@
         public final void run()
         {
             monitor.startedDriver( DefaultStage.this ) ;
-    
-            while( hasStarted.booleanValue() ) 
+
+            /*
+             * keep processing until the hasStarted variable is toggled off
+             * and there are no queue events left.  Before without the queue
+             * term events would be left unprocessed on the queue on stop calls
+             */
+            while( hasStarted.booleanValue() || !queue.isEmpty() )
             {
-                synchronized ( queue ) 
+                synchronized ( queue )
                 {
                     monitor.lockedQueue( DefaultStage.this ) ;
-                    
-                    if( queue.isEmpty() ) 
+
+                    if( queue.isEmpty() )
                     {
-                        try 
+                        try
                         {
                             monitor.waiting( DefaultStage.this ) ;
                             queue.wait() ;
                             monitor.notified( DefaultStage.this ) ;
-                        } 
-                        catch( InterruptedException e ) 
+                        }
+                        catch( InterruptedException e )
                         {
-                            try { stop() ; } catch ( Exception e2 ) 
+                            try { stop() ; } catch ( Exception e2 )
                             {/*NOT THROWN*/}
                             monitor.driverFailed( DefaultStage.this, e ) ;
                         }
@@ -268,8 +285,19 @@
         
         monitor.stopped( this ) ;
     }
-    
-    
+
+
+    /**
+     * Tests to see if this stage has started.
+     *
+     * @return true if this stage has started, false otherwise
+     */
+    public boolean hasStarted()
+    {
+        return hasStarted.booleanValue() ;
+    }
+
+
     /**
      * Gets this Stage's monitor.
      * 

Modified: incubator/directory/eve/branches/consolidation/frontend/src/java/org/apache/eve/seda/LoggingStageMonitor.java
==============================================================================
--- incubator/directory/eve/branches/consolidation/frontend/src/java/org/apache/eve/seda/LoggingStageMonitor.java
(original)
+++ incubator/directory/eve/branches/consolidation/frontend/src/java/org/apache/eve/seda/LoggingStageMonitor.java
Fri Jul  2 07:25:06 2004
@@ -123,8 +123,8 @@
     {
         if ( log.isDebugEnabled() )
         {
-            log.debug( stage.getConfig().getName() + " had event " + event 
-                    + " enqueued!" ) ;
+            log.debug( stage.getConfig().getName() + " had event "
+                    + getDesc( event ) + " enqueued!" ) ;
         }
     }
 
@@ -137,8 +137,8 @@
     {
         if ( log.isWarnEnabled() )
         {
-            log.warn( stage.getConfig().getName() + " had event " + event 
-                    + " enqueue REJECTED!" ) ;
+            log.warn( stage.getConfig().getName() + " had event "
+                    + getDesc( event ) + " enqueue REJECTED!" ) ;
         }
     }
 
@@ -152,7 +152,7 @@
         if ( log.isDebugEnabled() )
         {
             log.debug( stage.getConfig().getName() 
-                    + "'s queue locked for processing " + event ) ; 
+                    + "'s queue locked for processing " + getDesc( event ) ) ;
         }
     }
 
@@ -179,7 +179,7 @@
         if ( log.isDebugEnabled() )
         {
             log.debug( stage.getConfig().getName() 
-                    + "'s stage driver thread notified out of waiting" ) ; 
+                    + "'s driver thread notified out of waiting" ) ; 
         }
     }
 
@@ -233,8 +233,8 @@
     {
         if ( log.isDebugEnabled() )
         {
-            log.debug( stage.getConfig().getName() + " had event " + event 
-                    + " dequeued!" ) ;
+            log.debug( stage.getConfig().getName() + " had event "
+                    + getDesc( event ) + " dequeued!" ) ;
         }
     }
 
@@ -247,7 +247,8 @@
     {
         if ( log.isDebugEnabled() )
         {
-            log.debug( stage.getConfig().getName() + " handled " + event ) ; 
+            log.debug( stage.getConfig().getName() + " handled "
+                    + getDesc( event ) ) ;
         }
     }
 
@@ -277,5 +278,33 @@
             log.error( stage.getConfig().getName() 
                     + "'s handler failed", fault ) ; 
         }
+    }
+
+
+    /**
+     * Monitors enqueue predicate additions.
+     *
+     * @param stage the default stage the predicate is added to
+     * @param predicate    the enqueue predicate added to the stage
+     */
+    public void predicateAdded( DefaultStage stage, EnqueuePredicate predicate )
+    {
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "predicate added to stage "
+                    + stage.getConfig().getName() ) ;
+        }
+    }
+
+
+    /**
+     * Gets a short string description for an event.
+     *
+     * @param event the event to create a description string for
+     * @return the description string for the event
+     */
+    private String getDesc( EventObject event )
+    {
+        return ClassUtils.getShortClassName( event.getClass() ) ;
     }
 }

Modified: incubator/directory/eve/branches/consolidation/frontend/src/java/org/apache/eve/seda/StageMonitor.java
==============================================================================
--- incubator/directory/eve/branches/consolidation/frontend/src/java/org/apache/eve/seda/StageMonitor.java
(original)
+++ incubator/directory/eve/branches/consolidation/frontend/src/java/org/apache/eve/seda/StageMonitor.java
Fri Jul  2 07:25:06 2004
@@ -156,4 +156,13 @@
      * @param fault the faulting exception
      */
     void handlerFailed( Stage stage, EventObject event, Throwable fault ) ;
+
+    /**
+     * Monitors enqueue predicate additions.
+     *
+     * @param defaultStage the default stage the predicate is added to
+     * @param predicate the enqueue predicate added to the stage
+     */
+    void predicateAdded( DefaultStage defaultStage,
+                         EnqueuePredicate predicate ) ;
 }

Modified: incubator/directory/eve/branches/consolidation/frontend/src/java/org/apache/eve/seda/StageMonitorAdapter.java
==============================================================================
--- incubator/directory/eve/branches/consolidation/frontend/src/java/org/apache/eve/seda/StageMonitorAdapter.java
(original)
+++ incubator/directory/eve/branches/consolidation/frontend/src/java/org/apache/eve/seda/StageMonitorAdapter.java
Fri Jul  2 07:25:06 2004
@@ -172,4 +172,15 @@
     {
         System.err.println( ExceptionUtils.getFullStackTrace( fault ) ) ;
     }
+
+
+    /**
+     * Monitors enqueue predicate additions.
+     *
+     * @param stage the default stage the predicate is added to
+     * @param predicate    the enqueue predicate added to the stage
+     */
+    public void predicateAdded( DefaultStage stage, EnqueuePredicate predicate )
+    {
+    }
 }

Modified: incubator/directory/eve/branches/consolidation/frontend/src/test/org/apache/eve/seda/DefaultStageTest.java
==============================================================================
--- incubator/directory/eve/branches/consolidation/frontend/src/test/org/apache/eve/seda/DefaultStageTest.java
(original)
+++ incubator/directory/eve/branches/consolidation/frontend/src/test/org/apache/eve/seda/DefaultStageTest.java
Fri Jul  2 07:25:06 2004
@@ -20,12 +20,7 @@
 import java.util.ArrayList ;
 import java.util.EventObject ;
 
-import org.apache.eve.seda.DefaultStage ;
-import org.apache.eve.seda.StageHandler ;
 import org.apache.eve.thread.ThreadPool ;
-import org.apache.eve.seda.EnqueuePredicate ;
-import org.apache.eve.seda.DefaultStageConfig ;
-import org.apache.eve.seda.LoggingStageMonitor ;
 
 import junit.framework.TestCase ;
 
@@ -51,7 +46,6 @@
      */
     protected void tearDown() throws Exception
     {
-        // @todo Auto-generated method stub
         super.tearDown();
         
         events = null ;
@@ -91,7 +85,7 @@
             }
         } ;
         
-        config = new DefaultStageConfig( "test", pool ) ;
+        config = new DefaultStageConfig( "stage", pool ) ;
         config.setHandler( handler ) ;
         stage = new DefaultStage( config ) ;
         stage.setMonitor( new LoggingStageMonitor(stage.getClass()) ) ;
@@ -111,6 +105,11 @@
         
         stage.enqueue( new EventObject( this ) ) ;
         stage.stop() ;
+
+        while( stage.hasStarted() )
+        {
+            Thread.sleep( 100 );
+        }
         assertEquals( 1, events.size() ) ;
     }
 

Mime
View raw message