directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: rev 56602 - in incubator/directory/seda/trunk/src/java/org/apache/seda: decoder encoder event protocol
Date Thu, 04 Nov 2004 16:00:24 GMT
Author: trustin
Date: Thu Nov  4 08:00:23 2004
New Revision: 56602

Removed:
   incubator/directory/seda/trunk/src/java/org/apache/seda/event/AddProtocolEvent.java
   incubator/directory/seda/trunk/src/java/org/apache/seda/event/ProtocolEvent.java
   incubator/directory/seda/trunk/src/java/org/apache/seda/event/ProtocolSubscriber.java
Modified:
   incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/DefaultDecoderManager.java
   incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/DefaultEncoderManager.java
   incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/DefaultRequestProcessor.java
Log:
Changed EncoderManager, DecoderManager, and RequestProcessor to use the InetServiceEntry.getProtocolProvider()
to get an appropriate provider and its EncoderFactory, DecoderFactory, and ProtocolHandler.

Modified: incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/DefaultDecoderManager.java
==============================================================================
--- incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/DefaultDecoderManager.java
(original)
+++ incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/DefaultDecoderManager.java
Thu Nov  4 08:00:23 2004
@@ -20,14 +20,13 @@
 import java.nio.ByteBuffer;
 import java.util.EventObject;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.Map;
 
 import org.apache.commons.codec.DecoderException;
 import org.apache.commons.codec.stateful.DecoderCallback;
-import org.apache.commons.codec.stateful.DecoderFactory;
 import org.apache.commons.codec.stateful.StatefulDecoder;
 import org.apache.seda.event.AbstractSubscriber;
-import org.apache.seda.event.AddProtocolEvent;
 import org.apache.seda.event.ConnectEvent;
 import org.apache.seda.event.ConnectSubscriber;
 import org.apache.seda.event.DisconnectEvent;
@@ -35,13 +34,15 @@
 import org.apache.seda.event.EventRouter;
 import org.apache.seda.event.InputEvent;
 import org.apache.seda.event.InputSubscriber;
-import org.apache.seda.event.ProtocolEvent;
-import org.apache.seda.event.ProtocolSubscriber;
 import org.apache.seda.event.RequestEvent;
 import org.apache.seda.event.filter.EventTypeFilter;
 import org.apache.seda.listener.ClientKey;
 import org.apache.seda.listener.KeyExpiryException;
+import org.apache.seda.listener.UDPClientKey;
+import org.apache.seda.protocol.InetServiceEntry;
 import org.apache.seda.protocol.InetServicesDatabase;
+import org.apache.seda.protocol.ProtocolProvider;
+import org.apache.seda.protocol.TransportTypeEnum;
 import org.apache.seda.stage.DefaultStage;
 import org.apache.seda.stage.LoggingStageMonitor;
 import org.apache.seda.stage.StageConfig;
@@ -55,7 +56,7 @@
  */
 public class DefaultDecoderManager extends DefaultStage
     implements DecoderManager, InputSubscriber, ConnectSubscriber,
-               ProtocolSubscriber, DisconnectSubscriber
+               DisconnectSubscriber
 {
     /** event router or bus this component subscribes and publishes events on */
     private final EventRouter router;
@@ -91,7 +92,6 @@
 
         router.subscribe(new EventTypeFilter(InputEvent.class), this);
         router.subscribe(new EventTypeFilter(ConnectEvent.class), this);
-        router.subscribe(new EventTypeFilter(ProtocolEvent.class), this);
         router.subscribe(new EventTypeFilter(DisconnectEvent.class), this);
     }
 
