You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2004/09/15 01:48:34 UTC

svn commit: rev 46050 - in incubator/directory/seda/trunk: api api/src/java/org/apache/seda api/src/java/org/apache/seda/input api/src/java/org/apache/seda/output api/src/java/org/apache/seda/protocol impl impl/src/java/org/apache/seda impl/src/java/org/apache/seda/buffer impl/src/java/org/apache/seda/encoder impl/src/java/org/apache/seda/event impl/src/java/org/apache/seda/output impl/src/java/org/apache/seda/protocol impl/src/java/org/apache/seda/stage impl/src/test/org/apache/seda/buffer impl/src/test/org/apache/seda/decoder

Author: akarasulu
Date: Tue Sep 14 16:48:33 2004
New Revision: 46050

Added:
   incubator/directory/seda/trunk/api/src/java/org/apache/seda/Enum.java
   incubator/directory/seda/trunk/api/src/java/org/apache/seda/EnumUtils.java
   incubator/directory/seda/trunk/api/src/java/org/apache/seda/ValuedEnum.java
   incubator/directory/seda/trunk/impl/src/java/org/apache/seda/DefaultFrontendFactory.java   (contents, props changed)
   incubator/directory/seda/trunk/impl/src/java/org/apache/seda/FrontendFactory.java   (contents, props changed)
   incubator/directory/seda/trunk/impl/src/java/org/apache/seda/encoder/EncodeStageHandler.java   (contents, props changed)
   incubator/directory/seda/trunk/impl/src/java/org/apache/seda/protocol/DefaultInetServicesDatabase.java   (contents, props changed)
Modified:
   incubator/directory/seda/trunk/api/project.xml
   incubator/directory/seda/trunk/api/src/java/org/apache/seda/input/InputManagerMonitorAdapter.java
   incubator/directory/seda/trunk/api/src/java/org/apache/seda/output/OutputMonitorAdapter.java
   incubator/directory/seda/trunk/api/src/java/org/apache/seda/protocol/HandlerTypeEnum.java
   incubator/directory/seda/trunk/api/src/java/org/apache/seda/protocol/InetServicesDatabase.java
   incubator/directory/seda/trunk/api/src/java/org/apache/seda/protocol/RequestProcessorMonitorAdapter.java
   incubator/directory/seda/trunk/api/src/java/org/apache/seda/protocol/TransportTypeEnum.java
   incubator/directory/seda/trunk/impl/project.xml
   incubator/directory/seda/trunk/impl/src/java/org/apache/seda/DefaultFrontend.java
   incubator/directory/seda/trunk/impl/src/java/org/apache/seda/buffer/DefaultBufferPool.java
   incubator/directory/seda/trunk/impl/src/java/org/apache/seda/encoder/DefaultEncoderManager.java
   incubator/directory/seda/trunk/impl/src/java/org/apache/seda/event/AbstractSubscriber.java
   incubator/directory/seda/trunk/impl/src/java/org/apache/seda/output/LoggingOutputMonitor.java
   incubator/directory/seda/trunk/impl/src/java/org/apache/seda/protocol/DefaultRequestProcessor.java
   incubator/directory/seda/trunk/impl/src/java/org/apache/seda/stage/LoggingStageMonitor.java
   incubator/directory/seda/trunk/impl/src/test/org/apache/seda/buffer/DefaultBufferPoolTest.java
   incubator/directory/seda/trunk/impl/src/test/org/apache/seda/decoder/DefaultDecoderManagerTest.java
Log:
Commit changes ...

 o removed deps on commons-codec
 o removed deps on commons-lang
 o copied deprecated old enum code here to be removed on a move to 1.5
   which should occur shortly: so deps on lang are short lived anyway
 o factored out EncodeHandler like in DecodeHandler
 o reoved superfulous use of ExceptionUtils
 o started adding some experimental code that I will move to a testing
   harness for testing out the entire system without a kernel; much of
   this will probably need to be in the api.  This might not matter if
   we do decide to merge the two. 


Modified: incubator/directory/seda/trunk/api/project.xml
==============================================================================
--- incubator/directory/seda/trunk/api/project.xml	(original)
+++ incubator/directory/seda/trunk/api/project.xml	Tue Sep 14 16:48:33 2004
@@ -16,33 +16,14 @@
     minimum of external dependencies for the SEDA protocol server framework.
   </description>
 
-  <!-- When complete there should be no deps here -->
-
   <dependencies>
-    <!-- We need to get rid of this dependency on commons-codec -->
-    <dependency>
-      <groupId>commons-codec</groupId>
-      <artifactId>commons-codec</artifactId>
-      <version>SNAPSHOT</version>
-      <url>http://jakarta.apache.org/commons/codec</url>
-    </dependency>
-
-    <!-- We need to get rid of this dependency on commons-lang -->
-    <dependency>
-      <groupId>commons-lang</groupId>
-      <artifactId>commons-lang</artifactId>
-      <version>SNAPSHOT</version>
-      <url>http://jakarta.apache.org/commons/lang</url>
-    </dependency>
-
     <!-- We need to get rid of this dependency on codec-stateful -->
     <dependency>
       <groupId>incubator-directory</groupId>
       <artifactId>codec-stateful</artifactId>
       <version>SNAPSHOT</version>
-      <url>http://incubator.apache.org/directory/subprojects/ldap/common</url>
+      <url>http://incubator.apache.org/directory/subprojects/snickers/codec-stateful</url>
     </dependency>
   </dependencies>
-      
 </project>
 

