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/17 17:52:40 UTC

svn commit: rev 46257 - in incubator/directory/seda/trunk/src: java/org/apache/seda/listener test/org/apache/seda/listener

Author: akarasulu
Date: Fri Sep 17 08:52:39 2004
New Revision: 46257

Added:
   incubator/directory/seda/trunk/src/java/org/apache/seda/listener/UDPListenerConfig.java   (contents, props changed)
Modified:
   incubator/directory/seda/trunk/src/java/org/apache/seda/listener/DefaultListenerConfig.java
   incubator/directory/seda/trunk/src/java/org/apache/seda/listener/DefaultListenerManager.java
   incubator/directory/seda/trunk/src/java/org/apache/seda/listener/ListenerConfig.java
   incubator/directory/seda/trunk/src/test/org/apache/seda/listener/DefaultListenerManagerTest.java
Log:
Applying Trustin's new updated patch #1 here:

http://nagoya.apache.org/jira/secure/attachment/17705/ListenerConfig.patch

This patch came from the following improvement JIRA:

http://nagoya.apache.org/jira/browse/DIRSEDA-8

Alex



Modified: incubator/directory/seda/trunk/src/java/org/apache/seda/listener/DefaultListenerConfig.java
==============================================================================
--- incubator/directory/seda/trunk/src/java/org/apache/seda/listener/DefaultListenerConfig.java	(original)
+++ incubator/directory/seda/trunk/src/java/org/apache/seda/listener/DefaultListenerConfig.java	Fri Sep 17 08:52:39 2004
@@ -1,154 +0,0 @@
-/*
- *   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.listener;
-
-
-import org.apache.seda.protocol.InetServiceEntry;
-
-
-/**
- * A default server listener.
- *
- * @author <a href="mailto:akarasulu@apache.org">Alex Karasulu</a>
- * @author $LastChangedBy$
- * @version $LastChangedRevision$
- */
-public class DefaultListenerConfig implements ListenerConfig
-{
-    /** the connection backlog */
-    private int backlog;
-    /** the interface address or hostname of the server */
-    private byte[] address;
-    /** whether or not ssl is used to secure connections */
-    private boolean isSecure;
-    /** the inet service provided by this listener */
-    private InetServiceEntry servEnt;
-
-    /**
-     * Creates a default listener with all the supplied properties.
-     * 
-     * @param a_address the interface address or hostname of the server
-     * @param a_backlog the connection backlog
-     * @param a_isSecure whether or not ssl is used to secure connections
-     * @param servEnt the inet service entry for the service this listner
-     * provides
-     */
-    public DefaultListenerConfig( byte[] a_address, int a_backlog,
-                                  boolean a_isSecure, InetServiceEntry servEnt )
-    {
-        this.backlog = a_backlog;
-        this.address = a_address;
-        this.isSecure = a_isSecure;
-        this.servEnt = servEnt;
-    }
-    
-    
-    /* (non-Javadoc)
-     * @see org.apache.seda.listener.ServerListener#getAddress()
-     */
-    public byte[] getAddress()
-    {
-        return this.address;
-    }
-
-    
-    /* (non-Javadoc)
-     * @see org.apache.seda.listener.ServerListener#getBacklog()
-     */
-    public int getBacklog()
-    {
-        return this.backlog;
-    }
-
-    
-    /* (non-Javadoc)
-     * @see org.apache.seda.listener.ServerListener#isSecure()
-     */
-    public boolean isSecure()
-    {
-        return this.isSecure;
-    }
-
-
-    /* (non-Javadoc)
-     * @see org.apache.seda.listener.ServerListener#getURL()
-     */
-    public String getURL()
-    {
-        StringBuffer l_buf = new StringBuffer();
-        
-        l_buf.append( servEnt.getName() );
-        l_buf.append( "://" );
-        l_buf.append( this.address );
-        l_buf.append( ':' );
-        l_buf.append( servEnt.getPort() );
-        
-        return l_buf.toString();
-    }
-
-
-    /**
-     * Gets the Inet service entry for the service this config's listner
-     * provides.
-     *
-     * @return the served service's entry
-     */
-    public InetServiceEntry getInetServiceEntry()
-    {
-        return servEnt;
-    }
-
-
-    /**
-     * Sets the address for the 
-     * 
-     * @param a_address The address to set.
-     */
-    protected void setAddress( byte[] a_address )
-    {
-        this.address = a_address;
-    }
-    
-
-    /**
-     * @param a_backlog The backlog to set.
-     */
-    protected void setBacklog( int a_backlog )
-    {
-        this.backlog = a_backlog;
-    }
-
-    
-    /**
-     * @param a_isSecure The isSecure to set.
-     */
-    protected void setSecure( boolean a_isSecure )
-    {
-        this.isSecure = a_isSecure;
-    }
-
-
-    /**
-     * Set's the inet service entry.
-     *
-     * @param servEnt the service entry of the service this listener provides
-     */
-    protected void setInetServiceEntry( InetServiceEntry servEnt )
-    {
-        this.servEnt = servEnt;
-    }
-}

