directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: rev 56235 - in incubator/directory/seda/trunk/src: java/org/apache/seda/decoder java/org/apache/seda/encoder java/org/apache/seda/event java/org/apache/seda/event/filter java/org/apache/seda/input java/org/apache/seda/listener java/org/apache/seda/output java/org/apache/seda/protocol test/org/apache/seda/decoder test/org/apache/seda/examples
Date Mon, 01 Nov 2004 14:45:14 GMT
Author: trustin
Date: Mon Nov  1 06:45:13 2004
New Revision: 56235

Added:
   incubator/directory/seda/trunk/src/java/org/apache/seda/event/filter/ClientKeyTypeFilter.java
  (contents, props changed)
   incubator/directory/seda/trunk/src/java/org/apache/seda/event/filter/CompositeEventFilter.java
  (contents, props changed)
   incubator/directory/seda/trunk/src/java/org/apache/seda/event/filter/EventTypeFilter.java
  (contents, props changed)
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/event/DefaultEventRouter.java
   incubator/directory/seda/trunk/src/java/org/apache/seda/event/EventRouter.java
   incubator/directory/seda/trunk/src/java/org/apache/seda/event/Subscription.java
   incubator/directory/seda/trunk/src/java/org/apache/seda/input/TCPInputManager.java
   incubator/directory/seda/trunk/src/java/org/apache/seda/listener/TCPListenerManager.java
   incubator/directory/seda/trunk/src/java/org/apache/seda/listener/UDPListenerManager.java
   incubator/directory/seda/trunk/src/java/org/apache/seda/output/TCPOutputManager.java
   incubator/directory/seda/trunk/src/java/org/apache/seda/output/UDPOutputManager.java
   incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/DefaultRequestProcessor.java
   incubator/directory/seda/trunk/src/test/org/apache/seda/decoder/DefaultDecoderManagerTest.java
   incubator/directory/seda/trunk/src/test/org/apache/seda/examples/EchoProtocolProviderTest.java
Log:
* Fixed: UDPListenerManager listens to DisconnectEvent which is not fired by UDP-related managers.
* Added: EventTypeFilter which replaces Subscription.type property
  => This changes the method signature of EventRouter.subscribe/unsubscribe; event type
params are gone.
* Added: ClientKeyTypeFilter which prevents TCP-related managers from receiving UDP-related
events and vice versa.
* Added: CompositeEventFilter to combine EventTypeFilter and ClientKeyTypeFilter

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
Mon Nov  1 06:45:13 2004
@@ -38,6 +38,7 @@
 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.protocol.InetServicesDatabase;
@@ -88,10 +89,10 @@
         this.monitor = new DecoderManagerMonitorAdapter();
         super.setStageMonitor(new LoggingStageMonitor(getClass()));
 
-        router.subscribe(InputEvent.class, this);
-        router.subscribe(ConnectEvent.class, this);
-        router.subscribe(ProtocolEvent.class, this);
-        router.subscribe(DisconnectEvent.class, this);
+        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);
     }
 
     // ------------------------------------------------------------------------

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
Mon Nov  1 06:45:13 2004
@@ -18,7 +18,6 @@
 package org.apache.seda.encoder;
 
 import java.nio.ByteBuffer;
-
 import java.util.EventObject;
 import java.util.HashMap;
 
@@ -26,11 +25,25 @@
 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.*;
+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.protocol.InetServicesDatabase;
-import org.apache.seda.stage.*;
+import org.apache.seda.stage.DefaultStage;
+import org.apache.seda.stage.LoggingStageMonitor;
+import org.apache.seda.stage.StageConfig;
 
 
 /**
@@ -73,9 +86,9 @@
         monitor = new EncoderManagerMonitorAdapter();
         this.inetdb = inetdb;
         this.router = router;
-        this.router.subscribe(ConnectEvent.class, this);
-        this.router.subscribe(ProtocolEvent.class, this);
-        this.router.subscribe(ResponseEvent.class, this);
+        this.router.subscribe(new EventTypeFilter(ConnectEvent.class), this);
+        this.router.subscribe(new EventTypeFilter(ProtocolEvent.class), this);
+        this.router.subscribe(new EventTypeFilter(ResponseEvent.class), this);
     }
 
     /* (non-Javadoc)

Modified: incubator/directory/seda/trunk/src/java/org/apache/seda/event/DefaultEventRouter.java
==============================================================================
--- incubator/directory/seda/trunk/src/java/org/apache/seda/event/DefaultEventRouter.java
(original)
+++ incubator/directory/seda/trunk/src/java/org/apache/seda/event/DefaultEventRouter.java
Mon Nov  1 06:45:13 2004
@@ -40,39 +40,17 @@
     /** the monitor - initially set to the null monitor */
     private EventRouterMonitor monitor = new EventRouterMonitorAdapter();
 