Added: incubator/directory/seda/trunk/api/src/java/org/apache/seda/Enum.java
==============================================================================
--- (empty file)
+++ incubator/directory/seda/trunk/api/src/java/org/apache/seda/Enum.java	Tue Sep 14 16:48:33 2004
@@ -0,0 +1,616 @@
+/*
+ * Copyright 2002-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 java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * <p>Abstract superclass for type-safe enums.</p>
+ *
+ * <p>One feature of the C programming language lacking in Java is enumerations. The
+ * C implementation based on ints was poor and open to abuse. The original Java
+ * recommendation and most of the JDK also uses int constants. It has been recognised
+ * however that a more robust type-safe class-based solution can be designed. This
+ * class follows the basic Java type-safe enumeration pattern.</p>
+ *
+ * <p><em>NOTE:</em>Due to the way in which Java ClassLoaders work, comparing
+ * Enum objects should always be done using <code>equals()</code>, not <code>==</code>.
+ * The equals() method will try == first so in most cases the effect is the same.</p>
+ * 
+ * <p>Of course, if you actually want (or don't mind) Enums in different class
+ * loaders being non-equal, then you can use <code>==</code>.</p>
+ * 
+ * <h4>Simple Enums</h4>
+ *
+ * <p>To use this class, it must be subclassed. For example:</p>
+ *
+ * <pre>
+ * public final class ColorEnum extends Enum {
+ *   public static final ColorEnum RED = new ColorEnum("Red");
+ *   public static final ColorEnum GREEN = new ColorEnum("Green");
+ *   public static final ColorEnum BLUE = new ColorEnum("Blue");
+ *
+ *   private ColorEnum(String color) {
+ *     super(color);
+ *   }
+ * 
+ *   public static ColorEnum getEnum(String color) {
+ *     return (ColorEnum) getEnum(ColorEnum.class, color);
+ *   }
+ * 
+ *   public static Map getEnumMap() {
+ *     return getEnumMap(ColorEnum.class);
+ *   }
+ * 
+ *   public static List getEnumList() {
+ *     return getEnumList(ColorEnum.class);
+ *   }
+ * 
+ *   public static Iterator iterator() {
+ *     return iterator(ColorEnum.class);
+ *   }
+ * }
+ * </pre>
+ *
+ * <p>As shown, each enum has a name. This can be accessed using <code>getName</code>.</p>
+ *
+ * <p>The <code>getEnum</code> and <code>iterator</code> methods are recommended.
+ * Unfortunately, Java restrictions require these to be coded as shown in each subclass.
+ * An alternative choice is to use the {@link EnumUtils} class.</p>
+ * 
+ * <h4>Subclassed Enums</h4>
+ * <p>A hierarchy of Enum classes can be built. In this case, the superclass is
+ * unaffected by the addition of subclasses (as per normal Java). The subclasses
+ * may add additional Enum constants <em>of the type of the superclass</em>. The
+ * query methods on the subclass will return all of the Enum constants from the
+ * superclass and subclass.</p>
+ *
+ * <pre>
+ * public final class ExtraColorEnum extends ColorEnum {
+ *   // NOTE: Color enum declared above is final, change that to get this
+ *   // example to compile.
+ *   public static final ColorEnum YELLOW = new ExtraColorEnum("Yellow");
+ *
+ *   private ExtraColorEnum(String color) {
+ *     super(color);
+ *   }
+ * 
+ *   public static ColorEnum getEnum(String color) {
+ *     return (ColorEnum) getEnum(ExtraColorEnum.class, color);
+ *   }
+ * 
+ *   public static Map getEnumMap() {
+ *     return getEnumMap(ExtraColorEnum.class);
+ *   }
+ * 
+ *   public static List getEnumList() {
+ *     return getEnumList(ExtraColorEnum.class);
+ *   }
+ * 
+ *   public static Iterator iterator() {
+ *     return iterator(ExtraColorEnum.class);
+ *   }
+ * }
+ * </pre>
+ *
+ * <p>This example will return RED, GREEN, BLUE, YELLOW from the List and iterator
+ * methods in that order. The RED, GREEN and BLUE instances will be the same (==) 
+ * as those from the superclass ColorEnum. Note that YELLOW is declared as a
+ * ColorEnum and not an ExtraColorEnum.</p>
+ * 
+ * <h4>Functional Enums</h4>
+ *
+ * <p>The enums can have functionality by defining subclasses and
+ * overriding the <code>getEnumClass()</code> method:</p>
+ * 
+ * <pre>
+ *   public static final OperationEnum PLUS = new PlusOperation();
+ *   private static final class PlusOperation extends OperationEnum {
+ *     private PlusOperation() {
+ *       super("Plus");
+ *     }
+ *     public int eval(int a, int b) {
+ *       return (a + b);
+ *     }
+ *   }
+ *   public static final OperationEnum MINUS = new MinusOperation();
+ *   private static final class MinusOperation extends OperationEnum {
+ *     private MinusOperation() {
+ *       super("Minus");
+ *     }
+ *     public int eval(int a, int b) {
+ *       return (a - b);
+ *     }
+ *   }
+ *
+ *   private OperationEnum(String color) {
+ *     super(color);
+ *   }
+ * 
+ *   public final Class getEnumClass() {     // NOTE: new method!
+ *     return OperationEnum.class;
+ *   }
+ *
+ *   public abstract double eval(double a, double b);
+ * 
+ *   public static OperationEnum getEnum(String name) {
+ *     return (OperationEnum) getEnum(OperationEnum.class, name);
+ *   }
+ * 
+ *   public static Map getEnumMap() {
+ *     return getEnumMap(OperationEnum.class);
+ *   }
+ * 
+ *   public static List getEnumList() {
+ *     return getEnumList(OperationEnum.class);
+ *   }
+ * 
+ *   public static Iterator iterator() {
+ *     return iterator(OperationEnum.class);
+ *   }
+ * }
+ * </pre>
+ * <p>The code above will work on JDK 1.2. If JDK1.3 and later is used,
+ * the subclasses may be defined as anonymous.</p>
+ * 
+ * <h4>Nested class Enums</h4>
+ *
+ * <p>Care must be taken with class loading when defining a static nested class
+ * for enums. The static nested class can be loaded without the surrounding outer
+ * class being loaded. This can result in an empty list/map/iterator being returned.
+ * One solution is to define a static block that references the outer class where
+ * the constants are defined. For example:</p>
+ *
+ * <pre>
+ * public final class Outer {
+ *   public static final BWEnum BLACK = new BWEnum("Black");
+ *   public static final BWEnum WHITE = new BWEnum("White");
+ *
+ *   // static nested enum class
+ *   public static final class BWEnum extends Enum {
+ * 
+ *     static {
+ *       // explicitly reference BWEnum class to force constants to load
+ *       Object obj = Outer.BLACK;
+ *     }
+ * 
+ *     // ... other methods omitted
+ *   }
+ * }
+ * </pre>
+ * 
+ * <p>Although the above solves the problem, it is not recommended. The best solution
+ * is to define the constants in the enum class, and hold references in the outer class:
+ *
+ * <pre>
+ * public final class Outer {
+ *   public static final BWEnum BLACK = BWEnum.BLACK;
+ *   public static final BWEnum WHITE = BWEnum.WHITE;
+ *
+ *   // static nested enum class
+ *   public static final class BWEnum extends Enum {
+ *     // only define constants in enum classes - private if desired
+ *     private static final BWEnum BLACK = new BWEnum("Black");
+ *     private static final BWEnum WHITE = new BWEnum("White");
+ * 
+ *     // ... other methods omitted
+ *   }
+ * }
+ * </pre>
+ * 
+ * <p>For more details, see the 'Nested' test cases.
+ * 
+ * @see org.apache.seda.Enum
+ * @author Apache Avalon project
+ * @author Stephen Colebourne
+ * @author Chris Webb
+ * @author Mike Bowler
+ * @since 1.0
+ * @version $Id: Enum.java,v 1.28 2004/02/23 04:34:20 ggregory Exp $
+ */
+public abstract class Enum implements Comparable, Serializable {
+
+    /** Lang version 1.0.1 serial compatibility */
+    private static final long serialVersionUID = -487045951170455942L;
+    
+    // After discussion, the default size for HashMaps is used, as the
+    // sizing algorithm changes across the JDK versions
+    /**
+     * An empty <code>Map</code>, as JDK1.2 didn't have an empty map.
+     */
+    private static final Map EMPTY_MAP = Collections.unmodifiableMap(new HashMap(0));
+    
+    /**
+     * <code>Map</code>, key of class name, value of <code>Entry</code>.
+     */
+    private static final Map cEnumClasses = new HashMap();
+    
+    /**
+     * The string representation of the Enum.
+     */
+    private final String iName;
+    
+    /**
+     * The hashcode representation of the Enum.
+     */
+    private transient final int iHashCode;
+    
+    /**
+     * The toString representation of the Enum.
+     * @since 2.0
+     */
+    protected transient String iToString = null;
+
+    /**
+     * <p>Enable the iterator to retain the source code order.</p>
+     */
+    private static class Entry {
+        /**
+         * Map of Enum name to Enum.
+         */
+        final Map map = new HashMap();
+        /**
+         * Map of Enum name to Enum.
+         */
+        final Map unmodifiableMap = Collections.unmodifiableMap(map);
+        /**
+         * List of Enums in source code order.
+         */
+        final List list = new ArrayList(25);
+        /**
+         * Map of Enum name to Enum.
+         */
+        final List unmodifiableList = Collections.unmodifiableList(list);
+
+        /**
+         * <p>Restrictive constructor.</p>
+         */
+        private Entry() {
+        }
+    }
+
+    /**
+     * <p>Constructor to add a new named item to the enumeration.</p>
+     *
+     * @param name  the name of the enum object,
+     *  must not be empty or <code>null</code>
+     * @throws IllegalArgumentException if the name is <code>null</code>
+     *  or an empty string
+     * @throws IllegalArgumentException if the getEnumClass() method returns
+     *  a null or invalid Class
+     */
+    protected Enum(String name) {
+        super();
+        init(name);
+        iName = name;
+        iHashCode = 7 + getEnumClass().hashCode() + 3 * name.hashCode();
+        // cannot create toString here as subclasses may want to include other data
+    }
+
+    /**
+     * Initializes the enumeration.
+     * 
+     * @param name  the enum name
+     * @throws IllegalArgumentException if the name is null or empty or duplicate
+     * @throws IllegalArgumentException if the enumClass is null or invalid
+     */
+    private void init(String name) {
+        if ( name == null || name.equals( "" ) ) {
+            throw new IllegalArgumentException("The Enum name must not be empty or null");
+        }
+        
+        Class enumClass = getEnumClass();
+        if (enumClass == null) {
+            throw new IllegalArgumentException("getEnumClass() must not be null");
+        }
+        Class cls = getClass();
+        boolean ok = false;
+        while (cls != null && cls != Enum.class && cls != ValuedEnum.class) {
+            if (cls == enumClass) {
+                ok = true;
+                break;
+            }
+            cls = cls.getSuperclass();
+        }
+        if (ok == false) {
+            throw new IllegalArgumentException("getEnumClass() must return a superclass of this class");
+        }
+        
+        // create entry
+        Entry entry = (Entry) cEnumClasses.get(enumClass);
+        if (entry == null) {
+            entry = createEntry(enumClass);
+            cEnumClasses.put(enumClass, entry);
+        }
+        if (entry.map.containsKey(name)) {
+            throw new IllegalArgumentException("The Enum name must be unique, '" + name + "' has already been added");
+        }
+        entry.map.put(name, this);
+        entry.list.add(this);
+    }
+
+    /**
+     * <p>Handle the deserialization of the class to ensure that multiple
+     * copies are not wastefully created, or illegal enum types created.</p>
+     *
+     * @return the resolved object
+     */
+    protected Object readResolve() {
+        Entry entry = (Entry) cEnumClasses.get(getEnumClass());
+        if (entry == null) {
+            return null;
+        }
+        return (Enum) entry.map.get(getName());
+    }
+    
+    //--------------------------------------------------------------------------------
+
+    /**
+     * <p>Gets an <code>Enum</code> object by class and name.</p>
+     * 
+     * @param enumClass  the class of the Enum to get, must not
+     *  be <code>null</code>
+     * @param name  the name of the <code>Enum</code> to get,
+     *  may be <code>null</code>
+     * @return the enum object, or null if the enum does not exist
+     * @throws IllegalArgumentException if the enum class
+     *  is <code>null</code>
+     */
+    protected static Enum getEnum(Class enumClass, String name) {
+        Entry entry = getEntry(enumClass);
+        if (entry == null) {
+            return null;
+        }
+        return (Enum) entry.map.get(name);
+    }
+
+    /**
+     * <p>Gets the <code>Map</code> of <code>Enum</code> objects by
+     * name using the <code>Enum</code> class.</p>
+     *
+     * <p>If the requested class has no enum objects an empty
+     * <code>Map</code> is returned.</p>
+     * 
+     * @param enumClass  the class of the <code>Enum</code> to get,
+     *  must not be <code>null</code>
+     * @return the enum object Map
+     * @throws IllegalArgumentException if the enum class is <code>null</code>
+     * @throws IllegalArgumentException if the enum class is not a subclass of Enum
+     */
+    protected static Map getEnumMap(Class enumClass) {
+        Entry entry = getEntry(enumClass);
+        if (entry == null) {
+            return EMPTY_MAP;
+        }
+        return entry.unmodifiableMap;
+    }
+
+    /**
+     * <p>Gets the <code>List</code> of <code>Enum</code> objects using the
+     * <code>Enum</code> class.</p>
+     *
+     * <p>The list is in the order that the objects were created (source code order).
+     * If the requested class has no enum objects an empty <code>List</code> is
+     * returned.</p>
+     * 
+     * @param enumClass  the class of the <code>Enum</code> to get,
+     *  must not be <code>null</code>
+     * @return the enum object Map
+     * @throws IllegalArgumentException if the enum class is <code>null</code>
+     * @throws IllegalArgumentException if the enum class is not a subclass of Enum
+     */
+    protected static List getEnumList(Class enumClass) {
+        Entry entry = getEntry(enumClass);
+        if (entry == null) {
+            return Collections.EMPTY_LIST;
+        }
+        return entry.unmodifiableList;
+    }
+
+    /**
+     * <p>Gets an <code>Iterator</code> over the <code>Enum</code> objects in
+     * an <code>Enum</code> class.</p>
+     *
+     * <p>The <code>Iterator</code> is in the order that the objects were
+     * created (source code order). If the requested class has no enum
+     * objects an empty <code>Iterator</code> is returned.</p>
+     * 
+     * @param enumClass  the class of the <code>Enum</code> to get,
+     *  must not be <code>null</code>
+     * @return an iterator of the Enum objects
+     * @throws IllegalArgumentException if the enum class is <code>null</code>
+     * @throws IllegalArgumentException if the enum class is not a subclass of Enum
+     */
+    protected static Iterator iterator(Class enumClass) {
+        return Enum.getEnumList(enumClass).iterator();
+    }
+
+    //-----------------------------------------------------------------------
+    /**
+     * <p>Gets an <code>Entry</code> from the map of Enums.</p>
+     * 
+     * @param enumClass  the class of the <code>Enum</code> to get
+     * @return the enum entry
+     */
+    private static Entry getEntry(Class enumClass) {
+        if (enumClass == null) {
+            throw new IllegalArgumentException("The Enum Class must not be null");
+        }
+        if (Enum.class.isAssignableFrom(enumClass) == false) {
+            throw new IllegalArgumentException("The Class must be a subclass of Enum");
+        }
+        Entry entry = (Entry) cEnumClasses.get(enumClass);
+        return entry;
+    }
+    
+    /**
+     * <p>Creates an <code>Entry</code> for storing the Enums.</p>
+     *
+     * <p>This accounts for subclassed Enums.</p>
+     * 
+     * @param enumClass  the class of the <code>Enum</code> to get
+     * @return the enum entry
+     */
+    private static Entry createEntry(Class enumClass) {
+        Entry entry = new Entry();
+        Class cls = enumClass.getSuperclass();
+        while (cls != null && cls != Enum.class && cls != ValuedEnum.class) {
+            Entry loopEntry = (Entry) cEnumClasses.get(cls);
+            if (loopEntry != null) {
+                entry.list.addAll(loopEntry.list);
+                entry.map.putAll(loopEntry.map);
+                break;  // stop here, as this will already have had superclasses added
+            }
+            cls = cls.getSuperclass();
+        }
+        return entry;
+    }
+    
+    //-----------------------------------------------------------------------
+    /**
+     * <p>Retrieve the name of this Enum item, set in the constructor.</p>
+     * 
+     * @return the <code>String</code> name of this Enum item
+     */
+    public final String getName() {
+        return iName;
+    }
+
+    /**
+     * <p>Retrieves the Class of this Enum item, set in the constructor.</p>
+     * 
+     * <p>This is normally the same as <code>getClass()</code>, but for
+     * advanced Enums may be different. If overridden, it must return a
+     * constant value.</p>
+     * 
+     * @return the <code>Class</code> of the enum
+     * @since 2.0
+     */
+    public Class getEnumClass() {
+        return getClass();
+    }
+
+    /**
+     * <p>Tests for equality.</p>
+     *
+     * <p>Two Enum objects are considered equal
+     * if they have the same class names and the same names.
+     * Identity is tested for first, so this method usually runs fast.</p>
+     * 
+     * <p>If the parameter is in a different class loader than this instance,
+     * reflection is used to compare the names.</p>
+     *
+     * @param other  the other object to compare for equality
+     * @return <code>true</code> if the Enums are equal
+     */
+    public final boolean equals(Object other) {
+        if (other == this) {
+            return true;
+        } else if (other == null) {
+            return false;
+        } else if (other.getClass() == this.getClass()) {
+            // Ok to do a class cast to Enum here since the test above
+            // guarantee both
+            // classes are in the same class loader.
+            return iName.equals(((Enum) other).iName);
+        } else {
+            // This and other are in different class loaders, we must use reflection.
+            try {
+                Method mth = other.getClass().getMethod("getName", null);
+                String name = (String) mth.invoke(other, null);
+                return iName.equals(name);
+            } catch (NoSuchMethodException e) {
+                // ignore - should never happen
+            } catch (IllegalAccessException e) {
+                // ignore - should never happen
+            } catch (InvocationTargetException e) {
+                // ignore - should never happen
+            }
+            return false;
+        }
+    }
+    
+    /**
+     * <p>Returns a suitable hashCode for the enumeration.</p>
+     *
+     * @return a hashcode based on the name
+     */
+    public final int hashCode() {
+        return iHashCode;
+    }
+
+    /**
+     * <p>Tests for order.</p>
+     *
+     * <p>The default ordering is alphabetic by name, but this
+     * can be overridden by subclasses.</p>
+     * 
+     * @see java.lang.Comparable#compareTo(Object)
+     * @param other  the other object to compare to
+     * @return -ve if this is less than the other object, +ve if greater
+     *  than, <code>0</code> of equal
+     * @throws ClassCastException if other is not an Enum
+     * @throws NullPointerException if other is <code>null</code>
+     */
+    public int compareTo(Object other) {
+        if (other == this) {
+            return 0;
+        }
+        return iName.compareTo(((Enum) other).iName);
+    }
+
+    /**
+     * <p>Human readable description of this Enum item.</p>
+     * 
+     * @return String in the form <code>type[name]</code>, for example:
+     * <code>Color[Red]</code>. Note that the package name is stripped from
+     * the type name.
+     */
+    public String toString() {
+        if (iToString == null) {
+            String shortName = null;
+
+            if ( getEnumClass() == null )
+            {
+                shortName = "";
+            }
+            else {
+                char[] chars = getEnumClass().getClass().getName().toCharArray();
+                int lastDot = 0;
+                for (int i = 0; i < chars.length; i++) {
+                    if (chars[i] == '.') {
+                        lastDot = i + 1;
+                    } else if (chars[i] == '$') {  // handle inner classes
+                        chars[i] = '.';
+                    }
+                }
+                shortName = new String(chars, lastDot, chars.length - lastDot);
+            }
+
+            iToString = shortName + "[" + getName() + "]";
+        }
+        return iToString;
+    }
+}

