directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject svn commit: r110005 - /incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/input/ConnectSource.java /incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/input/test/TestConnectSource.java
Date Mon, 06 Dec 2004 18:50:33 GMT
Author: bloritsch
Date: Mon Dec  6 10:50:32 2004
New Revision: 110005

URL: http://svn.apache.org/viewcvs?view=rev&rev=110005
Log:
Did not add the all important "select()" method call...
Modified:
   incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/input/ConnectSource.java
   incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/input/test/TestConnectSource.java

Modified: incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/input/ConnectSource.java
Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/input/ConnectSource.java?view=diff&rev=110005&p1=incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/input/ConnectSource.java&r1=110004&p2=incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/input/ConnectSource.java&r2=110005
==============================================================================
--- incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/input/ConnectSource.java
(original)
+++ incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/input/ConnectSource.java
Mon Dec  6 10:50:32 2004
@@ -35,25 +35,37 @@
 public class ConnectSource implements Source
 {
     private Selector m_selector;
+    private long m_timeout;
 
     public ConnectSource() throws IOException
     {
         m_selector = Selector.open();
+        m_timeout = 1L;
     }
 
     public void setTimeout( final long timeout )
     {
+        m_timeout = timeout;
     }
 
     public Object dequeue()
     {
-        final Iterator keys = m_selector.selectedKeys().iterator();
         Object key = null;
 
-        if ( keys.hasNext() )
+        try
+        {
+            m_selector.select(m_timeout);
+            final Iterator keys = m_selector.selectedKeys().iterator();
+
+            if ( keys.hasNext() )
+            {
+                key = keys.next();
+                keys.remove();
+            }
+        }
+        catch ( IOException e )
         {
-            key = keys.next();
-            keys.remove();
+            e.printStackTrace();
         }
 
         return key;
@@ -63,11 +75,20 @@
     {
         final List keys = new ArrayList();
 
-        final Iterator set = m_selector.selectedKeys().iterator();
-        while( set.hasNext() )
+        try
+        {
+            m_selector.select(m_timeout);
+
+            final Iterator set = m_selector.selectedKeys().iterator();
+            while( set.hasNext() )
+            {
+                keys.add( set.next() );
+                set.remove();
+            }
+        }
+        catch ( IOException e )
         {
-            keys.add( set.next() );
-            set.remove();
+            e.printStackTrace();
         }
 
         return keys.toArray();
@@ -75,13 +96,22 @@
 
     public Object[] dequeue( final int numElements )
     {
-        final List keys = new ArrayList(numElements);
+        final List keys = new ArrayList();
+
+        try
+        {
+            m_selector.select(m_timeout);
 
-        final Iterator set = m_selector.selectedKeys().iterator();
-        for( int i = 0; i < numElements && set.hasNext(); i++ )
+            final Iterator set = m_selector.selectedKeys().iterator();
+            for( int i = 0; i < numElements && set.hasNext(); i++ )
+            {
+                keys.add( set.next() );
+                set.remove();
+            }
+        }
+        catch ( IOException e )
         {
-            keys.add( set.next() );
-            set.remove();
+            e.printStackTrace();
         }
 
         return keys.toArray();
@@ -91,10 +121,11 @@
     {
         try
         {
-            return m_selector.select( 0 );
+            return m_selector.select( m_timeout );
         }
         catch ( IOException e )
         {
+            e.printStackTrace();
             return 0;
         }
     }

Modified: incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/input/test/TestConnectSource.java
Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/input/test/TestConnectSource.java?view=diff&rev=110005&p1=incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/input/test/TestConnectSource.java&r1=110004&p2=incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/input/test/TestConnectSource.java&r2=110005
==============================================================================
--- incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/input/test/TestConnectSource.java
(original)
+++ incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/input/test/TestConnectSource.java
Mon Dec  6 10:50:32 2004
@@ -87,16 +87,11 @@
         m_clientChannel.connect( new InetSocketAddress(InetAddress.getLocalHost(), PORT)
);
         final Object key;
 
-        System.out.println(m_clientChannel.isConnectionPending());
-        System.out.println(m_clientChannel.isConnected());
-
         key = m_source.dequeue();
 
         assertNotNull( key );
         assertTrue( key instanceof SelectionKey );
         assertEquals( m_channel, ((SelectionKey)key).channel() );
-
-        assertTrue(m_clientChannel.isConnected());
     }
 
     public void testDequeue_many() throws IOException
@@ -132,7 +127,7 @@
         final Socket client = new Socket(InetAddress.getLocalHost(), PORT);
         assertTrue(client.isConnected());
 
-        m_source.setTimeout( 1L ); // does nothing
+        m_source.setTimeout( 10L );
         assertEquals( 1, m_source.size() );
 
         m_source.dequeueAll();

Mime
View raw message