Modified: incubator/directory/seda/trunk/src/java/org/apache/seda/listener/DefaultListenerManager.java
==============================================================================
--- incubator/directory/seda/trunk/src/java/org/apache/seda/listener/DefaultListenerManager.java	(original)
+++ incubator/directory/seda/trunk/src/java/org/apache/seda/listener/DefaultListenerManager.java	Fri Sep 17 08:52:39 2004
@@ -17,20 +17,16 @@
 package org.apache.seda.listener;
 
 
-import java.util.*;
+import org.apache.seda.event.*;
 
 import java.io.IOException;
-
-import java.net.Socket;
-import java.net.InetAddress;
 import java.net.InetSocketAddress;
-
-import java.nio.channels.Selector;
+import java.net.Socket;
 import java.nio.channels.SelectionKey;
-import java.nio.channels.SocketChannel;
+import java.nio.channels.Selector;
 import java.nio.channels.ServerSocketChannel;
-
-import org.apache.seda.event.*;
+import java.nio.channels.SocketChannel;
+import java.util.*;
 
 
 /**
@@ -119,6 +115,8 @@
      */
     public void bind( ListenerConfig listener ) throws IOException
     {
+        ensureListenerConfigType(listener);
+
         synchronized ( bindListeners )
         {
             bindListeners.add( listener );
@@ -133,6 +131,8 @@
      */
     public void unbind( ListenerConfig listener ) throws IOException
     {
+        ensureListenerConfigType(listener);
+
         synchronized ( unbindListeners )
         {
             unbindListeners.add( listener );
@@ -140,7 +140,13 @@
 
         selector.wakeup();
     }
-    
+
+    private void ensureListenerConfigType(ListenerConfig listener) {
+        if (listener == null)
+            throw new NullPointerException();
+        if (!(listener instanceof TCPListenerConfig))
+            throw new IllegalArgumentException();
+    }
 
     /**
      * Binds all the listeners that have been collecting up waiting to be bound.
@@ -154,14 +160,14 @@
             Iterator list = bindListeners.iterator();
             while ( list.hasNext() )
             {
-                ListenerConfig listener =
-                        ( ListenerConfig ) list.next();
+                TCPListenerConfig listener =
+                        ( TCPListenerConfig ) list.next();
                     
                 try
                 {
                     ServerSocketChannel channel = ServerSocketChannel.open();
-                    InetSocketAddress address = new InetSocketAddress( 
-                            InetAddress.getByAddress( listener.getAddress() ), 
+                    InetSocketAddress address = new InetSocketAddress(
+                            ((SocketListenerAddress) listener.getAddress()).getAddress(),
                             listener.getInetServiceEntry().getPort() );
                     channel.socket().bind( address, listener.getBacklog() );
                     channel.configureBlocking( false );

Modified: incubator/directory/seda/trunk/src/java/org/apache/seda/listener/ListenerConfig.java
==============================================================================
--- incubator/directory/seda/trunk/src/java/org/apache/seda/listener/ListenerConfig.java	(original)
+++ incubator/directory/seda/trunk/src/java/org/apache/seda/listener/ListenerConfig.java	Fri Sep 17 08:52:39 2004
@@ -26,28 +26,21 @@
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public interface ListenerConfig
+public abstract class ListenerConfig
 {
-    /**
-     * Gets the server socket backlog for this ListenerConfig
-     *
-     * @return client connection backlog
-     */
-    public int getBacklog();
+	private final ListenerAddress address;
 
+	public ListenerConfig(ListenerAddress address) {
+		if (address == null)
+			throw new NullPointerException("address");
+		this.address = address;
+	}
     /**
-     * Gets the ip interface address this ListenerConfig listens on.
-     *
-     * @return the ip address octets i.e. { 127,0,0,1 } for 127.0.0.1
-     */
-    public byte[] getAddress();
-    
-    /**
-     * Gets whether or not the listener is for establishing secure connections.
-     * 
-     * @return true if ssl is used to secure the connection, false otherwise.
+     * Gets the address on which this ListenerConfig listens.
      */
-    public boolean isSecure();
+    public final ListenerAddress getAddress() {
+	    return address;
+    }
     
     /**
      * Gets the URL for this ListenerConfig using the specified ip address and
@@ -56,12 +49,12 @@
      *
      * @return the URL with scheme like so ldap://localhost:389
      */
-    public String getURL();
+    public abstract String getURL();
 
     /**
      * Gets the InetServiceEntry associated with this ListenerConfig.
      *
      * @return the service entry for this listener
      */
-    public InetServiceEntry getInetServiceEntry();
+    public abstract InetServiceEntry getInetServiceEntry();
 }

Added: incubator/directory/seda/trunk/src/java/org/apache/seda/listener/UDPListenerConfig.java
==============================================================================
--- (empty file)
+++ incubator/directory/seda/trunk/src/java/org/apache/seda/listener/UDPListenerConfig.java	Fri Sep 17 08:52:39 2004
@@ -0,0 +1,85 @@
+/*
+ *   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.listener;
+
+import org.apache.seda.protocol.InetServiceEntry;
+
+/**
+ * A default server listener.
+ *
+ * @author <a href="mailto:akarasulu@apache.org">Alex Karasulu</a>
+ * @author $LastChangedBy$
+ * @version $LastChangedRevision$
+ */
+public class UDPListenerConfig extends ListenerConfig
+{
+    /** the inet service provided by this listener */
+    private InetServiceEntry servEnt;
+
+    /**
+     * Creates a default listener with all the supplied properties.
+     *
+     * @param a_address the interface address or hostname of the server
+     * @param servEnt the inet service entry for the service this listner
+     * provides
+     */
+    public UDPListenerConfig( SocketListenerAddress a_address, InetServiceEntry servEnt )
+    {
+	    super(a_address);
+
+        this.servEnt = servEnt;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.seda.listener.ServerListener#getURL()
+     */
+    public String getURL()
+    {
+        StringBuffer l_buf = new StringBuffer();
+
+        l_buf.append( servEnt.getName() );
+        l_buf.append( "://" );
+        l_buf.append( ((SocketListenerAddress) this.getAddress()).getAddress().
+                getHostAddress());
+        l_buf.append( ':' );
+        l_buf.append( servEnt.getPort() );
+
+        return l_buf.toString();
+    }
+
+
+    /**
+     * Gets the Inet service entry for the service this config's listner
+     * provides.
+     *
+     * @return the served service's entry
+     */
+    public InetServiceEntry getInetServiceEntry()
+    {
+        return servEnt;
+    }
+
+    /**
+     * Set's the inet service entry.
+     *
+     * @param servEnt the service entry of the service this listener provides
+     */
+    protected void setInetServiceEntry( InetServiceEntry servEnt )
+    {
+        this.servEnt = servEnt;
+    }
+}

Modified: incubator/directory/seda/trunk/src/test/org/apache/seda/listener/DefaultListenerManagerTest.java
==============================================================================
--- incubator/directory/seda/trunk/src/test/org/apache/seda/listener/DefaultListenerManagerTest.java	(original)
+++ incubator/directory/seda/trunk/src/test/org/apache/seda/listener/DefaultListenerManagerTest.java	Fri Sep 17 08:52:39 2004
@@ -23,6 +23,8 @@
 
 import junit.framework.TestCase;
 
+import java.net.InetAddress;
+
 
 /**
  * Tests the default ListenerManager's operations.
@@ -77,7 +79,7 @@
 
     public void testBind() throws Exception
     {
-        listener.bind( new DefaultListenerConfig( new byte[] { 127,0,0,1},
+        listener.bind( new TCPListenerConfig(new SocketListenerAddress(InetAddress.getLocalHost()),
                 50, false, new InetServiceEntry( "ldap", 10389 ) ) );
     }
 
@@ -85,7 +87,7 @@
     public void testUnbind() throws Exception
     {
         ListenerConfig sl = new
-                DefaultListenerConfig( new byte[] { 127,0,0,1}, 50, false,
+                TCPListenerConfig(new SocketListenerAddress(InetAddress.getLocalHost()), 50, false,
                         new InetServiceEntry( "ldap", 10389 ) );
         listener.bind( sl );
         listener.unbind( sl );