Added: incubator/directory/seda/trunk/api/src/java/org/apache/seda/EnumUtils.java
==============================================================================
--- (empty file)
+++ incubator/directory/seda/trunk/api/src/java/org/apache/seda/EnumUtils.java	Tue Sep 14 16:48:33 2004
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2002-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 java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * <p>Utility class for accessing and manipulating {@link Enum}s.</p>
+ *
+ * @see org.apache.seda.EnumUtils
+ * @see Enum
+ * @see ValuedEnum
+ * @author Stephen Colebourne
+ * @author Gary Gregory
+ * @since 1.0
+ * @version $Id: EnumUtils.java,v 1.12 2004/02/23 04:34:20 ggregory Exp $
+ */
+public class EnumUtils {
+
+    /**
+     * Public constructor. This class should not normally be instantiated.
+     * @since 2.0
+     */
+    public EnumUtils() {
+    }
+
+    /**
+     * <p>Gets an <code>Enum</code> object by class and name.</p>
+     * 
+     * @param enumClass  the class of the <code>Enum</code> to get
+     * @param name  the name of the Enum to get, may be <code>null</code>
+     * @return the enum object
+     * @throws IllegalArgumentException if the enum class is <code>null</code>
+     */
+    public static Enum getEnum(Class enumClass, String name) {
+        return Enum.getEnum(enumClass, name);
+    }
+
+    /**
+     * <p>Gets a <code>ValuedEnum</code> object by class and value.</p>
+     * 
+     * @param enumClass  the class of the <code>Enum</code> to get
+     * @param value  the value of the <code>Enum</code> to get
+     * @return the enum object, or null if the enum does not exist
+     * @throws IllegalArgumentException if the enum class is <code>null</code>
+     */
+    public static ValuedEnum getEnum(Class enumClass, int value) {
+        return (ValuedEnum) ValuedEnum.getEnum(enumClass, value);
+    }
+
+    /**
+     * <p>Gets the <code>Map</code> of <code>Enum</code> objects by
+     * name using the <code>Enum</code> class.</p>
+     *
+     * <p>If the requested class has no enum objects an empty
+     * <code>Map</code> is returned. The <code>Map</code> is unmodifiable.</p>
+     * 
+     * @param enumClass  the class of the <code>Enum</code> to get
+     * @return the enum object Map
+     * @throws IllegalArgumentException if the enum class is <code>null</code>
+     * @throws IllegalArgumentException if the enum class is not a subclass
+     *  of <code>Enum</code>
+     */
+    public static Map getEnumMap(Class enumClass) {
+        return Enum.getEnumMap(enumClass);
+    }
+
+    /**
+     * <p>Gets the <code>List</code> of <code>Enum</code> objects using
+     * the <code>Enum</code> class.</p>
+     *
+     * <p>The list is in the order that the objects were created
+     * (source code order).</p>
+     *
+     * <p>If the requested class has no enum objects an empty
+     * <code>List</code> is returned. The <code>List</code> is unmodifiable.</p>
+     * 
+     * @param enumClass  the class of the Enum to get
+     * @return the enum object Map
+     * @throws IllegalArgumentException if the enum class is <code>null</code>
+     * @throws IllegalArgumentException if the enum class is not a subclass
+     *  of <code>Enum</code>
+     */
+    public static List getEnumList(Class enumClass) {
+        return Enum.getEnumList(enumClass);
+    }
+
+    /**
+     * <p>Gets an <code>Iterator</code> over the <code>Enum</code> objects
+     * in an <code>Enum</code> class.</p>
+     *
+     * <p>The iterator is in the order that the objects were created
+     * (source code order).</p>
+     *
+     * <p>If the requested class has no enum objects an empty
+     * <code>Iterator</code> is returned. The <code>Iterator</code>
+     * is unmodifiable.</p>
+     * 
+     * @param enumClass  the class of the <code>Enum</code> to get
+     * @return an <code>Iterator</code> of the <code>Enum</code> objects
+     * @throws IllegalArgumentException if the enum class is <code>null</code>
+     * @throws IllegalArgumentException if the enum class is not a subclass of <code>Enum</code>
+     */
+    public static Iterator iterator(Class enumClass) {
+        return Enum.getEnumList(enumClass).iterator();
+    }
+    
+}

