directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 46153 - in incubator/directory/seda/trunk: . src/examples src/examples/org src/examples/org/apache src/examples/org/apache/seda src/examples/org/apache/seda/examples src/java/org/apache/seda src/test/org/apache/seda
Date Thu, 16 Sep 2004 04:06:46 GMT
Author: akarasulu
Date: Wed Sep 15 21:06:45 2004
New Revision: 46153

Added:
   incubator/directory/seda/trunk/src/examples/
   incubator/directory/seda/trunk/src/examples/org/
   incubator/directory/seda/trunk/src/examples/org/apache/
   incubator/directory/seda/trunk/src/examples/org/apache/seda/
   incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/
   incubator/directory/seda/trunk/src/test/org/apache/seda/DefaultFrontendFactoryTest.java
  (contents, props changed)
Modified:
   incubator/directory/seda/trunk/project.xml
   incubator/directory/seda/trunk/src/java/org/apache/seda/DefaultFrontend.java
   incubator/directory/seda/trunk/src/java/org/apache/seda/DefaultFrontendFactory.java
   incubator/directory/seda/trunk/src/java/org/apache/seda/FrontendFactory.java
Log:
Added the hard coded harness for now under the default frontend but this
might change as we start to figure out exactly what this default frontend
really is.  First lets start implementing a few example protocols.


Modified: incubator/directory/seda/trunk/project.xml
==============================================================================
--- incubator/directory/seda/trunk/project.xml	(original)
+++ incubator/directory/seda/trunk/project.xml	Wed Sep 15 21:06:45 2004
@@ -95,6 +95,10 @@
 
   <dependencies>
 
+    <!-- ================================ -->
+    <!-- CORE Dependencies needed for use -->
+    <!-- ================================ -->
+
     <dependency>
       <groupId>commons-logging</groupId>
       <artifactId>commons-logging</artifactId>
@@ -109,7 +113,10 @@
       <url>http://incubator.apache.org/directory/subprojects/ldap/common</url>
     </dependency>
 
-    <!-- Dependencies required for running test cases -->
+    <!-- ========================================================= -->
+    <!-- Dependencies required for running test cases and examples -->
+    <!-- ========================================================= -->
+
     <dependency>
       <groupId>commons-threadpool</groupId>
       <artifactId>commons-threadpool</artifactId>
@@ -145,6 +152,7 @@
       </excludes>
 
       <resources>
+        <!-- Actual test cases and supporting classes here -->
         <resource>
           <directory>${basedir}/src/test</directory>
           <includes>
@@ -157,8 +165,9 @@
           </includes>
         </resource>
 
+        <!-- Examples of protocol providers using framework -->
         <resource>
-          <directory>${basedir}/src/test</directory>
+          <directory>${basedir}/src/examples</directory>
           <includes>
             <include>**/*.dtd</include>
             <include>**/*.ldif</include>

Modified: incubator/directory/seda/trunk/src/java/org/apache/seda/DefaultFrontend.java
==============================================================================
--- incubator/directory/seda/trunk/src/java/org/apache/seda/DefaultFrontend.java	(original)
+++ incubator/directory/seda/trunk/src/java/org/apache/seda/DefaultFrontend.java	Wed Sep 15
21:06:45 2004
@@ -19,13 +19,21 @@
 
 import org.apache.seda.buffer.BufferPool;
 import org.apache.seda.event.EventRouter;
+import org.apache.seda.event.AddProtocolEvent;
 import org.apache.seda.decoder.DecoderManager;
+import org.apache.seda.decoder.DefaultDecoderManager;
 import org.apache.seda.encoder.EncoderManager;
+import org.apache.seda.encoder.DefaultEncoderManager;
 import org.apache.seda.input.InputManager;
+import org.apache.seda.input.DefaultInputManager;
 import org.apache.seda.listener.ListenerManager;
+import org.apache.seda.listener.DefaultListenerManager;
 import org.apache.seda.output.OutputManager;
+import org.apache.seda.output.DefaultOutputManager;
 import org.apache.seda.protocol.RequestProcessor;
 import org.apache.seda.protocol.InetServicesDatabase;
