directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject svn commit: r109728 - in incubator/directory/seda/branches/berin_api_proposal/src: java/org/apache/directory/seda/bufferpool java/org/apache/directory/seda/input java/org/apache/directory/seda/output java/org/apache/directory/seda/protocol test/org/apache/directory/seda/bufferpool test/org/apache/directory/seda/bufferpool/test test/org/apache/directory/seda/input test/org/apache/directory/seda/input/test test/org/apache/directory/seda/output test/org/apache/directory/seda/output/test test/org/apache/directory/seda/protocol test/org/apache/directory/seda/protocol/test
Date Fri, 03 Dec 2004 21:58:37 GMT
Author: bloritsch
Date: Fri Dec  3 13:58:35 2004
New Revision: 109728

URL: http://svn.apache.org/viewcvs?view=rev&rev=109728
Log:
Add the proposed package structure
Added:
   incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/bufferpool/
   incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/input/
   incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/input/ConnectSource.java
   incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/output/
   incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/protocol/
   incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/bufferpool/
   incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/bufferpool/test/
   incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/input/
   incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/input/test/
   incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/input/test/TestConnectSource.java
   incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/output/
   incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/output/test/
   incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/protocol/
   incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/protocol/test/

Added: 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=auto&rev=109728
==============================================================================
--- (empty file)
+++ incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/input/ConnectSource.java
Fri Dec  3 13:58:35 2004
@@ -0,0 +1,107 @@
+/*
+ *   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.directory.seda.input;
+
+import org.d_haven.event.Source;
+
+import java.nio.channels.Selector;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ArrayList;
+import java.net.ServerSocket;
+
+/**
+ * This stage does nothing other than retrieve the connection events
+ * from the java.nio selector.  It passes those events on to the next
+ * stage.
+ */
+public class ConnectSource implements Source
+{
+    private Selector m_selector;
+
+    public ConnectSource() throws IOException
+    {
+        m_selector = Selector.open();
+    }
+
+    public void setTimeout( final long timeout )
+    {
+    }
+
+    public Object dequeue()
+    {
+        final Iterator keys = m_selector.selectedKeys().iterator();
+        Object key = null;
+
+        if ( keys.hasNext() )
+        {
+            key = keys.next();
+            keys.remove();
+        }
+
+        return key;
+    }
+
+    public Object[] dequeueAll()
+    {
+        final List keys = new ArrayList();
+
+        final Iterator set = m_selector.selectedKeys().iterator();
+        while( set.hasNext() )
+        {
+            keys.add( set.next() );
+            set.remove();
+        }
+
+        return keys.toArray();
+    }
+
+    public Object[] dequeue( final int numElements )
+    {
+        final List keys = new ArrayList(numElements);
+
+        final Iterator set = m_selector.selectedKeys().iterator();
+        for( int i = 0; i < numElements && set.hasNext(); i++ )
+        {
+            keys.add( set.next() );
+            set.remove();
+        }
+
+        return keys.toArray();
+    }
+
+    public int size()
+    {
+        try
+        {
+            return m_selector.select( 0 );
+        }
+        catch ( IOException e )
+        {
+            return 0;
+        }
+    }
+
+    public void listen( final int port )
+    {
+    }
+
+    public void unlisten( final int port )
+    {
+    }
+}

Added: 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=auto&rev=109728
==============================================================================
--- (empty file)
+++ incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/input/test/TestConnectSource.java
Fri Dec  3 13:58:35 2004
@@ -0,0 +1,66 @@
+/*
+ *   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.directory.seda.input.test;
+
+import junit.framework.TestCase;
+
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.InetAddress;
+import java.io.IOException;
+
+import org.apache.directory.seda.input.ConnectSource;
+
+/**
+ * Created by IntelliJ IDEA. User: berin Date: Dec 3, 2004 Time: 9:12:50
+ * AM To change this template use File | Settings | File Templates.
+ */
+public class TestConnectSource extends TestCase
+{
+    private static final int PORT = 6666;
+    private ServerSocket m_socket;
+
+    public TestConnectSource(final String name)
+    {
+        super(name);
+    }
+
+    public void setUp() throws Exception
+    {
+        super.setUp();
+
+        m_socket = new ServerSocket(PORT);
+    }
+
+    public void tearDown() throws Exception
+    {
+        super.tearDown();
+
+        m_socket.close();
+    }
+
+    public void testConnectStage() throws IOException
+    {
+        final ConnectSource source = new ConnectSource();
+        source.listen(PORT);
+
+        final Socket client = new Socket(InetAddress.getLocalHost(), PORT);
+        assertTrue(client.isConnected());
+
+        source.unlisten(PORT);
+    }
+}

Mime
View raw message