You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by bl...@apache.org on 2004/12/09 23:35:37 UTC
svn commit: r111442 - in incubator/directory/seda/branches/berin_api_proposal: . src/java/org/apache/directory/seda src/java/org/apache/directory/seda/input src/java/org/apache/directory/seda/mocks src/java/org/apache/directory/seda/protocol src/test/org/apache/directory/seda/input/test src/test/org/apache/directory/seda/test
Author: bloritsch
Date: Thu Dec 9 14:35:36 2004
New Revision: 111442
URL: http://svn.apache.org/viewcvs?view=rev&rev=111442
Log:
I have some definite cleanup and bug fixing to do, but the bulk of how things should work is in place
Added:
incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/ProtocolPipeline.java
incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/mocks/
incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/mocks/MockDecoder.java
incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/mocks/MockDecoderFactory.java
incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/mocks/MockEncoder.java
incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/mocks/MockEncoderFactory.java
incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/mocks/MockProtocolProvider.java
incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/mocks/MockRequestHandler.java
incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/protocol/DecoderStage.java
incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/protocol/EncoderStage.java
incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/protocol/ProtocolProvider.java
incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/protocol/RequestHandler.java
incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/protocol/RequestStage.java
Modified:
incubator/directory/seda/branches/berin_api_proposal/SedaRedesign.iml
incubator/directory/seda/branches/berin_api_proposal/project.xml
incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/PipelineUtil.java
incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/SEDAServer.java
incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/Stage.java
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
incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/test/TestSEDAServer.java
Modified: incubator/directory/seda/branches/berin_api_proposal/SedaRedesign.iml
Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/berin_api_proposal/SedaRedesign.iml?view=diff&rev=111442&p1=incubator/directory/seda/branches/berin_api_proposal/SedaRedesign.iml&r1=111441&p2=incubator/directory/seda/branches/berin_api_proposal/SedaRedesign.iml&r2=111442
==============================================================================
--- incubator/directory/seda/branches/berin_api_proposal/SedaRedesign.iml (original)
+++ incubator/directory/seda/branches/berin_api_proposal/SedaRedesign.iml Thu Dec 9 14:35:36 2004
@@ -17,6 +17,7 @@
<orderEntry type="library" name="Doug Lea's Concurrent" level="application" />
<orderEntry type="library" name="JUnit" level="application" />
<orderEntry type="library" name="Event" level="application" />
+ <orderEntry type="library" name="Codec Stateful" level="application" />
<orderEntryProperties />
</component>
</module>
Modified: incubator/directory/seda/branches/berin_api_proposal/project.xml
Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/berin_api_proposal/project.xml?view=diff&rev=111442&p1=incubator/directory/seda/branches/berin_api_proposal/project.xml&r1=111441&p2=incubator/directory/seda/branches/berin_api_proposal/project.xml&r2=111442
==============================================================================
--- incubator/directory/seda/branches/berin_api_proposal/project.xml (original)
+++ incubator/directory/seda/branches/berin_api_proposal/project.xml Thu Dec 9 14:35:36 2004
@@ -86,6 +86,12 @@
<version>1.3.4</version>
<url>http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html</url>
</dependency>
+ <dependency>
+ <groupId>incubator-directory</groupId>
+ <artifactId>snickers-codec</artifactId>
+ <version>0.2.0-SNAPSHOT</version>
+ <url>http://incubator.apache.org/directory/subprojects/ldap/common</url>
+ </dependency>
</dependencies>
<build>
Modified: incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/PipelineUtil.java
Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/PipelineUtil.java?view=diff&rev=111442&p1=incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/PipelineUtil.java&r1=111441&p2=incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/PipelineUtil.java&r2=111442
==============================================================================
--- incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/PipelineUtil.java (original)
+++ incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/PipelineUtil.java Thu Dec 9 14:35:36 2004
@@ -16,6 +16,8 @@
*/
package org.apache.directory.seda;
+import org.d_haven.event.Pipe;
+
/**
* Utility to connect pipelines together.
*/
@@ -31,5 +33,25 @@
final Stage destination )
{
destination.addSource( origin.getNamedPipe( name ) );
+ }
+
+ public static void disconnectStage( final Stage origin, final String name,
+ final Stage destination )
+ {
+ final Pipe pipe = origin.getNamedPipe( name );
+ destination.removeSource( pipe );
+
+ // Flush out the contents
+ destination.handleEvents(pipe.dequeueAll());
+ }
+
+ public static void disconnectStage( final Stage origin,
+ final Stage destination )
+ {
+ final Pipe pipe = origin.getDefaultPipe();
+ destination.removeSource( pipe );
+
+ // Flush out the contents
+ destination.handleEvents(pipe.dequeueAll());
}
}
Added: incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/ProtocolPipeline.java
Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/ProtocolPipeline.java?view=auto&rev=111442
==============================================================================
--- (empty file)
+++ incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/ProtocolPipeline.java Thu Dec 9 14:35:36 2004
@@ -0,0 +1,41 @@
+/*
+ * 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;
+
+import org.apache.directory.seda.protocol.DecoderStage;
+import org.apache.directory.seda.protocol.RequestStage;
+import org.apache.directory.seda.protocol.EncoderStage;
+
+/**
+ * Created by IntelliJ IDEA. User: berin Date: Dec 9, 2004 Time: 5:15:39
+ * PM To change this template use File | Settings | File Templates.
+ */
+public class ProtocolPipeline
+{
+ public final DecoderStage decoderStage;
+ public final RequestStage requestStage;
+ public final EncoderStage encoderStage;
+
+ public ProtocolPipeline( final DecoderStage decoder,
+ final RequestStage request,
+ final EncoderStage encoder )
+ {
+ decoderStage = decoder;
+ requestStage = request;
+ encoderStage = encoder;
+ }
+}
Modified: incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/SEDAServer.java
Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/SEDAServer.java?view=diff&rev=111442&p1=incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/SEDAServer.java&r1=111441&p2=incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/SEDAServer.java&r2=111442
==============================================================================
--- incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/SEDAServer.java (original)
+++ incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/SEDAServer.java Thu Dec 9 14:35:36 2004
@@ -18,10 +18,23 @@
import org.apache.directory.seda.input.Firewall;
import org.apache.directory.seda.input.ReaderSource;
+import org.apache.directory.seda.input.ConnectSource;
import org.apache.directory.seda.output.Writer;
+import org.apache.directory.seda.protocol.ProtocolProvider;
+import org.apache.directory.seda.protocol.EncoderStage;
+import org.apache.directory.seda.protocol.RequestStage;
+import org.apache.directory.seda.protocol.DecoderStage;
+import org.d_haven.event.command.ThreadManager;
+import org.d_haven.event.command.DefaultThreadManager;
+import org.d_haven.event.impl.DefaultPipe;
import java.nio.channels.SocketChannel;
+import java.nio.channels.ServerSocketChannel;
import java.io.IOException;
+import java.net.ServerSocket;
+import java.net.InetSocketAddress;
+import java.util.Map;
+import java.util.HashMap;
/**
* Created by IntelliJ IDEA. User: berin Date: Dec 7, 2004 Time:
@@ -34,12 +47,30 @@
private final Firewall m_firewall;
private final ReaderSource m_reader;
private final Writer m_writer;
+ private final ThreadManager m_manager;
+ private final ProtocolRouter m_router;
+ private final ConnectSource m_connect;
+ private final Map m_protocols;
private SEDAServer() throws IOException
{
m_firewall = new Firewall();
m_reader = new ReaderSource();
m_writer = new Writer();
+ m_manager = new DefaultThreadManager();
+
+ m_connect = new ConnectSource();
+ m_firewall.addSource( m_connect );
+ m_manager.register( m_firewall );
+
+ m_router = new ProtocolRouter();
+ m_router.addSource( m_reader );
+ PipelineUtil.connectStage( m_router, m_writer );
+
+ m_manager.register( m_router );
+ m_manager.register( m_writer );
+
+ m_protocols = new HashMap();
}
public static SEDAServer getServer() throws IOException
@@ -68,7 +99,7 @@
}
catch (IOException ioe)
{
- // Could not connect the writer so we disconnect the reader
+ // Could not connect the writer so we disconnectStage the reader
m_reader.disconnect( client );
throw ioe;
@@ -92,5 +123,55 @@
{
m_reader.disconnect( client );
m_writer.disconnect( client );
+ }
+
+ public void addProtocolHandler( final int port, final ProtocolProvider handler)
+ throws IOException
+ {
+ final ServerSocketChannel channel = ServerSocketChannel.open();
+ channel.configureBlocking( false );
+ channel.socket().bind( new InetSocketAddress(port) );
+
+ m_connect.listen( channel );
+
+ m_router.addPipe( String.valueOf(port), new DefaultPipe() );
+ final DecoderStage decoder = new DecoderStage(handler.getDecoderFactory());
+ PipelineUtil.connectStage( m_router, String.valueOf(port), decoder );
+
+ m_manager.register( decoder );
+
+ final RequestStage request = new RequestStage(handler);
+ PipelineUtil.connectStage( decoder, request );
+
+ m_manager.register( request );
+
+ final EncoderStage encoder = new EncoderStage(handler.getEncoderFactory());
+ PipelineUtil.connectStage( request, encoder );
+
+ m_manager.register( encoder );
+
+ PipelineUtil.connectStage( encoder, m_writer );
+
+ m_protocols.put( String.valueOf(port), new ProtocolPipeline(decoder, request, encoder));
+ }
+
+ public void removeProtocolHandler( final int port )
+ {
+ final ProtocolPipeline pipeline = (ProtocolPipeline)m_protocols.remove(String.valueOf( port ) );
+
+ if ( null != pipeline )
+ {
+ PipelineUtil.disconnectStage( m_router, String.valueOf(port),pipeline.encoderStage );
+ m_router.removeNamedPipe(String.valueOf(port));
+
+ m_manager.unregister( pipeline.encoderStage );
+ PipelineUtil.disconnectStage( pipeline.encoderStage, pipeline.requestStage );
+
+ m_manager.unregister( pipeline.requestStage );
+ PipelineUtil.disconnectStage( pipeline.requestStage, pipeline.decoderStage );
+
+ m_manager.unregister( pipeline.decoderStage );
+ PipelineUtil.disconnectStage( pipeline.decoderStage, m_writer );
+ }
}
}
Modified: incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/Stage.java
Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/Stage.java?view=diff&rev=111442&p1=incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/Stage.java&r1=111441&p2=incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/Stage.java&r2=111442
==============================================================================
--- incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/Stage.java (original)
+++ incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/Stage.java Thu Dec 9 14:35:36 2004
@@ -90,4 +90,14 @@
{
return (Pipe)m_namedSinks.get(name);
}
+
+ public void removeSource( final Pipe pipe )
+ {
+ m_sources.remove( pipe );
+ }
+
+ public void removeNamedPipe( final String name )
+ {
+ m_namedSinks.remove( name );
+ }
}
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=111442&p1=incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/input/ConnectSource.java&r1=111441&p2=incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/input/ConnectSource.java&r2=111442
==============================================================================
--- 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 Thu Dec 9 14:35:36 2004
@@ -21,6 +21,7 @@
import java.nio.channels.Selector;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
+import java.nio.channels.ServerSocketChannel;
import java.io.IOException;
import java.util.Iterator;
import java.util.ArrayList;
@@ -100,9 +101,8 @@
}
}
- public void listen( final ServerSocket socket ) throws IOException
+ public void listen( final ServerSocketChannel channel ) throws IOException
{
- final SelectableChannel channel = socket.getChannel();
if ( channel.isBlocking() )
{
channel.configureBlocking( false );
@@ -111,10 +111,8 @@
channel.register( m_selector, SelectionKey.OP_ACCEPT );
}
- public void unlisten( final ServerSocket socket )
+ public void unlisten( final ServerSocketChannel channel )
{
- final SelectableChannel channel = socket.getChannel();
-
final SelectionKey key = channel.keyFor( m_selector );
key.cancel();
}
Added: incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/mocks/MockDecoder.java
Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/mocks/MockDecoder.java?view=auto&rev=111442
==============================================================================
--- (empty file)
+++ incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/mocks/MockDecoder.java Thu Dec 9 14:35:36 2004
@@ -0,0 +1,44 @@
+/*
+ * 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.mocks;
+
+import org.apache.snickers.codec.stateful.StatefulDecoder;
+import org.apache.snickers.codec.stateful.DecoderCallback;
+import org.apache.snickers.codec.stateful.DecoderMonitor;
+import org.apache.snickers.codec.DecoderException;
+
+/**
+ * Created by IntelliJ IDEA. User: berin Date: Dec 9, 2004 Time: 3:28:49
+ * PM To change this template use File | Settings | File Templates.
+ */
+public class MockDecoder implements StatefulDecoder
+{
+ public void decode( Object o ) throws DecoderException
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setCallback( final DecoderCallback decoderCallback )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setDecoderMonitor( final DecoderMonitor decoderMonitor )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+}
Added: incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/mocks/MockDecoderFactory.java
Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/mocks/MockDecoderFactory.java?view=auto&rev=111442
==============================================================================
--- (empty file)
+++ incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/mocks/MockDecoderFactory.java Thu Dec 9 14:35:36 2004
@@ -0,0 +1,32 @@
+/*
+ * 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.mocks;
+
+import org.apache.snickers.codec.stateful.DecoderFactory;
+import org.apache.snickers.codec.stateful.StatefulDecoder;
+
+/**
+ * Created by IntelliJ IDEA. User: berin Date: Dec 9, 2004 Time: 3:28:23
+ * PM To change this template use File | Settings | File Templates.
+ */
+public class MockDecoderFactory implements DecoderFactory
+{
+ public StatefulDecoder createDecoder()
+ {
+ return new MockDecoder();
+ }
+}
Added: incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/mocks/MockEncoder.java
Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/mocks/MockEncoder.java?view=auto&rev=111442
==============================================================================
--- (empty file)
+++ incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/mocks/MockEncoder.java Thu Dec 9 14:35:36 2004
@@ -0,0 +1,44 @@
+/*
+ * 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.mocks;
+
+import org.apache.snickers.codec.stateful.StatefulEncoder;
+import org.apache.snickers.codec.stateful.EncoderCallback;
+import org.apache.snickers.codec.stateful.EncoderMonitor;
+import org.apache.snickers.codec.EncoderException;
+
+/**
+ * Created by IntelliJ IDEA. User: berin Date: Dec 9, 2004 Time: 3:30:04
+ * PM To change this template use File | Settings | File Templates.
+ */
+public class MockEncoder implements StatefulEncoder
+{
+ public void encode( Object o ) throws EncoderException
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setCallback( EncoderCallback encoderCallback )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setEncoderMonitor( EncoderMonitor encoderMonitor )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+}
Added: incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/mocks/MockEncoderFactory.java
Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/mocks/MockEncoderFactory.java?view=auto&rev=111442
==============================================================================
--- (empty file)
+++ incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/mocks/MockEncoderFactory.java Thu Dec 9 14:35:36 2004
@@ -0,0 +1,32 @@
+/*
+ * 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.mocks;
+
+import org.apache.snickers.codec.stateful.EncoderFactory;
+import org.apache.snickers.codec.stateful.StatefulEncoder;
+
+/**
+ * Created by IntelliJ IDEA. User: berin Date: Dec 9, 2004 Time: 3:29:43
+ * PM To change this template use File | Settings | File Templates.
+ */
+public class MockEncoderFactory implements EncoderFactory
+{
+ public StatefulEncoder createEncoder()
+ {
+ return new MockEncoder();
+ }
+}
Added: incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/mocks/MockProtocolProvider.java
Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/mocks/MockProtocolProvider.java?view=auto&rev=111442
==============================================================================
--- (empty file)
+++ incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/mocks/MockProtocolProvider.java Thu Dec 9 14:35:36 2004
@@ -0,0 +1,73 @@
+/*
+ * 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.mocks;
+
+import org.apache.directory.seda.protocol.ProtocolProvider;
+import org.apache.directory.seda.protocol.RequestHandler;
+import org.apache.snickers.codec.stateful.DecoderFactory;
+import org.apache.snickers.codec.stateful.EncoderFactory;
+
+/**
+ * Created by IntelliJ IDEA. User: berin Date: Dec 9, 2004 Time: 3:27:08
+ * PM To change this template use File | Settings | File Templates.
+ */
+public class MockProtocolProvider implements ProtocolProvider
+{
+ /**
+ * Gets the authoritative name for the service of this provider.
+ *
+ * @return the authoritative service name
+ */
+ public String getName()
+ {
+ return "MockProtocolProvider";
+ }
+
+ /**
+ * Gets a factory used to create a new StatefulDecoder for this
+ * service's protocol.
+ *
+ * @return a new StatefulDecoder for this service's protocol
+ */
+ public DecoderFactory getDecoderFactory()
+ {
+ return new MockDecoderFactory(); //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ /**
+ * Gets a factory used to create a new StatefulEncoder for this
+ * service's protocol.
+ *
+ * @return a new StatefulEncoder for this service's protocol
+ */
+ public EncoderFactory getEncoderFactory()
+ {
+ return new MockEncoderFactory(); //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ /**
+ * Gets a protocol specific handler for an request object.
+ *
+ * @param request the protocol request to handle
+ *
+ * @return the protocol request handler for the request object
+ */
+ public RequestHandler getHandler( final Object request )
+ {
+ return new MockRequestHandler(); //To change body of implemented methods use File | Settings | File Templates.
+ }
+}
Added: incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/mocks/MockRequestHandler.java
Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/mocks/MockRequestHandler.java?view=auto&rev=111442
==============================================================================
--- (empty file)
+++ incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/mocks/MockRequestHandler.java Thu Dec 9 14:35:36 2004
@@ -0,0 +1,39 @@
+/*
+ * 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.mocks;
+
+import org.apache.directory.seda.protocol.RequestHandler;
+
+/**
+ * Created by IntelliJ IDEA. User: berin Date: Dec 9, 2004 Time: 3:30:40
+ * PM To change this template use File | Settings | File Templates.
+ */
+public class MockRequestHandler implements RequestHandler
+{
+ /**
+ * Handles a request that can return 0..n responses. Those
+ * responses are then encoded and returned to the user.
+ *
+ * @param request the request object from the encoder
+ *
+ * @return an array of 0..n elements for the responses.
+ */
+ public Object[] handleRequest( final Object request )
+ {
+ return RequestHandler.NO_RESPONSE;
+ }
+}
Added: incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/protocol/DecoderStage.java
Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/protocol/DecoderStage.java?view=auto&rev=111442
==============================================================================
--- (empty file)
+++ incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/protocol/DecoderStage.java Thu Dec 9 14:35:36 2004
@@ -0,0 +1,77 @@
+/*
+ * 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.protocol;
+
+import org.apache.directory.seda.Stage;
+import org.apache.directory.seda.NetworkEvent;
+import org.apache.directory.seda.bufferpool.BufferPool;
+import org.apache.snickers.codec.stateful.StatefulDecoder;
+import org.apache.snickers.codec.stateful.DecoderFactory;
+import org.apache.snickers.codec.DecoderException;
+
+import java.util.Map;
+import java.util.WeakHashMap;
+import java.nio.channels.SocketChannel;
+
+/**
+ * Created by IntelliJ IDEA. User: berin Date: Dec 9, 2004 Time: 4:51:52
+ * PM To change this template use File | Settings | File Templates.
+ */
+public class DecoderStage extends Stage
+{
+ private final DecoderFactory m_factory;
+ private Map m_encoders;
+
+ public DecoderStage(final DecoderFactory factory)
+ {
+ m_factory = factory;
+ m_encoders = new WeakHashMap();
+ }
+ public void handleEvent(final Object obj)
+ {
+ if (obj instanceof NetworkEvent)
+ {
+ final NetworkEvent event = (NetworkEvent)obj;
+ final StatefulDecoder encoder = getDecoder(event.channel());
+ try
+ {
+ encoder.decode( event.getBuffer() );
+ BufferPool.putBuffer( event.getBuffer() );
+ event.setBuffer( null );
+ }
+ catch ( DecoderException e )
+ {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+ }
+
+ super.handleEvent( obj );
+ }
+
+ private StatefulDecoder getDecoder( final SocketChannel socketChannel )
+ {
+ StatefulDecoder encoder = (StatefulDecoder)m_encoders.get(socketChannel);
+
+ if(encoder == null)
+ {
+ encoder = m_factory.createDecoder();
+ m_encoders.put(socketChannel, encoder);
+ }
+
+ return encoder;
+ }
+}
Added: incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/protocol/EncoderStage.java
Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/protocol/EncoderStage.java?view=auto&rev=111442
==============================================================================
--- (empty file)
+++ incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/protocol/EncoderStage.java Thu Dec 9 14:35:36 2004
@@ -0,0 +1,76 @@
+/*
+ * 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.protocol;
+
+import org.apache.directory.seda.Stage;
+import org.apache.directory.seda.NetworkEvent;
+import org.apache.snickers.codec.stateful.EncoderFactory;
+import org.apache.snickers.codec.stateful.StatefulEncoder;
+import org.apache.snickers.codec.EncoderException;
+
+import java.nio.channels.SocketChannel;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+/**
+ * Created by IntelliJ IDEA. User: berin Date: Dec 9, 2004 Time: 3:32:12
+ * PM To change this template use File | Settings | File Templates.
+ */
+public class EncoderStage extends Stage
+{
+ private final EncoderFactory m_factory;
+ private Map m_encoders;
+
+ public EncoderStage(final EncoderFactory factory)
+ {
+ m_factory = factory;
+ m_encoders = new WeakHashMap();
+ }
+ public void handleEvent(final Object obj)
+ {
+ if (obj instanceof NetworkEvent)
+ {
+ final NetworkEvent event = (NetworkEvent)obj;
+ final StatefulEncoder encoder = getEncoder(event.channel());
+ try
+ {
+ encoder.encode( event );
+ }
+ catch ( EncoderException e )
+ {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+ }
+ else
+ {
+ super.handleEvent( obj );
+ }
+ }
+
+ private StatefulEncoder getEncoder( final SocketChannel socketChannel )
+ {
+ StatefulEncoder encoder = (StatefulEncoder)m_encoders.get(socketChannel);
+
+ if(encoder == null)
+ {
+ encoder = m_factory.createEncoder();
+ m_encoders.put(socketChannel, encoder);
+ }
+
+ return encoder;
+ }
+}
Added: incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/protocol/ProtocolProvider.java
Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/protocol/ProtocolProvider.java?view=auto&rev=111442
==============================================================================
--- (empty file)
+++ incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/protocol/ProtocolProvider.java Thu Dec 9 14:35:36 2004
@@ -0,0 +1,60 @@
+/*
+ * 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.protocol;
+
+import org.apache.snickers.codec.stateful.EncoderFactory;
+import org.apache.snickers.codec.stateful.DecoderFactory;
+
+/**
+ * Interface for a internet service provider.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory Project</a>
+ * @version $Rev: 111192 $
+ */
+public interface ProtocolProvider
+{
+ /**
+ * Gets the authoritative name for the service of this provider.
+ *
+ * @return the authoritative service name
+ */
+ String getName();
+
+ /**
+ * Gets a factory used to create a new StatefulDecoder for this service's
+ * protocol.
+ *
+ * @return a new StatefulDecoder for this service's protocol
+ */
+ DecoderFactory getDecoderFactory();
+
+ /**
+ * Gets a factory used to create a new StatefulEncoder for this service's
+ * protocol.
+ *
+ * @return a new StatefulEncoder for this service's protocol
+ */
+ EncoderFactory getEncoderFactory();
+
+ /**
+ * Gets a protocol specific handler for an request object.
+ *
+ * @param request the protocol request to handle
+ * @return the protocol request handler for the request object
+ */
+ RequestHandler getHandler(Object request);
+}
\ No newline at end of file
Added: incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/protocol/RequestHandler.java
Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/protocol/RequestHandler.java?view=auto&rev=111442
==============================================================================
--- (empty file)
+++ incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/protocol/RequestHandler.java Thu Dec 9 14:35:36 2004
@@ -0,0 +1,40 @@
+/*
+ * 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.protocol;
+
+/**
+ * The RequestHandler is how the SEDA system interacts with the
+ * ProtocolProvider to actually handle individual requests.
+ */
+public interface RequestHandler
+{
+ /**
+ * A constant to use when the request does not return a response.
+ * This is a convenience.
+ */
+ Object[] NO_RESPONSE = new Object[0];
+
+ /**
+ * Handles a request that can return 0..n responses. Those
+ * responses are then encoded and returned to the user.
+ *
+ * @param request the request object from the encoder
+ *
+ * @return an array of 0..n elements for the responses.
+ */
+ Object[] handleRequest(Object request);
+}
Added: incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/protocol/RequestStage.java
Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/protocol/RequestStage.java?view=auto&rev=111442
==============================================================================
--- (empty file)
+++ incubator/directory/seda/branches/berin_api_proposal/src/java/org/apache/directory/seda/protocol/RequestStage.java Thu Dec 9 14:35:36 2004
@@ -0,0 +1,44 @@
+/*
+ * 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.protocol;
+
+import org.apache.directory.seda.Stage;
+
+/**
+ * Created by IntelliJ IDEA. User: berin Date: Dec 9, 2004 Time: 4:55:11
+ * PM To change this template use File | Settings | File Templates.
+ */
+public class RequestStage extends Stage
+{
+ private ProtocolProvider m_provider;
+
+ public RequestStage( final ProtocolProvider provider )
+ {
+ m_provider = provider;
+ }
+
+ public void handleEvent(final Object event)
+ {
+ final RequestHandler handler = m_provider.getHandler( event );
+ final Object[] values = handler.handleRequest( event );
+
+ for (int i = 0; i < values.length; i++)
+ {
+ super.handleEvent( values[i] );
+ }
+ }
+}
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=111442&p1=incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/input/test/TestConnectSource.java&r1=111441&p2=incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/input/test/TestConnectSource.java&r2=111442
==============================================================================
--- 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 Thu Dec 9 14:35:36 2004
@@ -58,14 +58,14 @@
m_clientChannel.configureBlocking( false );
m_source = new ConnectSource();
- m_source.listen(m_socket);
+ m_source.listen(m_channel);
}
public void tearDown() throws Exception
{
super.tearDown();
- m_source.unlisten(m_socket);
+ m_source.unlisten(m_channel);
m_source.close();
m_socket.close();
Modified: incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/test/TestSEDAServer.java
Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/test/TestSEDAServer.java?view=diff&rev=111442&p1=incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/test/TestSEDAServer.java&r1=111441&p2=incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/test/TestSEDAServer.java&r2=111442
==============================================================================
--- incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/test/TestSEDAServer.java (original)
+++ incubator/directory/seda/branches/berin_api_proposal/src/test/org/apache/directory/seda/test/TestSEDAServer.java Thu Dec 9 14:35:36 2004
@@ -18,6 +18,7 @@
import junit.framework.TestCase;
import org.apache.directory.seda.SEDAServer;
+import org.apache.directory.seda.mocks.MockProtocolProvider;
import org.apache.directory.seda.input.Firewall;
import org.apache.directory.seda.input.ReaderSource;
@@ -79,5 +80,14 @@
{
if (null != client) client.close();
}
+ }
+
+ public void testConnection() throws IOException
+ {
+ final SEDAServer server = SEDAServer.getServer();
+ server.addProtocolHandler( PORT, new MockProtocolProvider() );
+
+ // do something
+ server.removeProtocolHandler( PORT );
}
}