+import org.apache.seda.protocol.DefaultRequestProcessor;
+import org.apache.seda.protocol.ProtocolProvider;
 
 
 /**
@@ -39,15 +47,15 @@
  */
 public class DefaultFrontend implements Frontend
 {
-    final BufferPool bp;
-    final DecoderManager decMan;
-    final EncoderManager encMan;
-    final EventRouter router;
-    final InputManager inMan;
-    final ListenerManager srvMan;
-    final OutputManager outMan;
-    final RequestProcessor reqProc;
-    final InetServicesDatabase inetDb;
+    private final BufferPool bp;
+    private final DecoderManager decMan;
+    private final EncoderManager encMan;
+    private final EventRouter router;
+    private final InputManager inMan;
+    private final ListenerManager srvMan;
+    private final OutputManager outMan;
+    private final RequestProcessor reqProc;
+    private final InetServicesDatabase inetDb;
 
     DefaultFrontend( BufferPool bp, DecoderManager decMan, 
                      EncoderManager encMan, EventRouter router, 
@@ -64,5 +72,68 @@
         this.outMan = outMan;
         this.reqProc = reqProc;
         this.inetDb = inetDb;
+    }
+
+
+    public void register( ProtocolProvider provider )
+    {
+        AddProtocolEvent event = new AddProtocolEvent( provider );
+        router.publish( event );
+    }
+
+
+    public void stop() throws Exception
+    {
+        ( ( DefaultListenerManager ) srvMan ).stop();
+        ( ( DefaultInputManager ) inMan ).stop();
+        ( ( DefaultOutputManager ) outMan ).stop();
+        ( ( DefaultRequestProcessor ) reqProc ).stop();
+        ( ( DefaultDecoderManager ) decMan ).stop();
+        ( ( DefaultEncoderManager ) encMan ).stop();
+    }
+
+    public BufferPool getBufferPool()
+    {
+        return bp;
+    }
+
+    public DecoderManager getDecoderManager()
+    {
+        return decMan;
+    }
+
+    public EncoderManager getEncoderManager()
+    {
+        return encMan;
+    }
+
+    public EventRouter getEventRouter()
+    {
+        return router;
+    }
+
+    public InputManager getInputManager()
+    {
+        return inMan;
+    }
+
+    public ListenerManager getListenerManager()
+    {
+        return srvMan;
+    }
+
+    public OutputManager getOutputManager()
+    {
+        return outMan;
+    }
+
+    public RequestProcessor getRequestProcessor()
+    {
+        return reqProc;
+    }
+
+    public InetServicesDatabase getInetServicesDatabase()
+    {
+        return inetDb;
     }
 }

Modified: incubator/directory/seda/trunk/src/java/org/apache/seda/DefaultFrontendFactory.java
==============================================================================
--- incubator/directory/seda/trunk/src/java/org/apache/seda/DefaultFrontendFactory.java	(original)
+++ incubator/directory/seda/trunk/src/java/org/apache/seda/DefaultFrontendFactory.java	Wed
Sep 15 21:06:45 2004
@@ -16,11 +16,14 @@
  */
 package org.apache.seda;
 
+
 import org.apache.seda.buffer.BufferPool;
 import org.apache.seda.buffer.DefaultBufferPool;
 import org.apache.seda.buffer.DefaultBufferPoolConfig;
+import org.apache.seda.buffer.LoggingBufferMonitor;
 import org.apache.seda.event.EventRouter;
 import org.apache.seda.event.DefaultEventRouter;
+import org.apache.seda.event.EventRouterMonitorAdapter;
 import org.apache.seda.protocol.*;
 import org.apache.seda.decoder.DecoderManager;
 import org.apache.seda.decoder.DefaultDecoderManager;
@@ -37,19 +40,22 @@
 import org.apache.seda.output.OutputManager;
 import org.apache.seda.output.DefaultOutputManager;
 import org.apache.commons.threadpool.DefaultThreadPool;