Added: incubator/directory/seda/trunk/api/src/java/org/apache/seda/ValuedEnum.java
==============================================================================
--- (empty file)
+++ incubator/directory/seda/trunk/api/src/java/org/apache/seda/ValuedEnum.java	Tue Sep 14 16:48:33 2004
@@ -0,0 +1,205 @@
+/*
+ * Copyright 2002-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 java.util.Iterator;
+import java.util.List;
+
+
+/**
+ * <p>Abstract superclass for type-safe enums with integer values suitable
+ * for use in <code>switch</code> statements.</p>
+ *
+ * <p><em>NOTE:</em>Due to the way in which Java ClassLoaders work, comparing
+ * <code>Enum</code> objects should always be done using the equals() method,
+ * not <code>==</code>. The equals() method will try <code>==</code> first so
+ * in most cases the effect is the same.</p>
+ *
+ * <p>To use this class, it must be subclassed. For example:</p>
+ *
+ * <pre>
+ * public final class JavaVersionEnum extends ValuedEnum {
+ *   //standard enums for version of JVM
+ *   public static final int  JAVA1_0_VALUE  = 100;
+ *   public static final int  JAVA1_1_VALUE  = 110;
+ *   public static final int  JAVA1_2_VALUE  = 120;
+ *   public static final int  JAVA1_3_VALUE  = 130;
+ *   public static final JavaVersionEnum  JAVA1_0  = new JavaVersionEnum( "Java 1.0", JAVA1_0_VALUE );
+ *   public static final JavaVersionEnum  JAVA1_1  = new JavaVersionEnum( "Java 1.1", JAVA1_1_VALUE );
+ *   public static final JavaVersionEnum  JAVA1_2  = new JavaVersionEnum( "Java 1.2", JAVA1_2_VALUE );
+ *   public static final JavaVersionEnum  JAVA1_3  = new JavaVersionEnum( "Java 1.3", JAVA1_3_VALUE );
+ *
+ *   private JavaVersionEnum(String name, int value) {
+ *     super( name, value );
+ *   }
+ * 
+ *   public static JavaVersionEnum getEnum(String javaVersion) {
+ *     return (JavaVersionEnum) getEnum(JavaVersionEnum.class, javaVersion);
+ *   }
+ * 
+ *   public static JavaVersionEnum getEnum(int javaVersion) {
+ *     return (JavaVersionEnum) getEnum(JavaVersionEnum.class, javaVersion);
+ *   }
+ * 
+ *   public static Map getEnumMap() {
+ *     return getEnumMap(JavaVersionEnum.class);
+ *   }
+ * 
+ *   public static List getEnumList() {
+ *     return getEnumList(JavaVersionEnum.class);
+ *   }
+ * 
+ *   public static Iterator iterator() {
+ *     return iterator(JavaVersionEnum.class);
+ *   }
+ * }
+ * </pre>
+ *
+ * <p>The above class could then be used as follows:</p>
+ *
+ * <pre>
+ * public void doSomething(JavaVersion ver) {
+ *   switch (ver.getValue()) {
+ *     case JAVA1_0_VALUE:
+ *       // ...
+ *       break;
+ *     case JAVA1_1_VALUE:
+ *       // ...
+ *       break;
+ *     //...
+ *   }
+ * }
+ * </pre>
+ *
+ * <p>As shown, each enum has a name and a value. These can be accessed using
+ * <code>getName</code> and <code>getValue</code>.</p>
+ *
+ * <p>The <code>getEnum</code> and <code>iterator</code> methods are recommended.
+ * Unfortunately, Java restrictions require these to be coded as shown in each subclass.
+ * An alternative choice is to use the {@link EnumUtils} class.</p>
+ *
+ * @see org.apache.seda.ValuedEnum
+ * @author Apache Avalon project
+ * @author Stephen Colebourne
+ * @since 1.0
+ * @version $Id: ValuedEnum.java,v 1.16 2004/02/23 04:34:20 ggregory Exp $
+ */
+public abstract class ValuedEnum extends Enum {
+    
+    /** Lang version 1.0.1 serial compatibility */
+    private static final long serialVersionUID = -7129650521543789085L;
+    
+    /**
+     * The value contained in enum.
+     */
+    private final int iValue;
+
+    /**
+     * Constructor for enum item.
+     *
+     * @param name  the name of enum item
+     * @param value  the value of enum item
+     */
+    protected ValuedEnum(String name, int value) {
+        super(name);
+        iValue = value;
+    }
+
+    /**
+     * <p>Gets an <code>Enum</code> object by class and value.</p>
+     *
+     * <p>This method loops through the list of <code>Enum</code>,
+     * thus if there are many <code>Enum</code>s this will be
+     * slow.</p>
+     * 
+     * @param enumClass  the class of the <code>Enum</code> to get
+     * @param value  the value of the <code>Enum</code> to get
+     * @return the enum object, or null if the enum does not exist
+     * @throws IllegalArgumentException if the enum class is <code>null</code>
+     */
+    protected static Enum getEnum(Class enumClass, int value) {
+        if (enumClass == null) {
+            throw new IllegalArgumentException("The Enum Class must not be null");
+        }
+        List list = Enum.getEnumList(enumClass);
+        for (Iterator it = list.iterator(); it.hasNext();) {
+            ValuedEnum enum = (ValuedEnum) it.next();
+            if (enum.getValue() == value) {
+                return enum;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * <p>Get value of enum item.</p>
+     *
+     * @return the enum item's value.
+     */
+    public final int getValue() {
+        return iValue;
+    }
+
+    /**
+     * <p>Tests for order.</p>
+     *
+     * <p>The default ordering is numeric by value, but this
+     * can be overridden by subclasses.</p>
+     * 
+     * @see java.lang.Comparable#compareTo(Object)
+     * @param other  the other object to compare to
+     * @return -ve if this is less than the other object, +ve if greater than,
+     *  <code>0</code> of equal
+     * @throws ClassCastException if other is not an <code>Enum</code>
+     * @throws NullPointerException if other is <code>null</code>
+     */
+    public int compareTo(Object other) {
+        return iValue - ((ValuedEnum) other).iValue;
+    }
+
+    /**
+     * <p>Human readable description of this <code>Enum</code> item.</p>
+     *
+     * @return String in the form <code>type[name=value]</code>, for example:
+     *  <code>JavaVersion[Java 1.0=100]</code>. Note that the package name is
+     *  stripped from the type name.
+     */
+    public String toString() {
+        if (iToString == null) {
+            String shortName = null;
+
+            if ( getEnumClass() == null )
+            {
+                shortName = "";
+            }
+            else {
+                char[] chars = getEnumClass().getClass().getName().toCharArray();
+                int lastDot = 0;
+                for (int i = 0; i < chars.length; i++) {
+                    if (chars[i] == '.') {
+                        lastDot = i + 1;
+                    } else if (chars[i] == '$') {  // handle inner classes
+                        chars[i] = '.';
+                    }
+                }
+                shortName = new String(chars, lastDot, chars.length - lastDot);
+            }
+
+            iToString = shortName + "[" + getName() + "=" + getValue() + "]";
+        }
+        return iToString;
+    }
+}

Modified: incubator/directory/seda/trunk/api/src/java/org/apache/seda/input/InputManagerMonitorAdapter.java
==============================================================================
--- incubator/directory/seda/trunk/api/src/java/org/apache/seda/input/InputManagerMonitorAdapter.java	(original)
+++ incubator/directory/seda/trunk/api/src/java/org/apache/seda/input/InputManagerMonitorAdapter.java	Tue Sep 14 16:48:33 2004
@@ -24,8 +24,6 @@
 import java.nio.channels.SelectionKey;
 import java.nio.channels.SocketChannel;
 
-import org.apache.commons.lang.exception.ExceptionUtils;
-
 import org.apache.seda.ResourceException;
 import org.apache.seda.buffer.BufferPool;
 import org.apache.seda.listener.ClientKey;
@@ -83,10 +81,10 @@
      */
     public void selectFailure( Selector selector, IOException fault )
     {
-        System.err.println( ExceptionUtils.getFullStackTrace( fault ) );
+        dump( fault );
     }
 
-    
+
     /* (non-Javadoc)
      * @see org.apache.seda.input.InputManagerMonitor#keyExpiryFailure(
      * org.apache.seda.listener.ClientKey,
@@ -94,7 +92,7 @@
      */
     public void keyExpiryFailure( ClientKey key, KeyExpiryException fault )
     {
-        System.err.println( ExceptionUtils.getFullStackTrace( fault ) );
+        dump( fault );
     }
 
     
@@ -104,7 +102,7 @@
      */
     public void readFailed( ClientKey key, IOException fault ) 
     {
-        System.err.println( ExceptionUtils.getFullStackTrace( fault ) );
+        dump( fault );
     }
     
 
@@ -115,7 +113,7 @@
      */
     public void bufferUnavailable( BufferPool bp, ResourceException fault )
     {
-        System.err.println( ExceptionUtils.getFullStackTrace( fault ) );
+        dump( fault );
     }
 
     
@@ -127,7 +125,7 @@
     public void channelRegistrationFailure( Selector selector,
         SocketChannel channel, int key, IOException fault)
     {
-        System.err.println( ExceptionUtils.getFullStackTrace( fault ) );
+        dump( fault );
     }
 
     
@@ -138,7 +136,7 @@
     public void channelCloseFailure( SocketChannel channel, 
                                      IOException fault )
     {
-        System.err.println( ExceptionUtils.getFullStackTrace( fault ) );
+        dump( fault );
     }
     
     
@@ -175,5 +173,19 @@
      */
     public void cleanedStaleKey( SelectionKey key )
     {
+    }
+
+
+    /**
+     * Perform simple null pointer check before dumping a stack trace.
+     *
+     * @param t the throwables stack to dump to stderr
+     */
+    private void dump( Throwable t )
+    {
+        if ( t != null )
+        {
+            t.printStackTrace();
+        }
     }
 }

Modified: incubator/directory/seda/trunk/api/src/java/org/apache/seda/output/OutputMonitorAdapter.java
==============================================================================
--- incubator/directory/seda/trunk/api/src/java/org/apache/seda/output/OutputMonitorAdapter.java	(original)
+++ incubator/directory/seda/trunk/api/src/java/org/apache/seda/output/OutputMonitorAdapter.java	Tue Sep 14 16:48:33 2004
@@ -19,8 +19,6 @@
 
 import java.util.EventObject;
 
-import org.apache.commons.lang.exception.ExceptionUtils;
-
 import org.apache.seda.event.ConnectEvent;
 import org.apache.seda.listener.ClientKey;
 import org.apache.seda.event.DisconnectEvent;
@@ -45,8 +43,7 @@
     public void failedOnWrite( OutputManager manager, ClientKey key,
                                Throwable t )
     {
-        System.err.println( "Failed on write to client " + key + ":\n" 
-                + ExceptionUtils.getFullStackTrace( t ) );
+        dump( t );
     }
 
     
@@ -74,7 +71,6 @@
      */
     public void channelMissing( OutputManager manager, ClientKey key )
     {
-        System.err.println( "Channel for client " + key + " missing." );
     }
 
     
@@ -86,8 +82,7 @@
     public void keyExpired( OutputManager manager, ClientKey key, 
                             KeyExpiryException e )
     {
-        System.err.println( "Key for client " + key + ":\n" 
-                + ExceptionUtils.getFullStackTrace( e ) );
+        dump( e );
     }
 
 
@@ -99,8 +94,7 @@
     public void failedOnInform( OutputManager manager, EventObject event,
             Throwable fault )
     {
-        System.err.println( "Failed to inform of " + event + ":\n" 
-                + ExceptionUtils.getFullStackTrace( fault ) );
+        dump( fault );
     }
 
     
@@ -120,5 +114,19 @@
      */
     public void removedClient( OutputManager manager, DisconnectEvent event )
     {
+    }
+
+
+    /**
+     * Perform simple null pointer check before dumping a stack trace.
+     *
+     * @param t the throwables stack to dump to stderr
+     */
+    private void dump( Throwable t )
+    {
+        if ( t != null )
+        {
+            t.printStackTrace();
+        }
     }
 }

Modified: incubator/directory/seda/trunk/api/src/java/org/apache/seda/protocol/HandlerTypeEnum.java
==============================================================================
--- incubator/directory/seda/trunk/api/src/java/org/apache/seda/protocol/HandlerTypeEnum.java	(original)
+++ incubator/directory/seda/trunk/api/src/java/org/apache/seda/protocol/HandlerTypeEnum.java	Tue Sep 14 16:48:33 2004
@@ -17,7 +17,7 @@
 package org.apache.seda.protocol;
 
 
-import org.apache.commons.lang.enum.ValuedEnum;
+import org.apache.seda.ValuedEnum;
 
 
 /**

Modified: incubator/directory/seda/trunk/api/src/java/org/apache/seda/protocol/InetServicesDatabase.java
==============================================================================
--- incubator/directory/seda/trunk/api/src/java/org/apache/seda/protocol/InetServicesDatabase.java	(original)
+++ incubator/directory/seda/trunk/api/src/java/org/apache/seda/protocol/InetServicesDatabase.java	Tue Sep 14 16:48:33 2004
@@ -48,7 +48,7 @@
      * @param port the port one which the service resides
      * @return an Iterator over InetServiceEntry objects
      */
-    Iterator getByPort( String port );
+    Iterator getByPort( int port );
 
     /**
      * Gets the protocol associated with a port.

Modified: incubator/directory/seda/trunk/api/src/java/org/apache/seda/protocol/RequestProcessorMonitorAdapter.java
==============================================================================
--- incubator/directory/seda/trunk/api/src/java/org/apache/seda/protocol/RequestProcessorMonitorAdapter.java	(original)
+++ incubator/directory/seda/trunk/api/src/java/org/apache/seda/protocol/RequestProcessorMonitorAdapter.java	Tue Sep 14 16:48:33 2004
@@ -19,8 +19,6 @@
 
 import java.util.EventObject;
 
-import org.apache.commons.lang.exception.ExceptionUtils;
-
 import org.apache.seda.event.Subscriber;
 import org.apache.seda.listener.ClientKey;
 

Modified: incubator/directory/seda/trunk/api/src/java/org/apache/seda/protocol/TransportTypeEnum.java
==============================================================================
--- incubator/directory/seda/trunk/api/src/java/org/apache/seda/protocol/TransportTypeEnum.java	(original)
+++ incubator/directory/seda/trunk/api/src/java/org/apache/seda/protocol/TransportTypeEnum.java	Tue Sep 14 16:48:33 2004
@@ -17,7 +17,7 @@
 package org.apache.seda.protocol;
 
 
-import org.apache.commons.lang.enum.ValuedEnum;
+import org.apache.seda.ValuedEnum;
 
 
 /**

Modified: incubator/directory/seda/trunk/impl/project.xml
==============================================================================
--- incubator/directory/seda/trunk/impl/project.xml	(original)
+++ incubator/directory/seda/trunk/impl/project.xml	Tue Sep 14 16:48:33 2004
@@ -20,74 +20,41 @@
   <dependencies>
 
     <dependency>
-      <groupId>concurrent</groupId>
-      <artifactId>concurrent</artifactId>
-      <version>1.3.1</version>
-      <url>http://ultisque.notlong.com</url>
+      <groupId>commons-logging</groupId>                        
+      <artifactId>commons-logging</artifactId>
+      <version>1.0.3</version>
+      <url>http://jakarta.apache.org/commons/logging</url>
     </dependency>
-      
-    <!-- We need to get rid of this dependency on commons-codec -->
+
     <dependency>
-      <groupId>commons-codec</groupId>
-      <artifactId>commons-codec</artifactId>
+      <groupId>incubator-directory</groupId>
+      <artifactId>seda-api</artifactId>
       <version>SNAPSHOT</version>
-      <url>http://jakarta.apache.org/commons/codec</url>
-    </dependency>
-      
-    <dependency>
-      <groupId>commons-lang</groupId>
-      <artifactId>commons-lang</artifactId>
-      <version>2.0</version>
-      <url>http://jakarta.apache.org/commons/lang</url>
+      <url>http://incubator.apache.org/directory/subprojects/seda</url>
     </dependency>
 
     <dependency>
-      <groupId>commons-primitives</groupId>
-      <artifactId>commons-primitives</artifactId>
+      <groupId>incubator-directory</groupId>
+      <artifactId>codec-stateful</artifactId>
       <version>SNAPSHOT</version>
-      <url>http://jakarta.apache.org/commons/primitives</url>
+      <url>http://incubator.apache.org/directory/subprojects/ldap/common</url>
     </dependency>
 
-    <dependency>
-      <groupId>commons-collections</groupId>
-      <artifactId>commons-collections</artifactId>
-      <version>2.1</version>
-      <url>http://jakarta.apache.org/commons/collections</url>
-    </dependency>
+    <!-- Dependencies required for running test cases -->
 
+    <!-- THIS SHOULD ONLY BE USED FOR TESTING -->
     <dependency>
-      <groupId>commons-logging</groupId>
-      <artifactId>commons-logging</artifactId>
-      <version>1.0.3</version>
-      <url>http://jakarta.apache.org/commons/logging</url>
+      <groupId>commons-threadpool</groupId>
+      <artifactId>commons-threadpool</artifactId>
+      <version>1.0-dev</version>
+      <url>http://jakarta.apache.org/commons/sandbox/threadpool</url>
     </dependency>
 
     <dependency>
-      <groupId>commons-primitives</groupId>
-      <artifactId>commons-primitives</artifactId>
-      <version>1.1-dev</version>
-      <url>http://jakarta.apache.org/commons/primitives</url>
-    </dependency>
-        
-    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>3.8.1</version>
       <url>http://junit.org</url>
-    </dependency>
-
-    <dependency>
-      <groupId>incubator-directory</groupId>
-      <artifactId>seda-api</artifactId>
-      <version>SNAPSHOT</version>
-      <url>http://incubator.apache.org/directory/subprojects/seda</url>
-    </dependency>
-
-    <dependency>
-      <groupId>incubator-directory</groupId>
-      <artifactId>codec-stateful</artifactId>
-      <version>SNAPSHOT</version>
-      <url>http://incubator.apache.org/directory/subprojects/ldap/common</url>
     </dependency>
 
   </dependencies>

Modified: incubator/directory/seda/trunk/impl/src/java/org/apache/seda/DefaultFrontend.java
==============================================================================
--- incubator/directory/seda/trunk/impl/src/java/org/apache/seda/DefaultFrontend.java	(original)
+++ incubator/directory/seda/trunk/impl/src/java/org/apache/seda/DefaultFrontend.java	Tue Sep 14 16:48:33 2004
@@ -17,6 +17,17 @@
 package org.apache.seda;
 
 
+import org.apache.seda.buffer.BufferPool;
+import org.apache.seda.event.EventRouter;
+import org.apache.seda.decoder.DecoderManager;
+import org.apache.seda.encoder.EncoderManager;
+import org.apache.seda.input.InputManager;
+import org.apache.seda.listener.ListenerManager;
+import org.apache.seda.output.OutputManager;
+import org.apache.seda.protocol.RequestProcessor;
+import org.apache.seda.protocol.InetServicesDatabase;
+
+
 /**
  * A container neutral implementation of the Eve frontend.  There really is 
  * nothing here but this will evolve as we determine the use cases for 
@@ -28,4 +39,30 @@
  */
 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;
+
+    DefaultFrontend( BufferPool bp, DecoderManager decMan, 
+                     EncoderManager encMan, EventRouter router, 
+                     InputManager inMan, ListenerManager srvMan,
+                     OutputManager outMan, RequestProcessor reqProc,
+                     InetServicesDatabase inetDb )
+    {
+        this.bp = bp;
+        this.decMan = decMan;
+        this.encMan = encMan;
+        this.router = router;
+        this.inMan = inMan;
+        this.srvMan = srvMan;
+        this.outMan = outMan;
+        this.reqProc = reqProc;
+        this.inetDb = inetDb;
+    }
 }

