Author: akarasulu Date: Sat Sep 18 17:35:07 2004 New Revision: 46305 Added: incubator/directory/seda/trunk/maven.xml incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/EchoTest.java incubator/directory/seda/trunk/src/java/org/apache/seda/listener/SocketListenerConfig.java Removed: incubator/directory/seda/trunk/src/java/org/apache/seda/listener/SocketListenerAddress.java Modified: incubator/directory/seda/trunk/project.xml incubator/directory/seda/trunk/src/java/org/apache/seda/listener/ListenerConfig.java incubator/directory/seda/trunk/src/java/org/apache/seda/listener/TCPListenerConfig.java incubator/directory/seda/trunk/src/java/org/apache/seda/listener/TCPListenerManager.java incubator/directory/seda/trunk/src/java/org/apache/seda/listener/UDPListenerConfig.java incubator/directory/seda/trunk/src/test/org/apache/seda/DefaultFrontendFactoryTest.java incubator/directory/seda/trunk/src/test/org/apache/seda/listener/TCPListenerManagerTest.java Log: Commit changes ...
o applied latest patch by Trustin here: http://ecolapon.notlong.com o added new maven.xml to add src/examples to the list of src paths o removed SocketListenerAddress since its not needed anymore o added a simple EchoTest CLI prog for remote tests o Added new SocketListenerConfig which was not in Trustin's diff hope we got this right but he should check it out Added: incubator/directory/seda/trunk/maven.xml ============================================================================== --- (empty file) +++ incubator/directory/seda/trunk/maven.xml Sat Sep 18 17:35:07 2004 @@ -0,0 +1,13 @@ +<project default="test" + xmlns:ant="jelly:ant" xmlns:maven="jelly:maven"> + + <preGoal name="java:compile"> + <ant:path + id="my.other.src.dir" + location="${basedir}/src/examples"/> + <maven:addPath + id="maven.compile.src.set" + refid="my.other.src.dir"/> + </preGoal> + +</project> \ No newline at end of file Modified: incubator/directory/seda/trunk/project.xml ============================================================================== --- incubator/directory/seda/trunk/project.xml (original) +++ incubator/directory/seda/trunk/project.xml Sat Sep 18 17:35:07 2004 @@ -159,9 +159,9 @@ </excludes> <resources> - <!-- Actual test cases and supporting classes here --> + <!-- Examples of protocol providers using framework --> <resource> - <directory>${basedir}/src/test</directory> + <directory>${basedir}/src/examples</directory> <includes> <include>**/*.dtd</include> <include>**/*.ldif</include> @@ -172,9 +172,9 @@ </includes> </resource> - <!-- Examples of protocol providers using framework --> + <!-- Actual test cases and supporting classes here --> <resource> - <directory>${basedir}/src/examples</directory> + <directory>${basedir}/src/test</directory> <includes> <include>**/*.dtd</include> <include>**/*.ldif</include> @@ -184,6 +184,7 @@ <include>**/*.jar</include> </includes> </resource> + </resources> </unitTest> Added: incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/EchoTest.java ============================================================================== --- (empty file) +++ incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/EchoTest.java Sat Sep 18 17:35:07 2004 @@ -0,0 +1,39 @@ +import org.apache.commons.net.EchoTCPClient; + + +public class EchoTest +{ + public static void main(String[]args) + { + byte[] recieved = null; + + try + { + EchoTCPClient client = new EchoTCPClient(); + client.connect( args[0], 7 ); + byte[] toSend = args[1].getBytes(); + recieved = new byte[toSend.length]; + client.getOutputStream().write( toSend ); + client.getInputStream().read( recieved ); + client.disconnect(); + } + catch( Exception e ) + { + e.printStackTrace(); + System.out.println( "echo of '" + args[1] + + "' to " + args[0] + " failed!" ); + System.exit( 1 ); + } + + if ( args[1].equals( new String( recieved ) ) ) + { + System.out.println( "Successfully echo'd '" + args[1] + + "' to " + args[0] ) ; + System.exit( 0 ); + } + + System.out.println( "echo of '" + args[1] + "' to " + + args[0] + " failed!" ); + System.exit( 2 ); + } +} 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 Sat Sep 18 17:35:07 2004 @@ -17,7 +17,7 @@ package org.apache.seda.listener; -import org.apache.seda.protocol.InetServiceEntry; + /** @@ -28,33 +28,18 @@ */ public abstract class ListenerConfig { - private final ListenerAddress address; - - public ListenerConfig(ListenerAddress address) { - if (address == null) - throw new NullPointerException("address"); - this.address = address; - } /** - * Gets the address on which this ListenerConfig listens. + * Empty default constructor. */ - public final ListenerAddress getAddress() { - return address; - } - + protected ListenerConfig() { + } + /** - * Gets the URL for this ListenerConfig using the specified ip address and + * Gets the URI for this ListenerConfig using the specified ip address and * the tcp port number listened to. The ipaddress is resolved to a host * name. * - * @return the URL with scheme like so ldap://localhost:389 - */ - public abstract String getURL(); - - /** - * Gets the InetServiceEntry associated with this ListenerConfig. - * - * @return the service entry for this listener + * @return the URI with scheme like so ldap://localhost:389 */ - public abstract InetServiceEntry getInetServiceEntry(); + public abstract String getURI(); } Added: incubator/directory/seda/trunk/src/java/org/apache/seda/listener/SocketListenerConfig.java ============================================================================== --- (empty file) +++ incubator/directory/seda/trunk/src/java/org/apache/seda/listener/SocketListenerConfig.java Sat Sep 18 17:35:07 2004 @@ -0,0 +1,88 @@ +/* + * 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; + +import java.net.InetAddress; + + +/** + * The configuration base class for socket based listeners. + * + * @author <a href="mailto:[EMAIL PROTECTED]"> Apache Directory Project</a> + * @version $Rev$ + */ +public class SocketListenerConfig extends ListenerConfig +{ + /** the InetAddress associated with this server socket configuration */ + private final InetAddress inetAddress; + /** the service entry in the inet service database */ + private final InetServiceEntry servEnt; + + + /** + * Creates a socket listener config with all the supplied properties. + * + * @param inetAddress the inetAddress for the server listener + * @param servEnt the inet service entry for the service this listner + * provides + */ + public SocketListenerConfig( InetAddress inetAddress, InetServiceEntry servEnt ) + { + this.servEnt = servEnt; + this.inetAddress = inetAddress; + } + + + /** + * Gets the InetAddress associated with this server socket configuration. + * + * @return the address for the server socket associated with this config + */ + public InetAddress getInetAddress() + { + return inetAddress; + } + + + /** + * Gets the service entry in the inet service database associated with + * this server socket configuration. + * + * @return the service entry in the inet service database + */ + public InetServiceEntry getInetServiceEntry() + { + return servEnt; + } + + + public String getURI() + { + StringBuffer l_buf = new StringBuffer(); + + l_buf.append( servEnt.getName() ); + l_buf.append( "://" ); + l_buf.append( inetAddress ); + l_buf.append( ':' ); + l_buf.append( servEnt.getPort() ); + + return l_buf.toString(); + } +} Modified: incubator/directory/seda/trunk/src/java/org/apache/seda/listener/TCPListenerConfig.java ============================================================================== --- incubator/directory/seda/trunk/src/java/org/apache/seda/listener/TCPListenerConfig.java (original) +++ incubator/directory/seda/trunk/src/java/org/apache/seda/listener/TCPListenerConfig.java Sat Sep 18 17:35:07 2004 @@ -19,6 +19,8 @@ import org.apache.seda.protocol.InetServiceEntry; +import java.net.InetAddress; + /** * A default server listener. @@ -27,26 +29,21 @@ * @author $LastChangedBy$ * @version $LastChangedRevision$ */ -public class TCPListenerConfig extends ListenerConfig +public class TCPListenerConfig extends SocketListenerConfig { /** the connection backlog */ private int backlog; - /** the interface address or hostname of the server */ - private byte[] address; - /** the inet service provided by this listener */ - private InetServiceEntry servEnt; /** * Creates a default listener with all the supplied properties. * - * @param address the address for the server listener + * @param inetAddress the inetAddress for the server listener * @param servEnt the inet service entry for the service this listner * provides */ - public TCPListenerConfig( ListenerAddress address, InetServiceEntry servEnt ) + public TCPListenerConfig( InetAddress inetAddress, InetServiceEntry servEnt ) { - super( address ); - this.servEnt = servEnt; + super( inetAddress, servEnt ); } @@ -58,64 +55,12 @@ return this.backlog; } - - /* (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; - } - - - /** - * 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/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 Sat Sep 18 17:35:07 2004 @@ -166,8 +166,9 @@ try { ServerSocketChannel channel = ServerSocketChannel.open(); - InetSocketAddress address = new InetSocketAddress( - ((SocketListenerAddress) listener.getAddress()).getAddress(), + InetSocketAddress address = + new InetSocketAddress( + listener.getInetAddress(), listener.getInetServiceEntry().getPort() ); channel.socket().bind( address, listener.getBacklog() ); channel.configureBlocking( false ); Modified: incubator/directory/seda/trunk/src/java/org/apache/seda/listener/UDPListenerConfig.java ============================================================================== --- incubator/directory/seda/trunk/src/java/org/apache/seda/listener/UDPListenerConfig.java (original) +++ incubator/directory/seda/trunk/src/java/org/apache/seda/listener/UDPListenerConfig.java Sat Sep 18 17:35:07 2004 @@ -18,6 +18,8 @@ import org.apache.seda.protocol.InetServiceEntry; +import java.net.InetAddress; + /** * A default server listener. * @@ -25,11 +27,8 @@ * @author $LastChangedBy$ * @version $LastChangedRevision$ */ -public class UDPListenerConfig extends ListenerConfig +public class UDPListenerConfig extends SocketListenerConfig { - /** the inet service provided by this listener */ - private InetServiceEntry servEnt; - /** * Creates a default listener with all the supplied properties. * @@ -37,49 +36,8 @@ * @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 ) + public UDPListenerConfig( InetAddress a_address, InetServiceEntry servEnt ) { - this.servEnt = servEnt; + super(a_address, servEnt); } } Modified: incubator/directory/seda/trunk/src/test/org/apache/seda/DefaultFrontendFactoryTest.java ============================================================================== --- incubator/directory/seda/trunk/src/test/org/apache/seda/DefaultFrontendFactoryTest.java (original) +++ incubator/directory/seda/trunk/src/test/org/apache/seda/DefaultFrontendFactoryTest.java Sat Sep 18 17:35:07 2004 @@ -18,14 +18,13 @@ import junit.framework.TestCase; +import org.apache.commons.net.EchoTCPClient; +import org.apache.seda.examples.EchoProtocolProvider; +import org.apache.seda.listener.AvailablePortFinder; import org.apache.seda.listener.ListenerConfig; import org.apache.seda.listener.TCPListenerConfig; -import org.apache.seda.listener.SocketListenerAddress; -import org.apache.seda.listener.AvailablePortFinder; -import org.apache.seda.protocol.InetServiceEntry; import org.apache.seda.protocol.DefaultInetServicesDatabase; -import org.apache.seda.examples.EchoProtocolProvider; -import org.apache.commons.net.EchoTCPClient; +import org.apache.seda.protocol.InetServiceEntry; import java.io.IOException; import java.net.InetAddress; @@ -93,8 +92,9 @@ { int port = AvailablePortFinder.getNextAvailable(); ListenerConfig config = null; - config = new TCPListenerConfig( new SocketListenerAddress( - InetAddress.getLocalHost() ), new InetServiceEntry( "ldap", port ) ); + config = new TCPListenerConfig( + InetAddress.getLocalHost(), + new InetServiceEntry( "ldap", port ) ); fe.getListenerManager().bind( config ); fe.getListenerManager().unbind( config ); } @@ -107,8 +107,7 @@ ( ( DefaultInetServicesDatabase ) fe.getInetServicesDatabase() ) .addEntry( srvEntry ); ListenerConfig config = null; - config = new TCPListenerConfig( new SocketListenerAddress( - InetAddress.getLocalHost() ), srvEntry ); + config = new TCPListenerConfig( InetAddress.getLocalHost(), srvEntry ); fe.getListenerManager().bind( config ); fe.register( new EchoProtocolProvider() ); Modified: incubator/directory/seda/trunk/src/test/org/apache/seda/listener/TCPListenerManagerTest.java ============================================================================== --- incubator/directory/seda/trunk/src/test/org/apache/seda/listener/TCPListenerManagerTest.java (original) +++ incubator/directory/seda/trunk/src/test/org/apache/seda/listener/TCPListenerManagerTest.java Sat Sep 18 17:35:07 2004 @@ -80,7 +80,7 @@ { int port = AvailablePortFinder.getNextAvailable(); ListenerConfig config = new TCPListenerConfig( - new SocketListenerAddress( InetAddress.getLocalHost() ), + InetAddress.getLocalHost(), new InetServiceEntry( "ldap", port ) ); listener.bind( config ); listener.unbind( config ); @@ -91,7 +91,7 @@ { int port = AvailablePortFinder.getNextAvailable(); ListenerConfig config = new TCPListenerConfig( - new SocketListenerAddress(InetAddress.getLocalHost()), + InetAddress.getLocalHost(), new InetServiceEntry( "ldap", port ) ); listener.bind( config ); listener.unbind( config );