@@ -119,24 +119,6 @@
     }
 
     /**
-     * For now this method just adds the DecoderFactory associated with the
-     * protocol to a map for use when setting up new clients.  Later as other
-     * events besides AddProtocolEvent are supported we'll add more
-     * functionality.
-     *
-     * @param event the protocol event to be informed of
-     */
-    public void inform(ProtocolEvent event)
-    {
-        if (event instanceof AddProtocolEvent)
-        {
-            factories.put(
-                          event.getProtocolProvider().getName(),
-                          event.getProtocolProvider().getDecoderFactory());
-        }
-    }
-
-    /**
      * Enqueues the event onto this Stages event queue for processing.
      *
      * @see org.apache.seda.event.InputSubscriber#inform(
@@ -170,13 +152,27 @@
     private StatefulDecoder createDecoder(ClientKey key)
                                    throws KeyExpiryException
     {
-        String proto = inetdb.getProtoByPort(key.getLocalAddress().getPort());
+        TransportTypeEnum transportType;
+        if (key instanceof UDPClientKey) {
+        	transportType = TransportTypeEnum.UDP;
+        } else {
+        	transportType = TransportTypeEnum.TCP;
+        }
         
-        // FIXME Better synchronization implementation or non asynchronous event firing
-        DecoderFactory factory;
-        while ((factory = (DecoderFactory) factories.get(proto)) == null)
-        	continue;
-        return factory.createDecoder();
+        Iterator it = inetdb.getByPort(key.getLocalAddress().getPort());
+        ProtocolProvider provider = null;
+        while (it.hasNext()) {
+        	InetServiceEntry entry = (InetServiceEntry) it.next();
+        	if (entry.getTransport() == transportType) {
+        		provider = entry.getProtocolProvider();
+        	}
+        }
+
+        // TODO replace RuntimeException with ProtocolProviderNotFoundException
+        if (provider == null)
+        	throw new RuntimeException("No protocol provider available");
+
+        return provider.getDecoderFactory().createDecoder();
     }
 
     /**

Modified: incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/DefaultEncoderManager.java
==============================================================================
--- incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/DefaultEncoderManager.java
(original)
+++ incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/DefaultEncoderManager.java
Thu Nov  4 08:00:23 2004
@@ -20,27 +20,29 @@
 import java.nio.ByteBuffer;
 import java.util.EventObject;
 import java.util.HashMap;
+import java.util.Iterator;
 
 import org.apache.commons.codec.EncoderException;
 import org.apache.commons.codec.stateful.EncoderCallback;
 import org.apache.commons.codec.stateful.EncoderFactory;
 import org.apache.commons.codec.stateful.StatefulEncoder;
 import org.apache.seda.event.AbstractSubscriber;
-import org.apache.seda.event.AddProtocolEvent;
 import org.apache.seda.event.ConnectEvent;
 import org.apache.seda.event.ConnectSubscriber;
 import org.apache.seda.event.DisconnectEvent;
 import org.apache.seda.event.DisconnectSubscriber;
 import org.apache.seda.event.EventRouter;
 import org.apache.seda.event.OutputEvent;
-import org.apache.seda.event.ProtocolEvent;
-import org.apache.seda.event.ProtocolSubscriber;
 import org.apache.seda.event.ResponseEvent;
 import org.apache.seda.event.ResponseSubscriber;
 import org.apache.seda.event.filter.EventTypeFilter;
 import org.apache.seda.listener.ClientKey;
 import org.apache.seda.listener.KeyExpiryException;
+import org.apache.seda.listener.UDPClientKey;
+import org.apache.seda.protocol.InetServiceEntry;
 import org.apache.seda.protocol.InetServicesDatabase;
+import org.apache.seda.protocol.ProtocolProvider;
+import org.apache.seda.protocol.TransportTypeEnum;
 import org.apache.seda.stage.DefaultStage;
 import org.apache.seda.stage.LoggingStageMonitor;
 import org.apache.seda.stage.StageConfig;
@@ -56,7 +58,7 @@
  */
 public class DefaultEncoderManager extends DefaultStage
     implements EncoderManager, ConnectSubscriber, ResponseSubscriber,
-               ProtocolSubscriber, DisconnectSubscriber
+               DisconnectSubscriber
 {
     /** the event router used to publish and subscribe to events on */
     private final EventRouter router;
@@ -87,7 +89,6 @@
         this.inetdb = inetdb;
         this.router = router;
         this.router.subscribe(new EventTypeFilter(ConnectEvent.class), this);
-        this.router.subscribe(new EventTypeFilter(ProtocolEvent.class), this);
         this.router.subscribe(new EventTypeFilter(ResponseEvent.class), this);
     }
 
@@ -126,15 +127,6 @@
         super.enqueue(event);
     }
 