-    /* (non-Javadoc)
-     * @see org.apache.seda.event.EventRouter#subscribe(java.lang.Class,
-     * org.apache.seda.event.Subscriber)
-     */
-    public void subscribe(Class type, Subscriber subscriber)
+    public void subscribe(EventFilter filter, Subscriber subscriber)
     {
-        subscribe(type, null, subscriber);
-    }
-
-    /*
-     * @see org.apache.seda.event.EventRouter#subscribe(java.lang.Class,
-     * org.apache.seda.event.Filter, org.apache.eve.event.Subscriber)
-     */
-    public void subscribe(Class type, EventFilter filter, Subscriber subscriber)
-    {
-        if (!EventObject.class.isAssignableFrom(type))
-        {
-            throw new IllegalArgumentException("Invalid event class: "
-                                               + type.getName());
-        }
-
         Subscription l_subscription =
-            new Subscription(type, filter, subscriber);
+            new Subscription(filter, subscriber);
 
-        if (!subscriptions.contains(l_subscription))
+        synchronized (subscriptions)
         {
-            synchronized (subscriptions)
-            {
-                subscriptions.add(l_subscription);
-            }
-
-            monitor.addedSubscription(l_subscription);
+            subscriptions.add(l_subscription);
         }
+
+        monitor.addedSubscription(l_subscription);
     }
 
     /**
@@ -98,12 +76,7 @@
         }
     }
 
-    /**
-     * (non-Javadoc)
-     * @see org.apache.seda.event.EventRouter#unsubscribe(java.lang.Class,
-     * org.apache.seda.event.Subscriber)
-     */
-    public void unsubscribe(Class type, Subscriber subscriber)
+    public void unsubscribe(EventFilter filter, Subscriber subscriber)
     {
         Iterator l_list = subscriptions.iterator();
 
@@ -115,7 +88,7 @@
 
                 if (
                     (subscriber == l_subscription.getSubscriber())
-                        && type.equals(l_subscription.getType()))
+                        && filter == l_subscription.getFilter())
                 {
                     l_list.remove();
                     monitor.removedSubscription(l_subscription);
@@ -126,28 +99,6 @@
 
     /**
      * (non-Javadoc)
-     * @see org.apache.seda.event.EventRouter#unsubscribe(java.lang.Class,
-     * org.apache.seda.event.Subscriber)
-     */
-    public void unsubscribe(Class type, EventFilter filter, Subscriber subscriber)
-    {
-        if (!EventObject.class.isAssignableFrom(type))
-        {
-            throw new IllegalArgumentException("Invalid event class: "
-                                               + type.getName());
-        }
-
-        final Subscription l_subscription =
-            new Subscription(type, filter, subscriber);
-
-        synchronized (subscriptions)
-        {
-            subscriptions.remove(l_subscription);
-        }
-    }
-
-    /**
-     * (non-Javadoc)
      * @see org.apache.seda.event.EventRouter#publish(java.util.EventObject)
      */
     public void publish(EventObject event)
@@ -216,14 +167,6 @@
     {
         for (int ii = 0; ii < subscriptions.length; ii++)
         {
-            boolean isAssignable =
-                subscriptions[ii].getType().isAssignableFrom(ev.getClass());
-
-            if (!isAssignable)
-            {
-                continue;
-            }
-
             if (subscriptions[ii].getFilter() == null)
             {
                 subscriptions[ii].getSubscriber().inform(ev);

Modified: incubator/directory/seda/trunk/src/java/org/apache/seda/event/EventRouter.java
==============================================================================
--- incubator/directory/seda/trunk/src/java/org/apache/seda/event/EventRouter.java	(original)
+++ incubator/directory/seda/trunk/src/java/org/apache/seda/event/EventRouter.java	Mon Nov
 1 06:45:13 2004
@@ -32,19 +32,10 @@
     /**
      * Subscribes an event subscriber.
      *
-     * @param type an event type enumeration value
      * @param filter an event filter if any to apply
      * @param subscriber the Subscriber to subscribe
      */
-    void subscribe(Class type, EventFilter filter, Subscriber subscriber);
-
-    /**
-     * Subscribes an event subscriber.
-     *
-     * @param type an event type
-     * @param subscriber the Subscriber to subscribe
-     */
-    void subscribe(Class type, Subscriber subscriber);
+    void subscribe(EventFilter filter, Subscriber subscriber);
 
     /**
      * Unsubscribes an event subscriber.
@@ -56,10 +47,10 @@
     /**
      * Unsubscribes an event subscriber.
      *
-     * @param type an event type
+     * @param filter an event filter
      * @param subscriber the Subscriber to unsubscribe
      */
-    void unsubscribe(Class type, Subscriber subscriber);
+    void unsubscribe(EventFilter filter, Subscriber subscriber);
 
     /**
      * Fires an event synchronously in the thread of the caller to all

Modified: incubator/directory/seda/trunk/src/java/org/apache/seda/event/Subscription.java
==============================================================================
--- incubator/directory/seda/trunk/src/java/org/apache/seda/event/Subscription.java	(original)
+++ incubator/directory/seda/trunk/src/java/org/apache/seda/event/Subscription.java	Mon Nov
 1 06:45:13 2004
@@ -29,38 +29,23 @@
     /** the filter if any used to filter out events */
     private final EventFilter filter;
 
-    /** the event class */
-    private final Class type;
-
     /** the subscriber */
     private final Subscriber subscriber;
 
     /**
-     * Creates a subscription for a type of event using a filter and a
+     * Creates a subscription for a set of events using a filter and a
      * subscriber.
      *
-     * @param type the class of event to be informed on
      * @param filter the Filter to use weed out unwanted events
      * @param subscriber the subscriber to deliever the event to
      */
-    public Subscription(Class type, EventFilter filter, Subscriber subscriber)
+    public Subscription(EventFilter filter, Subscriber subscriber)
     {
-        this.type = type;
         this.filter = filter;
         this.subscriber = subscriber;
     }
 
     /**
-     * Get the event class/type
-     *
-     * @return the event class/type
-     */
-    public Class getType()
-    {
-        return type;
-    }
-
-    /**
      * Get the filter used with this subscription.
      *
      * @return  The filter
@@ -78,71 +63,5 @@
     public Subscriber getSubscriber()
     {
         return subscriber;
-    }
-
-    /**
-     * Compare two Subscriptions to each other.
-     *
-     * @param obj the object to compare this Subscription to
-     * @return <code>true</code> if the two Subscription objects are the same
-     */
-    public boolean equals(Object obj)
-    {
-        if (this == obj)
-        {
-            return true;
-        }
-
-        if (!(obj instanceof Subscription))
-        {
-            return false;
-        }
-
-        final Subscription l_subscription = (Subscription) obj;
-
-        if (!type.equals(l_subscription.getType()))
-        {
-            return false;
-        }
-
-        if (filter != null)
-        {
-            if (l_subscription.getFilter() == null)
-            {
-                return false;
-            }
-
-            if (!filter.equals(l_subscription.getFilter()))
-            {
-                return false;
-            }
-        }
-
-        if (!subscriber.equals(l_subscription.getSubscriber()))
-        {
-            return false;
-        }
-
-        return true;
-    }
-
-    /**
-     * Get the hashcode (used in HashMaps).
-     *
-     * hashCode = 37 * (37 * (629 + event.hashCode()) + filter.hashCode())
-     *            + subscriber.hashCode()
-     *
-     * This method was borrowed from Berin Loritsch.
-     *
-     * @return the hashCode value
-     */
-    public int hashCode()
-    {
-        int l_result = 17;
-        l_result = (37 * l_result) + type.hashCode();
-        l_result =
-            (37 * l_result) + ((filter != null) ? filter.hashCode() : 0);
-        l_result = (37 * l_result) + subscriber.hashCode();
-        return l_result;
     }
 }

Added: incubator/directory/seda/trunk/src/java/org/apache/seda/event/filter/ClientKeyTypeFilter.java
==============================================================================
--- (empty file)
+++ incubator/directory/seda/trunk/src/java/org/apache/seda/event/filter/ClientKeyTypeFilter.java
Mon Nov  1 06:45:13 2004
@@ -0,0 +1,54 @@
+/*
+ *   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.event.filter;
+
+import java.util.EventObject;
+
+import org.apache.seda.event.ClientEvent;
+import org.apache.seda.event.EventFilter;
+import org.apache.seda.listener.ClientKey;
+
+/**
+ * An {@link EventFilter} which accepts only the {@link ClientEvent}s
+ * whose {@link ClientKey}'s type matches. 
+ * 
+ * @author Trustin Lee (trustin@gmail.com)
+ * @version $Rev$, $Date$
+ */
+public class ClientKeyTypeFilter implements EventFilter {
+	
+	private final Class keyType;
+	
+	public ClientKeyTypeFilter(Class keyType) {
+		if (!ClientKey.class.isAssignableFrom(keyType))
+        {
+            throw new IllegalArgumentException("Invalid event class: "
+                                               + keyType.getName());
+        }
+		this.keyType = keyType;
+	}
+
+	public boolean accept(EventObject event) {
+		if (event instanceof ClientEvent) {
+			ClientEvent ce = (ClientEvent) event;
+			return (keyType.isAssignableFrom(ce.getClientKey().getClass()));
+			
+		} else {
+			return false;
+		}
+	}
+}

Added: incubator/directory/seda/trunk/src/java/org/apache/seda/event/filter/CompositeEventFilter.java
==============================================================================
--- (empty file)
+++ incubator/directory/seda/trunk/src/java/org/apache/seda/event/filter/CompositeEventFilter.java
Mon Nov  1 06:45:13 2004
@@ -0,0 +1,74 @@
+/*
+ *   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.event.filter;
+
+import java.util.EventObject;
+
+import org.apache.seda.event.EventFilter;
+
+/**
+ * An {@link EventFilter} which performs AND/OR operations on two or more {@link EventFilter}s.
+ * 
+ * @author Trustin Lee (trustin@gmail.com)
+ * @version $Rev$, $Date$
+ */
+public class CompositeEventFilter implements EventFilter {
+	
+	public static final int AND = 0;
+	public static final int OR = 1;
+	
+	private final EventFilter[] filters;
+	private final int operator;
+	
+	public CompositeEventFilter(EventFilter[] filters, int operator) {
+		switch (operator) {
+		case AND:
+		case OR:
+			this.operator = operator;
+			break;
+		default:
+			throw new IllegalArgumentException("unknown operator");
+		}
+		
+		this.filters = new EventFilter[filters.length];
+		System.arraycopy(filters, 0, this.filters, 0, filters.length);
+		
+	}
+
+	public boolean accept(EventObject event) {
+		EventFilter[] filters = this.filters;
+		switch (operator) {
+		case AND:
+			for (int i = filters.length - 1; i >= 0; i--) {
+				if (!filters[i].accept(event))
+					return false;
+			}
+			
+			return true;
+		case OR:
+			for (int i = filters.length - 1; i >= 0; i--) {
+				if (filters[i].accept(event))
+					return true;
+			}
+			
+			return false;
+		default:
+			throw new InternalError(); // this cannot happen
+		}
+	}
+
+}

Added: incubator/directory/seda/trunk/src/java/org/apache/seda/event/filter/EventTypeFilter.java
==============================================================================
--- (empty file)
+++ incubator/directory/seda/trunk/src/java/org/apache/seda/event/filter/EventTypeFilter.java
Mon Nov  1 06:45:13 2004
@@ -0,0 +1,51 @@
+/*
+ *   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.event.filter;
+
+import java.util.EventObject;
+
+import org.apache.seda.event.EventFilter;
+
+/**
+ * An {@link EventFilter} which accepts the only events of the specific class.
+ * 
+ * @author Trustin Lee (trustin@gmail.com)
+ * @version $Rev$, $Date$
+ */
+public class EventTypeFilter implements EventFilter {
+	
+	private final Class eventType;
+	
+	public EventTypeFilter(Class eventType) {
+		if (eventType == null)
+			throw new NullPointerException();
+
+		if (!EventObject.class.isAssignableFrom(eventType))
+        {
+            throw new IllegalArgumentException("Invalid event class: "
+                                               + eventType.getName());
+        }
+		this.eventType = eventType;
+	}
+
+	/**
+	 * Returns <code>true</code> if the specified event is of the type which is
specified in the constructor of this filter.
+	 */
+	public boolean accept(EventObject event) {
+		return (eventType.isAssignableFrom(event.getClass()));
+	}
+}

Modified: incubator/directory/seda/trunk/src/java/org/apache/seda/input/TCPInputManager.java
==============================================================================
--- incubator/directory/seda/trunk/src/java/org/apache/seda/input/TCPInputManager.java	(original)
+++ incubator/directory/seda/trunk/src/java/org/apache/seda/input/TCPInputManager.java	Mon
Nov  1 06:45:13 2004
@@ -18,12 +18,10 @@
 package org.apache.seda.input;
 
 import java.io.IOException;
-
 import java.nio.ByteBuffer;
 import java.nio.channels.SelectionKey;
 import java.nio.channels.Selector;
 import java.nio.channels.SocketChannel;
-
 import java.util.ArrayList;
 import java.util.Iterator;
 
@@ -34,8 +32,12 @@
 import org.apache.seda.event.ConnectSubscriber;
 import org.apache.seda.event.DisconnectEvent;
 import org.apache.seda.event.DisconnectSubscriber;
+import org.apache.seda.event.EventFilter;
 import org.apache.seda.event.EventRouter;
 import org.apache.seda.event.InputEvent;
+import org.apache.seda.event.filter.ClientKeyTypeFilter;
+import org.apache.seda.event.filter.CompositeEventFilter;
+import org.apache.seda.event.filter.EventTypeFilter;
 import org.apache.seda.listener.ClientKey;
 import org.apache.seda.listener.KeyExpiryException;
 import org.apache.seda.listener.TCPClientKey;
@@ -94,8 +96,18 @@
         selector = Selector.open();
 
         this.router = router;
-        this.router.subscribe(ConnectEvent.class, null, this);
-        this.router.subscribe(DisconnectEvent.class, null, this);
+        this.router.subscribe(
+        		new CompositeEventFilter(
+        				new EventFilter[] {
+        						new EventTypeFilter(ConnectEvent.class),
+								new ClientKeyTypeFilter(TCPClientKey.class)
+        				}, CompositeEventFilter.AND), this);
+        this.router.subscribe(
+        		new CompositeEventFilter(
+        				new EventFilter[] {
+        						new EventTypeFilter(DisconnectEvent.class),
+								new ClientKeyTypeFilter(TCPClientKey.class)
+        				}, CompositeEventFilter.AND), this);
     }
 
     // ------------------------------------------------------------------------
@@ -441,7 +453,7 @@
      *
      * @author <a href="mailto:aok123@bellsouth.net">Alex Karasulu</a>
      * @author $Author$
-     * @version $Revision$
+     * @version $Revision: 56106 $
      */
     class ConcreteInputEvent extends InputEvent
     {

Modified: incubator/directory/seda/trunk/src/java/org/apache/seda/listener/TCPListenerManager.java
==============================================================================
--- incubator/directory/seda/trunk/src/java/org/apache/seda/listener/TCPListenerManager.java
(original)
+++ incubator/directory/seda/trunk/src/java/org/apache/seda/listener/TCPListenerManager.java
Mon Nov  1 06:45:13 2004
@@ -37,9 +37,13 @@
 import org.apache.seda.event.ConnectEvent;
 import org.apache.seda.event.DisconnectEvent;
 import org.apache.seda.event.DisconnectSubscriber;
+import org.apache.seda.event.EventFilter;
 import org.apache.seda.event.EventRouter;
 import org.apache.seda.event.ProtocolEvent;
 import org.apache.seda.event.ProtocolSubscriber;
+import org.apache.seda.event.filter.ClientKeyTypeFilter;
+import org.apache.seda.event.filter.CompositeEventFilter;
+import org.apache.seda.event.filter.EventTypeFilter;
 
 
 /**
@@ -101,7 +105,12 @@
         this.bindListeners = new HashSet();
         this.unbindListeners = new HashSet();
 
-        this.router.subscribe(DisconnectEvent.class, null, this);
+        this.router.subscribe(
+        		new CompositeEventFilter(
+        				new EventFilter[] {
+        						new EventTypeFilter(DisconnectEvent.class),
+								new ClientKeyTypeFilter(TCPClientKey.class)
+        				}, CompositeEventFilter.AND), this);
         this.monitor = new ListenerManagerMonitorAdapter();
     }
 

Modified: incubator/directory/seda/trunk/src/java/org/apache/seda/listener/UDPListenerManager.java
==============================================================================
--- incubator/directory/seda/trunk/src/java/org/apache/seda/listener/UDPListenerManager.java
(original)
+++ incubator/directory/seda/trunk/src/java/org/apache/seda/listener/UDPListenerManager.java
Mon Nov  1 06:45:13 2004
@@ -107,7 +107,6 @@
         this.unbindListeners = new HashSet();
         this.bp = bp;
 
-        this.router.subscribe(DisconnectEvent.class, null, this);
         this.monitor = new ListenerManagerMonitorAdapter();
     }
 
@@ -501,7 +500,7 @@
      *
      * @author <a href="mailto:aok123@bellsouth.net">Alex Karasulu</a>
      * @author $Author$
-     * @version $Revision$
+     * @version $Revision: 56106 $
      */
     class ConcreteInputEvent extends InputEvent
     {

Modified: incubator/directory/seda/trunk/src/java/org/apache/seda/output/TCPOutputManager.java
==============================================================================
--- incubator/directory/seda/trunk/src/java/org/apache/seda/output/TCPOutputManager.java	(original)
+++ incubator/directory/seda/trunk/src/java/org/apache/seda/output/TCPOutputManager.java	Mon
Nov  1 06:45:13 2004
@@ -29,9 +29,13 @@
 import org.apache.seda.event.ConnectSubscriber;
 import org.apache.seda.event.DisconnectEvent;
 import org.apache.seda.event.DisconnectSubscriber;
+import org.apache.seda.event.EventFilter;
 import org.apache.seda.event.EventRouter;
 import org.apache.seda.event.OutputEvent;
 import org.apache.seda.event.OutputSubscriber;
+import org.apache.seda.event.filter.ClientKeyTypeFilter;
+import org.apache.seda.event.filter.CompositeEventFilter;
+import org.apache.seda.event.filter.EventTypeFilter;
 import org.apache.seda.listener.ClientKey;
 import org.apache.seda.listener.KeyExpiryException;
 import org.apache.seda.listener.TCPClientKey;
@@ -75,9 +79,24 @@
     {
         super(config);
         this.router = router;
-        this.router.subscribe(OutputEvent.class, this);
-        this.router.subscribe(ConnectEvent.class, this);
-        this.router.subscribe(DisconnectEvent.class, this);
+        this.router.subscribe(
+        		new CompositeEventFilter(
+        				new EventFilter[] {
+        						new EventTypeFilter(ConnectEvent.class),
+								new ClientKeyTypeFilter(TCPClientKey.class)
+        				}, CompositeEventFilter.AND), this);
+        this.router.subscribe(
+        		new CompositeEventFilter(
+        				new EventFilter[] {
+        						new EventTypeFilter(OutputEvent.class),
+								new ClientKeyTypeFilter(TCPClientKey.class)
+        				}, CompositeEventFilter.AND), this);
+        this.router.subscribe(
+        		new CompositeEventFilter(
+        				new EventFilter[] {
+        						new EventTypeFilter(DisconnectEvent.class),
+								new ClientKeyTypeFilter(TCPClientKey.class)
+        				}, CompositeEventFilter.AND), this);
         config.setHandler(new OutputStageHandler());
         this.setStageMonitor(new LoggingStageMonitor());
         this.setOutputMonitor(new LoggingOutputMonitor());

Modified: incubator/directory/seda/trunk/src/java/org/apache/seda/output/UDPOutputManager.java
==============================================================================
--- incubator/directory/seda/trunk/src/java/org/apache/seda/output/UDPOutputManager.java	(original)
+++ incubator/directory/seda/trunk/src/java/org/apache/seda/output/UDPOutputManager.java	Mon
Nov  1 06:45:13 2004
@@ -18,10 +18,8 @@
 package org.apache.seda.output;
 
 import java.io.IOException;
-
 import java.nio.ByteBuffer;
 import java.nio.channels.DatagramChannel;
-
 import java.util.EventObject;
 import java.util.HashMap;
 import java.util.Map;
@@ -31,9 +29,13 @@
 import org.apache.seda.event.ConnectSubscriber;
 import org.apache.seda.event.DisconnectEvent;
 import org.apache.seda.event.DisconnectSubscriber;
+import org.apache.seda.event.EventFilter;
 import org.apache.seda.event.EventRouter;
 import org.apache.seda.event.OutputEvent;
 import org.apache.seda.event.OutputSubscriber;
+import org.apache.seda.event.filter.ClientKeyTypeFilter;
+import org.apache.seda.event.filter.CompositeEventFilter;
+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;
@@ -77,9 +79,12 @@
     {
         super(config);
         this.router = router;
-        this.router.subscribe(OutputEvent.class, this);
-        this.router.subscribe(ConnectEvent.class, this);
-        this.router.subscribe(DisconnectEvent.class, this);
+        this.router.subscribe(
+        		new CompositeEventFilter(
+        				new EventFilter[] {
+        						new EventTypeFilter(OutputEvent.class),
+								new ClientKeyTypeFilter(UDPClientKey.class)
+        				}, CompositeEventFilter.AND), this);
         config.setHandler(new OutputStageHandler());
         this.setStageMonitor(new LoggingStageMonitor());
         this.setOutputMonitor(new LoggingOutputMonitor());

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
Mon Nov  1 06:45:13 2004
@@ -22,10 +22,21 @@
 import java.util.Iterator;
 import java.util.Map;
 
-import org.apache.seda.event.*;
+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.stage.*;
+import org.apache.seda.stage.DefaultStage;
+import org.apache.seda.stage.DefaultStageConfig;
+import org.apache.seda.stage.LoggingStageMonitor;
+import org.apache.seda.stage.StageConfig;
+import org.apache.seda.stage.StageHandler;
 
 
 /**
@@ -60,8 +71,8 @@
 
         this.inetDb = inetDb;
         this.router = router;
-        this.router.subscribe(RequestEvent.class, this);
-        this.router.subscribe(ProtocolEvent.class, this);
+        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();
     }

Modified: incubator/directory/seda/trunk/src/test/org/apache/seda/decoder/DefaultDecoderManagerTest.java
==============================================================================
--- incubator/directory/seda/trunk/src/test/org/apache/seda/decoder/DefaultDecoderManagerTest.java
(original)
+++ incubator/directory/seda/trunk/src/test/org/apache/seda/decoder/DefaultDecoderManagerTest.java
Mon Nov  1 06:45:13 2004
@@ -20,6 +20,8 @@
 import java.util.EventObject;
 import java.util.Iterator;
 
+import junit.framework.TestCase;
+
 import org.apache.seda.buffer.BufferPool;
 import org.apache.seda.buffer.BufferPoolConfig;
 import org.apache.seda.buffer.DefaultBufferPool;
@@ -29,13 +31,12 @@
 import org.apache.seda.event.EventRouter;
 import org.apache.seda.event.RequestEvent;
 import org.apache.seda.event.RequestSubscriber;
+import org.apache.seda.event.filter.EventTypeFilter;
 import org.apache.seda.protocol.InetServiceEntry;
 import org.apache.seda.protocol.InetServicesDatabase;
 import org.apache.seda.stage.DefaultStageConfig;
 import org.apache.seda.thread.ThreadPool;
 
-import junit.framework.TestCase;
-
 
 /**
  * Tests the decoder manager pojo.
@@ -78,7 +79,7 @@
         bpConfig = new DefaultBufferPoolConfig("default", 10, 100, 10, 1024);
         bp = new DefaultBufferPool(bpConfig);
         router = new DefaultEventRouter();
-        router.subscribe(RequestEvent.class, this);
+        router.subscribe(new EventTypeFilter(RequestEvent.class), this);
         tpool =
             new ThreadPool()
                 {

Modified: incubator/directory/seda/trunk/src/test/org/apache/seda/examples/EchoProtocolProviderTest.java
==============================================================================
--- incubator/directory/seda/trunk/src/test/org/apache/seda/examples/EchoProtocolProviderTest.java
(original)
+++ incubator/directory/seda/trunk/src/test/org/apache/seda/examples/EchoProtocolProviderTest.java
Mon Nov  1 06:45:13 2004
@@ -42,6 +42,7 @@
     {
         EchoTCPClient client = new EchoTCPClient();
         client.connect(InetAddress.getLocalHost(), port);
+        client.setSoTimeout(3000);
 
         byte[] writeBuf = new byte[16];
 

Mime
View raw message