Added: incubator/directory/seda/trunk/impl/src/java/org/apache/seda/DefaultFrontendFactory.java
==============================================================================
--- (empty file)
+++ incubator/directory/seda/trunk/impl/src/java/org/apache/seda/DefaultFrontendFactory.java	Tue Sep 14 16:48:33 2004
@@ -0,0 +1,168 @@
+/*
+ *   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 org.apache.seda.buffer.BufferPool;
+import org.apache.seda.buffer.DefaultBufferPool;
+import org.apache.seda.buffer.DefaultBufferPoolConfig;
+import org.apache.seda.event.EventRouter;
+import org.apache.seda.event.DefaultEventRouter;
+import org.apache.seda.protocol.*;
+import org.apache.seda.decoder.DecoderManager;
+import org.apache.seda.decoder.DefaultDecoderManager;
+import org.apache.seda.decoder.DecodeStageHandler;
+import org.apache.seda.stage.DefaultStageConfig;
+import org.apache.seda.thread.ThreadPool;
+import org.apache.seda.encoder.EncoderManager;
+import org.apache.seda.encoder.DefaultEncoderManager;
+import org.apache.seda.encoder.EncodeStageHandler;
+import org.apache.seda.listener.ListenerManager;
+import org.apache.seda.listener.DefaultListenerManager;
+import org.apache.seda.input.InputManager;
+import org.apache.seda.input.DefaultInputManager;
+import org.apache.seda.output.OutputManager;
+import org.apache.seda.output.DefaultOutputManager;
+import org.apache.commons.threadpool.DefaultThreadPool;
+
+import java.io.IOException;
+
+
+/**
+ * Document me.
+ *
+ * @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
+    {
+        // create all services that do not have any deps on other services
+        BufferPool bp = createBufferPool();
+        EventRouter router = createEventRouter();
+        InetServicesDatabase inetDb = createServicesDatabase();
+
+        // create dependent services in order
+        ListenerManager listMan = createListenerManager( router );
+        InputManager inMan = createInputManager( router, bp );
+        OutputManager outMan = createOutputManager( router );
+        DecoderManager decMan = createDecoderManager( router, inetDb );
+        EncoderManager encMan = createEncoderManager( router, inetDb );
+        RequestProcessor reqProc = createRequestProcessor( router );
+
+        DefaultFrontend fe = new DefaultFrontend( bp, decMan, encMan, router,
+            inMan, listMan, outMan, reqProc, inetDb );
+        return fe;
+    }
+
+
+    // no deps
+    private BufferPool createBufferPool()
+    {
+        DefaultBufferPoolConfig config = new DefaultBufferPoolConfig(
+            "", 10, 100, 20, 20 );
+        return new DefaultBufferPool( config ) ;
+    }
+
+
+    // no deps
+    private EventRouter createEventRouter()
+    {
+        return new DefaultEventRouter();
+    }
+
+
+    // no deps
+    private InetServicesDatabase createServicesDatabase()
+    {
+        InetServiceEntry[] entries = { new InetServiceEntry( "ldap", 389 ) };
+        return new DefaultInetServicesDatabase( entries ) ;
+    }
+
+
+    // no deps
+    private ThreadPool createThreadPool( int threads )
+    {
+        final DefaultThreadPool ctp = new DefaultThreadPool( threads );
+        ThreadPool pool = new ThreadPool()
+        {
+            public void execute( Runnable runnable )
+            {
+                ctp.invokeLater( runnable );
+            }
+        };
+        return pool;
+    }
+
+
+    // deps on router, inetDb, and listener
+    private DecoderManager createDecoderManager( EventRouter router,
+                                                 InetServicesDatabase inetDb )
+    {
+        DefaultStageConfig config = new DefaultStageConfig( "decoderManager",
+            createThreadPool( 3 ) );
+        DefaultDecoderManager decMan = new DefaultDecoderManager( router,
+            config, inetDb );
+        DecodeStageHandler handler = new DecodeStageHandler( decMan );
+        config.setHandler( handler );
+        return new DefaultDecoderManager( router, config, inetDb );
+    }
+
+
+    // deps on router, inetDb, and listener
+    private EncoderManager createEncoderManager( EventRouter router,
+                                                 InetServicesDatabase inetDb )
+    {
+        DefaultStageConfig config = new DefaultStageConfig( "encoderManager",
+            createThreadPool( 3 ) );
+        DefaultEncoderManager encMan = new DefaultEncoderManager( router,
+            config, inetDb );
+        EncodeStageHandler handler = new EncodeStageHandler( encMan );
+        config.setHandler( handler );
+        return encMan;
+    }
+
+
+    private ListenerManager createListenerManager( EventRouter router )
+        throws IOException
+    {
+        return new DefaultListenerManager( router );
+    }
+
+
+    private InputManager createInputManager( EventRouter router, BufferPool bp )
+        throws IOException
+    {
+        return new DefaultInputManager( router, bp );
+    }
+
+
+    private OutputManager createOutputManager( EventRouter router )
+    {
+        DefaultStageConfig config = new DefaultStageConfig( "outputManager",
+            createThreadPool( 3 ) );
+        return new DefaultOutputManager( router, config );
+    }
+
+
+    private RequestProcessor createRequestProcessor( EventRouter router )
+    {
+        DefaultStageConfig config = new DefaultStageConfig( "requestProcessor",
+            createThreadPool( 3 ) );
+        return new DefaultRequestProcessor( router, config );
+    }
+}

Added: incubator/directory/seda/trunk/impl/src/java/org/apache/seda/FrontendFactory.java
==============================================================================
--- (empty file)
+++ incubator/directory/seda/trunk/impl/src/java/org/apache/seda/FrontendFactory.java	Tue Sep 14 16:48:33 2004
@@ -0,0 +1,30 @@
+/*
+ *   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 java.io.IOException;
+
+/**
+ * Document me.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface FrontendFactory
+{
+    Frontend create() throws IOException;
+}

Modified: incubator/directory/seda/trunk/impl/src/java/org/apache/seda/buffer/DefaultBufferPool.java
==============================================================================
--- incubator/directory/seda/trunk/impl/src/java/org/apache/seda/buffer/DefaultBufferPool.java	(original)
+++ incubator/directory/seda/trunk/impl/src/java/org/apache/seda/buffer/DefaultBufferPool.java	Tue Sep 14 16:48:33 2004
@@ -21,7 +21,6 @@
 
 import java.util.ArrayList;
 
-import org.apache.commons.lang.Validate;
 import org.apache.seda.ResourceException;
 
 
@@ -62,9 +61,9 @@
 
         for( int ii = 0; ii < this.config.getInitialSize(); ii++ )
         {
-            BufferListPair l_list = new BufferListPair();
-            this.freeList.add( l_list );
-            this.allList.add( l_list );
+            BufferListPair list = new BufferListPair();
+            this.freeList.add( list );
+            this.allList.add( list );
         }
     }
 
@@ -75,7 +74,7 @@
     public synchronized ByteBuffer getBuffer( Object party ) 
         throws ResourceException
     {
-        BufferListPair l_list = null;
+        BufferListPair list = null;
         
         if ( freeList.size() == 0 )
         {
@@ -83,9 +82,9 @@
             {
                 for ( int ii = 0; ii < config.getIncrement(); ii++ )
                 {
-                    l_list = new BufferListPair();
-                    freeList.add( l_list );
-                    allList.add( l_list );
+                    list = new BufferListPair();
+                    freeList.add( list );
+                    allList.add( list );
                 }
             }
             else
@@ -96,14 +95,14 @@
         }
         
         // remove from free list and add to in use list then report to monitir
-        l_list = ( BufferListPair ) freeList.remove( 0 );
-        inUseList.add( l_list );
-        monitor.bufferTaken( this, l_list.getBuffer(), party );
+        list = ( BufferListPair ) freeList.remove( 0 );
+        inUseList.add( list );
+        monitor.bufferTaken( this, list.getBuffer(), party );
 
         // claim interest on the buffer automatically then report to monitor
-        l_list.add( party );
-        monitor.interestClaimed( this, l_list.getBuffer(), party );
-        return l_list.getBuffer();
+        list.add( party );
+        monitor.interestClaimed( this, list.getBuffer(), party );
+        return list.getBuffer();
     }
 
     
@@ -114,15 +113,15 @@
     public synchronized void claimInterest( ByteBuffer buffer, 
                                             Object party )
     {
-        BufferListPair l_list = getBufferListPair( buffer );
+        BufferListPair list = getBufferListPair( buffer );
         
-        if ( null == l_list )
+        if ( null == list )
         {
             monitor.nonPooledBuffer( this, buffer, party );
             throw new IllegalStateException( "Not a BufferPool resource" );
         }
         
-        l_list.add( party );
+        list.add( party );
         monitor.interestClaimed( this, buffer, party );
     }
 
@@ -133,29 +132,29 @@
      */
     public synchronized void releaseClaim( ByteBuffer buffer, Object party )
     {
-        BufferListPair l_list = getBufferListPair( buffer );
+        BufferListPair list = getBufferListPair( buffer );
         
-        if ( null == l_list )
+        if ( null == list )
         {
             monitor.releaseOfUnclaimed( this, buffer, party );
             throw new IllegalArgumentException( "Not a pooled resource" );
         }
         
-        if ( ! l_list.contains( party ) )
+        if ( ! list.contains( party ) )
         {
             monitor.unregisteredParty( this, buffer, party );
             throw new IllegalStateException( 
                     "Party nsedar registered interest with buffer" );
         }
         
-        l_list.remove( party );
+        list.remove( party );
         monitor.interestReleased( this, buffer, party );
         
         // if the list of interested parties hits zero then we release buf
-        if ( l_list.size() == 0 )
+        if ( list.size() == 0 )
         {
-            inUseList.remove( l_list );
-            freeList.add( l_list );
+            inUseList.remove( list );
+            freeList.add( list );
             monitor.bufferReleased( this, buffer, party );
         }
     }