-    public void inform(ProtocolEvent event)
-    {
-        if (event instanceof AddProtocolEvent)
-        {
-            factories.put(event.getProtocolProvider().getName(),
-                          event.getProtocolProvider().getEncoderFactory());
-        }
-    }
-
     /**
      * Temporary place holder for functionality that looks up a protocol
      * specific StatefulEncoder.
@@ -145,14 +137,27 @@
     private StatefulEncoder createEncoder(ClientKey key)
                                    throws KeyExpiryException
     {
-        String proto = inetdb.getProtoByPort(key.getLocalAddress().getPort());
-        EncoderFactory factory;
-
-        // FIXME Event synchronization
-        while ((factory = (EncoderFactory) factories.get(proto)) == null)
-            continue;
+        TransportTypeEnum transportType;
+        if (key instanceof UDPClientKey) {
+        	transportType = TransportTypeEnum.UDP;
+        } else {
+        	transportType = TransportTypeEnum.TCP;
+        }
+        
+        Iterator it = inetdb.getByPort(key.getLocalAddress().getPort());
+        ProtocolProvider provider = null;
+        while (it.hasNext()) {
+        	InetServiceEntry entry = (InetServiceEntry) it.next();
+        	if (entry.getTransport() == transportType) {
+        		provider = entry.getProtocolProvider();
+        	}
+        }
+
+        // TODO replace RuntimeException with ProtocolProviderNotFoundException
+        if (provider == null)
+        	throw new RuntimeException("No protocol provider available");
 
-        return factory.createEncoder();
+        return provider.getEncoderFactory().createEncoder();
     }
 
     /**
@@ -197,16 +202,7 @@
     public ByteBuffer encodeBlocking(ClientKey key, Object response)
                               throws EncoderException
     {
-        int port = -1;
-
-        try
-        {
-            port = key.getLocalAddress().getPort();
-        }
-        catch (KeyExpiryException e)
-        {
-            monitor.failedOnEncode(this, key, response, e);
-        }
+        int port = key.getLocalAddress().getPort();
 
         EncoderFactory factory =
             (EncoderFactory) factories.get(inetdb.getProtoByPort(port));

Modified: incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/DefaultRequestProcessor.java
==============================================================================
--- incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/DefaultRequestProcessor.java
(original)
+++ incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/DefaultRequestProcessor.java
Thu Nov  4 08:00:23 2004
@@ -18,20 +18,17 @@
 package org.apache.seda.protocol;
 
 import java.util.EventObject;
-import java.util.HashMap;
 import java.util.Iterator;
-import java.util.Map;
 
 import org.apache.seda.event.AbstractSubscriber;
 import org.apache.seda.event.EventRouter;
-import org.apache.seda.event.ProtocolEvent;
-import org.apache.seda.event.ProtocolSubscriber;
 import org.apache.seda.event.RequestEvent;
 import org.apache.seda.event.RequestSubscriber;
 import org.apache.seda.event.ResponseEvent;
 import org.apache.seda.event.filter.EventTypeFilter;
 import org.apache.seda.listener.ClientKey;
 import org.apache.seda.listener.KeyExpiryException;
+import org.apache.seda.listener.UDPClientKey;
 import org.apache.seda.stage.DefaultStage;
 import org.apache.seda.stage.DefaultStageConfig;
 import org.apache.seda.stage.LoggingStageMonitor;
@@ -46,9 +43,8 @@
  * @version $Rev$
  */
 public class DefaultRequestProcessor extends DefaultStage
-    implements RequestProcessor, RequestSubscriber, ProtocolSubscriber
-{
-    private final Map protocols;
+    implements RequestProcessor, RequestSubscriber {
+	
     private final EventRouter router;
     private final InetServicesDatabase inetDb;
     private RequestProcessorMonitor monitor = null;
@@ -71,8 +67,6 @@
         this.inetDb = inetDb;
         this.router = router;
         this.router.subscribe(new EventTypeFilter(RequestEvent.class), this);
-        this.router.subscribe(new EventTypeFilter(ProtocolEvent.class), this);
-        this.protocols = new HashMap(3);
         this.monitor = new RequestProcessorMonitorAdapter();
     }
 
@@ -100,33 +94,29 @@
         }
     }
 
-    /**
-     * Informs this subscriber of a protocol event.
-     *
-     * @param event the protocol event to inform of
-     */
-    public void inform(ProtocolEvent event)
-    {
-        ProtocolProvider proto = event.getProtocolProvider();
-        protocols.put(proto.getName(), proto);
-    }
-
     private RequestHandler getProtocolHandler(ClientKey key, Object request)
     {
-        String name = null;
-
-        try
-        {
-            name = inetDb.getProtoByPort(key.getLocalAddress().getPort());
-        }
-        catch (KeyExpiryException e)
-        {
-            monitor.keyExpired(key, request, e);
-            throw new IllegalStateException("key expired can't service req");
-        }
+        TransportTypeEnum transportType;
+        if (key instanceof UDPClientKey) {
+        	transportType = TransportTypeEnum.UDP;
+        } else {
+        	transportType = TransportTypeEnum.TCP;
+        }
+        
+        Iterator it = inetDb.getByPort(key.getLocalAddress().getPort());
+        ProtocolProvider provider = null;
+        while (it.hasNext()) {
+        	InetServiceEntry entry = (InetServiceEntry) it.next();
+        	if (entry.getTransport() == transportType) {
+        		provider = entry.getProtocolProvider();
+        	}
+        }
+
+        // TODO replace RuntimeException with ProtocolProviderNotFoundException
+        if (provider == null)
+        	throw new RuntimeException("No protocol provider available");
 
-        ProtocolProvider proto = (ProtocolProvider) protocols.get(name);
-        return proto.getHandler(key, request);
+        return provider.getHandler(key, request);
     }
 
     /**
@@ -204,6 +194,7 @@
          * Event handler method for processing RequestEvents.
          *
          * @param nonspecific the RequestEvent to process.
+         * @throws KeyExpiryException
          */
         public void handleEvent(EventObject nonspecific)
         {

Mime
View raw message