directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject svn commit: r111884 - in incubator/directory/network/trunk/sedang/src: java/org/apache/directory/seda test/org/apache/directory/seda/output/test test/org/apache/directory/seda/test
Date Tue, 14 Dec 2004 22:00:07 GMT
Author: bloritsch
Date: Tue Dec 14 14:00:06 2004
New Revision: 111884

URL: http://svn.apache.org/viewcvs?view=rev&rev=111884
Log:
Some more clean up, but its not listening quite yet....
Modified:
   incubator/directory/network/trunk/sedang/src/java/org/apache/directory/seda/SEDAServer.java
   incubator/directory/network/trunk/sedang/src/test/org/apache/directory/seda/output/test/TestWriter.java
   incubator/directory/network/trunk/sedang/src/test/org/apache/directory/seda/test/TestSEDAServer.java

Modified: incubator/directory/network/trunk/sedang/src/java/org/apache/directory/seda/SEDAServer.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/sedang/src/java/org/apache/directory/seda/SEDAServer.java?view=diff&rev=111884&p1=incubator/directory/network/trunk/sedang/src/java/org/apache/directory/seda/SEDAServer.java&r1=111883&p2=incubator/directory/network/trunk/sedang/src/java/org/apache/directory/seda/SEDAServer.java&r2=111884
==============================================================================
--- incubator/directory/network/trunk/sedang/src/java/org/apache/directory/seda/SEDAServer.java
(original)
+++ incubator/directory/network/trunk/sedang/src/java/org/apache/directory/seda/SEDAServer.java
Tue Dec 14 14:00:06 2004
@@ -51,6 +51,7 @@
     private final ProtocolRouter m_router;
     private final ConnectSource m_connect;
     private final Map m_protocols;
+    private final Map m_connections;
 
     private SEDAServer() throws IOException
     {
@@ -71,6 +72,7 @@
         m_manager.register( m_writer );
 
         m_protocols = new HashMap();
+        m_connections = new HashMap();
     }
 
     public static SEDAServer getServer() throws IOException
@@ -128,11 +130,13 @@
     public void addProtocolHandler( final int port, final ProtocolProvider handler)
             throws IOException
     {
+        final InetSocketAddress key = new InetSocketAddress(port);
         final ServerSocketChannel channel = ServerSocketChannel.open();
         channel.configureBlocking( false );
-        channel.socket().bind( new InetSocketAddress(port) );
+        channel.socket().bind( key );
 
         m_connect.listen( channel );
+        m_connections.put(key, channel);
 
         m_router.addPipe( String.valueOf(port), new DefaultPipe() );
         final DecoderStage decoder = new DecoderStage(handler);
@@ -152,12 +156,19 @@
 
         PipelineUtil.connectStage( encoder, m_writer );
 
-        m_protocols.put( String.valueOf(port), new ProtocolPipeline(decoder, request, encoder));
+        m_protocols.put( key, new ProtocolPipeline(decoder, request, encoder));
     }
 
     public void removeProtocolHandler( final int port )
     {
-        final ProtocolPipeline pipeline = (ProtocolPipeline)m_protocols.remove(String.valueOf(
port ) );
+        final InetSocketAddress key = new InetSocketAddress(port);
+        final ServerSocketChannel channel = (ServerSocketChannel)m_connections.remove( key
);
+        final ProtocolPipeline pipeline = (ProtocolPipeline)m_protocols.remove( key );
+
+        if ( null != channel )
+        {
+            m_connect.unlisten( channel );
+        }
 
         if ( null != pipeline )
         {

Modified: incubator/directory/network/trunk/sedang/src/test/org/apache/directory/seda/output/test/TestWriter.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/sedang/src/test/org/apache/directory/seda/output/test/TestWriter.java?view=diff&rev=111884&p1=incubator/directory/network/trunk/sedang/src/test/org/apache/directory/seda/output/test/TestWriter.java&r1=111883&p2=incubator/directory/network/trunk/sedang/src/test/org/apache/directory/seda/output/test/TestWriter.java&r2=111884
==============================================================================
--- incubator/directory/network/trunk/sedang/src/test/org/apache/directory/seda/output/test/TestWriter.java
(original)
+++ incubator/directory/network/trunk/sedang/src/test/org/apache/directory/seda/output/test/TestWriter.java
Tue Dec 14 14:00:06 2004
@@ -89,7 +89,8 @@
     {
         final NetworkEvent event = new NetworkEvent(m_clientChannel);
         event.setBuffer( BufferPool.getBuffer() );
-        event.getBuffer().put( "test".getBytes() ).flip();
+        event.getBuffer().put( "test".getBytes() );
+        event.getBuffer().flip();
         m_writer.handleEvent( event );
 
         final ByteBuffer buffer = ByteBuffer.allocate( 20 );

Modified: incubator/directory/network/trunk/sedang/src/test/org/apache/directory/seda/test/TestSEDAServer.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/sedang/src/test/org/apache/directory/seda/test/TestSEDAServer.java?view=diff&rev=111884&p1=incubator/directory/network/trunk/sedang/src/test/org/apache/directory/seda/test/TestSEDAServer.java&r1=111883&p2=incubator/directory/network/trunk/sedang/src/test/org/apache/directory/seda/test/TestSEDAServer.java&r2=111884
==============================================================================
--- incubator/directory/network/trunk/sedang/src/test/org/apache/directory/seda/test/TestSEDAServer.java
(original)
+++ incubator/directory/network/trunk/sedang/src/test/org/apache/directory/seda/test/TestSEDAServer.java
Tue Dec 14 14:00:06 2004
@@ -20,8 +20,10 @@
 import org.apache.directory.seda.SEDAServer;
 import org.apache.directory.seda.mocks.MockProtocolProvider;
 import org.apache.directory.seda.input.Firewall;
+import org.apache.protocol.bufferpool.BufferPool;
 
 import java.nio.channels.SocketChannel;
+import java.nio.ByteBuffer;
 import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.net.InetAddress;
@@ -84,9 +86,35 @@
     public void testConnection() throws IOException
     {
         final SEDAServer server = SEDAServer.getServer();
-        server.addProtocolHandler( PORT, new MockProtocolProvider() );
+        final SocketChannel client = SocketChannel.open();
+
+        try
+        {
+            server.addProtocolHandler( PORT, new MockProtocolProvider() );
+
+            client.configureBlocking( true );
+            client.connect( new InetSocketAddress(InetAddress.getLocalHost(), PORT));
+
+            ByteBuffer buffer = BufferPool.getBuffer();
+            buffer.put( "test".getBytes() );
+            buffer.flip();
+
+            client.write( buffer );
+            BufferPool.putBuffer( buffer );
 
-        // do something
-        server.removeProtocolHandler( PORT );
+            buffer = BufferPool.getBuffer();
+            client.read( buffer );
+            client.close();
+            buffer.flip();
+
+            assertEquals( "test", buffer.asCharBuffer().toString() );
+
+            BufferPool.putBuffer(buffer);
+        }
+        finally
+        {
+            server.removeProtocolHandler( PORT );
+            if (null != client) client.close();
+        }
     }
 }

Mime
View raw message