@@ -213,9 +212,14 @@
      */
     public int getInterestedCount( ByteBuffer buffer )
     {
-        BufferListPair l_list = getBufferListPair( buffer );
-        Validate.notNull( l_list );
-        return l_list.size();
+        BufferListPair list = getBufferListPair( buffer );
+
+        if ( list == null )
+        {
+            throw new IllegalArgumentException( "not a buffer from this pool" );
+        }
+
+        return list.size();
     }
     
     
@@ -247,9 +251,9 @@
      */
     public String toString()
     {
-        StringBuffer l_buf = new StringBuffer( config.getName() );
-        l_buf.append( " buffer pool" );
-        return l_buf.toString();
+        StringBuffer buf = new StringBuffer( config.getName() );
+        buf.append( " buffer pool" );
+        return buf.toString();
     }
     
     
@@ -267,14 +271,14 @@
      */
     BufferListPair getBufferListPair( ByteBuffer buffer )
     {
-        BufferListPair l_list = null;
+        BufferListPair list = null;
         
         for ( int ii = 0; ii < allList.size(); ii++ )
         {
-            l_list = ( BufferListPair ) allList.get( ii );
-            if ( buffer == l_list.getBuffer() )
+            list = ( BufferListPair ) allList.get( ii );
+            if ( buffer == list.getBuffer() )
             {
-                return l_list;
+                return list;
             }
         }
         

Modified: incubator/directory/seda/trunk/impl/src/java/org/apache/seda/encoder/DefaultEncoderManager.java
==============================================================================
--- incubator/directory/seda/trunk/impl/src/java/org/apache/seda/encoder/DefaultEncoderManager.java	(original)
+++ incubator/directory/seda/trunk/impl/src/java/org/apache/seda/encoder/DefaultEncoderManager.java	Tue Sep 14 16:48:33 2004
@@ -26,10 +26,7 @@
 import org.apache.commons.codec.stateful.StatefulEncoder;
 import org.apache.commons.codec.stateful.EncoderCallback;
 
-import org.apache.seda.stage.StageHandler;
-import org.apache.seda.stage.DefaultStage;
-import org.apache.seda.stage.DefaultStageConfig;
-import org.apache.seda.stage.LoggingStageMonitor;
+import org.apache.seda.stage.*;
 
 import org.apache.seda.event.*;
 import org.apache.seda.listener.ClientKey;
@@ -71,13 +68,12 @@
      * @param router the event router used to publish and subscribe to events on
      */
     public DefaultEncoderManager( EventRouter router, 
-                                  DefaultStageConfig config,
+                                  StageConfig config,
                                   InetServicesDatabase inetdb )
     {
         super( config );
         super.setMonitor( new LoggingStageMonitor( this.getClass() ) );
         monitor = new EncoderManagerMonitorAdapter();
-        config.setHandler( new EncoderStageHandler() );
         this.inetdb = inetdb;
         this.router = router;
         this.router.subscribe( ProtocolEvent.class, this );
@@ -239,26 +235,14 @@
     }
 
 
-    class EncoderStageHandler implements StageHandler
+    EncoderManagerMonitor getMonitor()
     {
-        /* (non-Javadoc)
-         * @see org.apache.seda.seda.StageHandler#handleEvent(
-         * java.util.EventObject)
-         */
-        public void handleEvent( EventObject generic )
-        {
-            ResponseEvent event = ( ResponseEvent ) generic;
-            ClientKey key = event.getClientKey();
-            StatefulEncoder encoder = ( StatefulEncoder ) encoders.get( key );
+        return monitor;
+    }
 
-            try
-            {
-                encoder.encode( event.getResponse() );
-            }
-            catch ( EncoderException e )
-            {
-                monitor.failedOnEncode( DefaultEncoderManager.this, event, e );
-            }
-        }
+
+    StatefulEncoder getEncoder( ClientKey key )
+    {
+        return ( StatefulEncoder ) encoders.get( key ) ;
     }
 }