+import org.apache.commons.threadpool.CommonsLoggingThreadPoolMonitor;
 
 import java.io.IOException;
 
 
 /**
- * Document me.
+ * A factory implementation that ties together the frontend components for
+ * testing purposes.  The assembly uses only the POJO's manually hardcoding
+ * them without the use of a micro kernel for an IoC container.
  *
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
 public class DefaultFrontendFactory implements FrontendFactory
 {
-    public Frontend create() throws IOException
+    public Frontend create() throws Exception
     {
         // create all services that do not have any deps on other services
         BufferPool bp = createBufferPool();
@@ -75,14 +81,20 @@
     {
         DefaultBufferPoolConfig config = new DefaultBufferPoolConfig(
             "", 10, 100, 20, 20 );
-        return new DefaultBufferPool( config ) ;
+        DefaultBufferPool bp = new DefaultBufferPool( config ) ;
+        bp.setMonitor( new LoggingBufferMonitor( "bufferPool" ) );
+        return bp;
     }
 
 
     // no deps
     private EventRouter createEventRouter()
     {
-        return new DefaultEventRouter();
+        DefaultEventRouter router = new DefaultEventRouter();
+
+        // @todo start using a logging monitor for event router
+        router.setMonitor( new EventRouterMonitorAdapter() );
+        return router;
     }
 
 
@@ -90,14 +102,20 @@
     private InetServicesDatabase createServicesDatabase()
     {
         InetServiceEntry[] entries = { new InetServiceEntry( "ldap", 389 ) };
-        return new DefaultInetServicesDatabase( entries ) ;
+
+        // @todo add a monitor interface for this service and logging impl
+        InetServicesDatabase inetDb =
+            new DefaultInetServicesDatabase( entries );
+        return inetDb;
     }
 
 
     // no deps
     private ThreadPool createThreadPool( int threads )
     {
-        final DefaultThreadPool ctp = new DefaultThreadPool( threads );
+        CommonsLoggingThreadPoolMonitor monitor =
+            new CommonsLoggingThreadPoolMonitor();
+        final DefaultThreadPool ctp = new DefaultThreadPool( monitor, threads );
         ThreadPool pool = new ThreadPool()
         {
             public void execute( Runnable runnable )
@@ -119,7 +137,8 @@
             config, inetDb );
         DecodeStageHandler handler = new DecodeStageHandler( decMan );
         config.setHandler( handler );
-        return new DefaultDecoderManager( router, config, inetDb );
+        decMan.start();
+        return decMan;
     }
 
 
@@ -133,21 +152,26 @@
             config, inetDb );
         EncodeStageHandler handler = new EncodeStageHandler( encMan );
         config.setHandler( handler );
+        encMan.start();
         return encMan;
     }
 
 
     private ListenerManager createListenerManager( EventRouter router )
-        throws IOException
+        throws IOException, InterruptedException
     {
-        return new DefaultListenerManager( router );
+        DefaultListenerManager listMan = new DefaultListenerManager( router );
+        listMan.start();
+        return listMan;
     }
 
 
     private InputManager createInputManager( EventRouter router, BufferPool bp )
         throws IOException
     {
-        return new DefaultInputManager( router, bp );
+        DefaultInputManager inMan = new DefaultInputManager( router, bp );
+        inMan.start();
+        return inMan;
     }
 
 
@@ -155,7 +179,9 @@
     {
         DefaultStageConfig config = new DefaultStageConfig( "outputManager",
             createThreadPool( 3 ) );
-        return new DefaultOutputManager( router, config );
+        DefaultOutputManager outMan = new DefaultOutputManager( router, config );
+        outMan.start();
+        return outMan;
     }
 
 
@@ -163,6 +189,9 @@
     {
         DefaultStageConfig config = new DefaultStageConfig( "requestProcessor",
             createThreadPool( 3 ) );
-        return new DefaultRequestProcessor( router, config );
+        DefaultRequestProcessor reqProc =
+            new DefaultRequestProcessor( router, config );
+        reqProc.start();
+        return reqProc;
     }
 }

Modified: incubator/directory/seda/trunk/src/java/org/apache/seda/FrontendFactory.java
==============================================================================
--- incubator/directory/seda/trunk/src/java/org/apache/seda/FrontendFactory.java	(original)
+++ incubator/directory/seda/trunk/src/java/org/apache/seda/FrontendFactory.java	Wed Sep 15
21:06:45 2004
@@ -26,5 +26,5 @@
  */
 public interface FrontendFactory
 {
-    Frontend create() throws IOException;
+    Frontend create() throws Exception;
 }

Added: incubator/directory/seda/trunk/src/test/org/apache/seda/DefaultFrontendFactoryTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/seda/trunk/src/test/org/apache/seda/DefaultFrontendFactoryTest.java
Wed Sep 15 21:06:45 2004
@@ -0,0 +1,94 @@
+/*
+ *   Copyright 2004 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.seda;
+
+
+import junit.framework.TestCase;
+import org.apache.seda.listener.ListenerConfig;
+import org.apache.seda.listener.DefaultListenerConfig;
+import org.apache.seda.protocol.InetServiceEntry;
+
+import java.io.IOException;
+
+
+/**
+ * Tests the correct operation of the default frontend factory.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class DefaultFrontendFactoryTest extends TestCase
+{
+    DefaultFrontend fe = null;
+
+    /**
+     * Stops the created frontend.
+     *
+     * @throws Exception due to super call and stop method
+     */
+    protected void tearDown() throws Exception
+    {
+        super.tearDown();
+        fe.stop();
+        fe = null;
+    }
+
+
+    /**
+     * Instantiates the factory then gets a handle on the Frontend.
+     *
+     * @throws Exception due to super call and create()
+     */
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        fe = ( DefaultFrontend ) new DefaultFrontendFactory().create();
+    }
+
+
+    /**
+     * Tests to make sure setup of the apparatus works.
+     */
+    public void testSetup()
+    {
+        assertNotNull( fe );
+        assertNotNull( fe.getBufferPool() );
+        assertNotNull( fe.getDecoderManager() );
+        assertNotNull( fe.getEncoderManager() );
+        assertNotNull( fe.getEventRouter() );
+        assertNotNull( fe.getInetServicesDatabase() );
+        assertNotNull( fe.getInputManager() );
+        assertNotNull( fe.getListenerManager() );
+        assertNotNull( fe.getOutputManager() );
+        assertNotNull( fe.getRequestProcessor() );
+    }
+
+
+    /**
+     * Tests to make sure the bind operation works.
+     *
+     * @throws IOException
+     */
+    public void testBind() throws IOException
+    {
+        ListenerConfig config = null;
+        config = new DefaultListenerConfig( new byte[] { 127,0,0,1}, 20, false,
+            new InetServiceEntry( "ldap", 10389 ) );
+        fe.getListenerManager().bind( config );
+        fe.getListenerManager().unbind( config );
+    }
+}

Mime
View raw message