Added: incubator/directory/seda/trunk/impl/src/java/org/apache/seda/encoder/EncodeStageHandler.java
==============================================================================
--- (empty file)
+++ incubator/directory/seda/trunk/impl/src/java/org/apache/seda/encoder/EncodeStageHandler.java	Tue Sep 14 16:48:33 2004
@@ -0,0 +1,66 @@
+/*
+ *   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.encoder;
+
+
+import org.apache.seda.stage.StageHandler;
+import org.apache.seda.event.ResponseEvent;
+import org.apache.seda.listener.ClientKey;
+import org.apache.commons.codec.stateful.StatefulEncoder;
+import org.apache.commons.codec.EncoderException;
+
+import java.util.EventObject;
+
+
+/**
+ * A SEDA stage handler specifically designed for the encode stage.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class EncodeStageHandler implements StageHandler
+{
+    private final DefaultEncoderManager encMan;
+
+
+    public EncodeStageHandler( DefaultEncoderManager encMan )
+    {                                         
+        this.encMan = encMan;
+    }
+
+
+    /**
+     * Handles an event for the Stage.
+     *
+     * @param event the event to process or handle.
+     */
+    public void handleEvent( EventObject event )
+    {
+        ResponseEvent re = ( ResponseEvent ) event;
+        ClientKey key = re.getClientKey();
+        StatefulEncoder encoder = ( StatefulEncoder ) encMan.getEncoder( key );
+
+        try
+        {
+            encoder.encode( re.getResponse() );
+        }
+        catch ( EncoderException e )
+        {
+            encMan.getMonitor().failedOnEncode( encMan, event, e );
+        }
+    }
+}

Modified: incubator/directory/seda/trunk/impl/src/java/org/apache/seda/event/AbstractSubscriber.java
==============================================================================
--- incubator/directory/seda/trunk/impl/src/java/org/apache/seda/event/AbstractSubscriber.java	(original)
+++ incubator/directory/seda/trunk/impl/src/java/org/apache/seda/event/AbstractSubscriber.java	Tue Sep 14 16:48:33 2004
@@ -20,13 +20,11 @@
 import java.util.List;
 import java.util.HashMap;
 import java.util.EventObject;
+import java.util.ArrayList;
 
 import java.lang.reflect.Method;
 import java.lang.reflect.InvocationTargetException;
 
-import org.apache.commons.lang.Validate;
-import org.apache.commons.lang.ClassUtils;
-
 
 /**
  * An abstract Subscriber that calls the provided type-specific inform method
@@ -106,8 +104,15 @@
     public static void inform( Subscriber subscriber, EventObject event ) throws
         NoSuchMethodException, IllegalAccessException, InvocationTargetException
     {
-        Validate.notNull( subscriber, "subscriber arg cannot be null" );
-        Validate.notNull( event, "event arg cannot be null" );
+        if ( subscriber == null )
+        {
+            throw new IllegalArgumentException( "subscriber arg can't be null" );
+        }
+
+        if ( event == null )
+        {
+            throw new IllegalArgumentException( "event arg cannot be null" );
+        }
 
         Method method = getSpecificInformMethod( subscriber, event );
         Object params[] = { event };
@@ -152,8 +157,8 @@
          * we could not find the method in the cache so we need to find it
          * and add it to the cache if it exists at all  
          */
-        List list = ClassUtils.getAllSuperclasses( event.getClass() );
-        list.removeAll( ClassUtils.getAllSuperclasses( EventObject.class ) );
+        List list = getAllSuperclasses( event.getClass() );
+        list.removeAll( getAllSuperclasses( EventObject.class ) );
         list.add( 0, event.getClass() );
         
         // there may be two EventObject class references in the list
@@ -188,5 +193,30 @@
         throw new NoSuchMethodException( "Could not find a more specific "
                 + "inform method other than " + subscr.getClass().getName()
                 + ".inform(EventObject)" );
+    }
+
+
+    /**
+     * <p>Gets a <code>List</code> of superclasses for the given class.</p>
+     * Note this method is taken from commons lang ClassUtils sto reduce deps.
+     *
+     * @param cls the class to look up, may be <code>null</code>
+     * @return the <code>List</code> of superclasses in order going up from
+     * this one <code>null</code> if null input
+     */
+    public static List getAllSuperclasses(Class cls) {
+        if (cls == null)
+        {
+            return null;
+        }
+        
+        List classes = new ArrayList();
+        Class superclass = cls.getSuperclass();
+        while ( superclass != null )
+        {
+            classes.add( superclass );
+            superclass = superclass.getSuperclass();
+        }
+        return classes;
     }
 }

Modified: incubator/directory/seda/trunk/impl/src/java/org/apache/seda/output/LoggingOutputMonitor.java
==============================================================================
--- incubator/directory/seda/trunk/impl/src/java/org/apache/seda/output/LoggingOutputMonitor.java	(original)
+++ incubator/directory/seda/trunk/impl/src/java/org/apache/seda/output/LoggingOutputMonitor.java	Tue Sep 14 16:48:33 2004
@@ -21,14 +21,11 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.commons.lang.exception.ExceptionUtils;
 
 import org.apache.seda.event.ConnectEvent;
 import org.apache.seda.listener.ClientKey;
 import org.apache.seda.event.DisconnectEvent;
 import org.apache.seda.listener.KeyExpiryException;
-import org.apache.seda.output.OutputMonitor;
-import org.apache.seda.output.OutputManager;
 
 
 /**
@@ -53,8 +50,7 @@
         if ( log.isErrorEnabled() )
         {
             log.error( manager + " failed while trying to write to client " 
-                    + key + ":\n"
-                    + ExceptionUtils.getFullStackTrace( t ) );
+                    + key, t );
         }
     }
 
@@ -108,8 +104,7 @@
     {
         if ( log.isWarnEnabled() )
         {
-            log.warn( manager + " cannot use expired key for client " + key 
-                    + ":\n" + ExceptionUtils.getFullStackTrace( e ) );
+            log.warn( manager + " can't use expired key for client " + key, e );
         }
     }
 

Added: incubator/directory/seda/trunk/impl/src/java/org/apache/seda/protocol/DefaultInetServicesDatabase.java
==============================================================================
--- (empty file)
+++ incubator/directory/seda/trunk/impl/src/java/org/apache/seda/protocol/DefaultInetServicesDatabase.java	Tue Sep 14 16:48:33 2004
@@ -0,0 +1,138 @@
+/*
+ *   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.protocol;
+
+
+import java.util.*;
+
+
+/**
+ * The default implementation for an internet services database.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class DefaultInetServicesDatabase implements InetServicesDatabase
+{
+    /** maintains a list of entries mapped by the authoritative name */
+    private final Map entriesByName = new HashMap();
+    /** maintains a list of entries mapped by the service port */
+    private final Map entriesByPort = new HashMap();
+    /** maps a port number to the authoritative service protocol name */
+    private final Map protoByPort = new HashMap();
+
+    public DefaultInetServicesDatabase( InetServiceEntry[] entries )
+    {
+        for ( int ii = 0; ii < entries.length; ii++ )
+        {
+            // first add entry to entriesByName map
+            List list = ( List ) entriesByName.get( entries[ii].getName() );
+            if ( list == null )
+            {
+                list = new ArrayList( 2 );
+                entriesByName.put( entries[ii].getName(), list );
+            }
+            list.add( entries[ii] );
+
+            // now add entry to the entriesByPort map
+            Integer iport = new Integer( entries[ii].getPort() );
+            list = ( List ) entriesByPort.get( iport );
+            if ( list == null )
+            {
+                list = new ArrayList( 2 );
+                entriesByPort.put( iport, list );
+            }
+            list.add( entries[ii] );
+
+            // now map the port to the auth service name (protocol)
+            protoByPort.put( iport, entries[ii].getName() );
+        }
+    }
+
+
+    /**
+     * Gets an iteration over all the entries for a service by the name of the
+     * service.
+     *
+     * @param name the authoritative name of the service
+     * @return an Iterator over InetServiceEntry objects
+     */
+    public Iterator getByName( String name )
+    {
+        List list = ( List ) entriesByName.get( name );
+        if ( list == null )
+        {
+            list = Collections.EMPTY_LIST;
+        }
+
+        return list.iterator();
+    }
+
+    /**
+     * Gets an iteration over all the entries for a service by port number. This
+     * method returns an Iterator over the set of InetServiceEntry objects since
+     * more than one transport protocol can be used on the same port.
+     *
+     * @param port the port one which the service resides
+     * @return an Iterator over InetServiceEntry objects
+     */
+    public Iterator getByPort( int port )
+    {
+        List list = ( List ) entriesByPort.get( new Integer( port ) );
+        if ( list == null )
+        {
+            list = Collections.EMPTY_LIST;
+        }
+
+        return list.iterator();
+    }
+
+    /**
+     * Gets the protocol associated with a port.
+     *
+     * @param port the port one which the service resides
+     */
+    public String getProtoByPort( int port )
+    {
+        return ( String ) protoByPort.get( new Integer( port ) );
+    }
+
+    /**
+     * Gets the service entry by name using the authoritative service name and a
+     * transport protocol.
+     *
+     * @param name  the authoritative name of the service
+     * @param proto the transport protocol used for the service
+     * @return the internet service entry
+     */
+    public InetServiceEntry getByName( String name, String proto )
+    {
+        throw new UnsupportedOperationException( "not needed yet" );
+    }
+
+    /**
+     * Gets the service entry by port using the port and a transport protocol.
+     *
+     * @param port  the port on which the service resides
+     * @param proto the transport protocol used for the service
+     * @return the internet service entry
+     */
+    public InetServiceEntry getByPort( String port, String proto )
+    {
+        throw new UnsupportedOperationException( "not needed yet" );
+    }
+}

Modified: incubator/directory/seda/trunk/impl/src/java/org/apache/seda/protocol/DefaultRequestProcessor.java
==============================================================================
--- incubator/directory/seda/trunk/impl/src/java/org/apache/seda/protocol/DefaultRequestProcessor.java	(original)
+++ incubator/directory/seda/trunk/impl/src/java/org/apache/seda/protocol/DefaultRequestProcessor.java	Tue Sep 14 16:48:33 2004
@@ -20,8 +20,6 @@
 import java.util.Iterator;
 import java.util.EventObject;
 
-import org.apache.commons.lang.NotImplementedException;
-
 import org.apache.seda.event.EventRouter;
 import org.apache.seda.event.RequestEvent;
 import org.apache.seda.event.ResponseEvent;
@@ -136,7 +134,8 @@
             throw new NullPointerException(
                     "both key and request must not be null" );
         }
-        throw new NotImplementedException( "need mech to acquire handler" );
+
+        throw new UnsupportedOperationException( "need mech to acquire handler" );
     }
 
 
@@ -166,7 +165,7 @@
                      // perhaps we need to add an isResponseOrdered or a
                      // response sequence number for multi-part responses
 
-                     throw new NotImplementedException(
+                     throw new UnsupportedOperationException(
                              "need response serialization" );
                  }
              }

Modified: incubator/directory/seda/trunk/impl/src/java/org/apache/seda/stage/LoggingStageMonitor.java
==============================================================================
--- incubator/directory/seda/trunk/impl/src/java/org/apache/seda/stage/LoggingStageMonitor.java	(original)
+++ incubator/directory/seda/trunk/impl/src/java/org/apache/seda/stage/LoggingStageMonitor.java	Tue Sep 14 16:48:33 2004
@@ -19,9 +19,6 @@
 
 import java.util.EventObject;
 
-import org.apache.commons.lang.Validate;
-import org.apache.commons.lang.ClassUtils;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -57,9 +54,7 @@
      */
     public LoggingStageMonitor( Class clazz )
     {
-        Validate.isTrue( ClassUtils.isAssignable( clazz, Stage.class ),
-                clazz.getName() + " does not implement the Stage interface" );
-        log = LogFactory.getLog( DefaultStage.class );
+        log = LogFactory.getLog( clazz );
     }
     
     
@@ -305,6 +300,42 @@
      */
     private String getDesc( EventObject event )
     {
-        return ClassUtils.getShortClassName( event.getClass() );
+        return getShortClassName( event.getClass().getName() );
+    }
+
+
+    /**
+     * <p>Gets the class name minus the package name from a String.</p>
+     * Got this straight out of ClassUtils in commons-lang to remove deps.
+     *
+     * @param className  the className to get the short name for
+     * @return the class name of the class without the package name or an
+     * empty string
+     */
+    public static String getShortClassName(String className) {
+        if ( className == null )
+        {
+            return "";
+        }
+
+        if ( className.length() == 0 )
+        {
+            return "";
+        }
+
+        char[] chars = className.toCharArray();
+        int lastDot = 0;
+        for ( int i = 0; i < chars.length; i++ )
+        {
+            if ( chars[i] == '.' )
+            {
+                lastDot = i + 1;
+            }
+            else if ( chars[i] == '$' )
+            {
+                chars[i] = '.';
+            }
+        }
+        return new String( chars, lastDot, chars.length - lastDot );
     }
 }

Modified: incubator/directory/seda/trunk/impl/src/test/org/apache/seda/buffer/DefaultBufferPoolTest.java
==============================================================================
--- incubator/directory/seda/trunk/impl/src/test/org/apache/seda/buffer/DefaultBufferPoolTest.java	(original)
+++ incubator/directory/seda/trunk/impl/src/test/org/apache/seda/buffer/DefaultBufferPoolTest.java	Tue Sep 14 16:48:33 2004
@@ -27,8 +27,7 @@
 /**
  * Tests the default buffer pool implementation.
  *
- * @author <a href="mailto:directory-dev@incubator.apache.org">
- * Apache Directory Project</a>
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
 public class DefaultBufferPoolTest extends TestCase

Modified: incubator/directory/seda/trunk/impl/src/test/org/apache/seda/decoder/DefaultDecoderManagerTest.java
==============================================================================
--- incubator/directory/seda/trunk/impl/src/test/org/apache/seda/decoder/DefaultDecoderManagerTest.java	(original)
+++ incubator/directory/seda/trunk/impl/src/test/org/apache/seda/decoder/DefaultDecoderManagerTest.java	Tue Sep 14 16:48:33 2004
@@ -94,7 +94,7 @@
                 return null;
             }
 
-            public Iterator getByPort( String port )
+            public Iterator getByPort( int port )
             {
                 return null;
             }