directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r169259 [3/5] - in /directory/network/branches/api_integration/src: examples/org/apache/mina/examples/echoserver/ examples/org/apache/mina/examples/httpserver/ examples/org/apache/mina/examples/netcat/ examples/org/apache/mina/examples/reverser/ examples/org/apache/mina/examples/tennis/ java/org/apache/mina/common/ java/org/apache/mina/filter/ java/org/apache/mina/filter/codec/ java/org/apache/mina/handler/ java/org/apache/mina/io/ java/org/apache/mina/io/datagram/ java/org/apache/mina/io/filter/ java/org/apache/mina/io/handler/ java/org/apache/mina/io/socket/ java/org/apache/mina/protocol/ java/org/apache/mina/protocol/codec/ java/org/apache/mina/protocol/filter/ java/org/apache/mina/protocol/handler/ java/org/apache/mina/protocol/io/ java/org/apache/mina/protocol/vmpipe/ java/org/apache/mina/registry/ java/org/apache/mina/transport/ java/org/apache/mina/transport/socket/ java/org/apache/mina/transport/socket/bio/ java/org/apache/mina/transport/socket/nio/ java/org/apache/mina/transport/vmpipe/ java/org/apache/mina/util/ test/org/apache/mina/examples/echoserver/ test/org/apache/mina/io/ test/org/apache/mina/io/datagram/ test/org/apache/mina/io/socket/ test/org/apache/mina/protocol/ test/org/apache/mina/protocol/codec/ test/org/apache/mina/util/
Date Mon, 09 May 2005 09:21:54 GMT
Added: directory/network/branches/api_integration/src/java/org/apache/mina/filter/ThreadPoolFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/filter/ThreadPoolFilter.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/filter/ThreadPoolFilter.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/filter/ThreadPoolFilter.java Mon May  9 02:21:50 2005
@@ -0,0 +1,123 @@
+/*
+ *   @(#) $Id$
+ *
+ *   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.mina.filter;
+
+import org.apache.mina.common.IdleStatus;
+import org.apache.mina.common.IoFilter;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.util.BaseThreadPool;
+import org.apache.mina.util.EventType;
+import org.apache.mina.util.ThreadPool;
+
+/**
+ * A Thread-pooling filter.  This filter forwards {@link IoHandler} events
+ * to its thread pool.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ * 
+ * @see ThreadPool
+ * @see BaseThreadPool
+ */
+public class ThreadPoolFilter extends BaseThreadPool implements ThreadPool, IoFilter
+{
+
+    /**
+     * Creates a new instanceof this filter with default thread pool settings.
+     * You'll have to invoke {@link #start()} method to start threads actually.
+     */
+    public ThreadPoolFilter()
+    {
+    }
+
+    public void sessionOpened( NextFilter nextFilter,
+                              IoSession session )
+    {
+        fireEvent( nextFilter, session, EventType.OPENED, null );
+    }
+
+    public void sessionClosed( NextFilter nextFilter,
+                              IoSession session )
+    {
+        fireEvent( nextFilter, session, EventType.CLOSED, null );
+    }
+
+    public void sessionIdle( NextFilter nextFilter,
+                            IoSession session, IdleStatus status )
+    {
+        fireEvent( nextFilter, session, EventType.IDLE, status );
+    }
+
+    public void exceptionCaught( NextFilter nextFilter,
+                                IoSession session, Throwable cause )
+    {
+        fireEvent( nextFilter, session, EventType.EXCEPTION, cause );
+    }
+
+    public void messageReceived( NextFilter nextFilter,
+                                IoSession session, Object message )
+    {
+        fireEvent( nextFilter, session, EventType.RECEIVED, message );
+    }
+
+    public void messageSent( NextFilter nextFilter,
+                            IoSession session, Object message )
+    {
+        fireEvent( nextFilter, session, EventType.SENT, message );
+    }
+
+    protected void processEvent( Object nextFilter0,
+                                 IoSession session0, EventType type,
+                                 Object data )
+    {
+        NextFilter nextFilter = ( NextFilter ) nextFilter0;
+        IoSession session = ( IoSession ) session0;
+
+        if( type == EventType.RECEIVED )
+        {
+            nextFilter.messageReceived( session, data );
+        }
+        else if( type == EventType.SENT )
+        {
+            nextFilter.messageSent( session, data );
+        }
+        else if( type == EventType.EXCEPTION )
+        {
+            nextFilter.exceptionCaught( session, ( Throwable ) data );
+        }
+        else if( type == EventType.IDLE )
+        {
+            nextFilter.sessionIdle( session, ( IdleStatus ) data );
+        }
+        else if( type == EventType.OPENED )
+        {
+            nextFilter.sessionOpened( session );
+        }
+        else if( type == EventType.CLOSED )
+        {
+            nextFilter.sessionClosed( session );
+        }
+    }
+
+    public void filterWrite( NextFilter nextFilter, IoSession session, Object message )
+    {
+        nextFilter.filterWrite( session, message );
+    }
+}
\ No newline at end of file

Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/filter/ThreadPoolFilter.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/CumulativeProtocolDecoder.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/CumulativeProtocolDecoder.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/CumulativeProtocolDecoder.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/CumulativeProtocolDecoder.java Mon May  9 02:21:50 2005
@@ -0,0 +1,132 @@
+/*
+ *   @(#) $Id$
+ *
+ *   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.mina.filter.codec;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+
+/**
+ * A {@link ProtocolDecoder} that cumulates the content of received
+ * buffers to a <em>cumulative buffer</em> to help users implement decoders.
+ * <p>
+ * If the received {@link ByteBuffer} is only a part of a message.
+ * decoders should cumulate received buffers to make a message complete or
+ * to postpone decoding until more buffers arrive.
+ * <p>
+ * Here is an example decoder that decodes a list of integers:
+ * <pre>
+ * public class IntegerDecoder extends CumulativeProtocolDecoder {
+ * 
+ *     public IntegerDecoder() {
+ *         super(4);
+ *     }
+ * 
+ *     protected boolean doDecode(IoSession session, ByteBuffer in,
+ *                                ProtocolDecoderOutput out) throws ProtocolViolationException {
+ *         if (in.remaining() < 4) {
+ *             return false; // Cumulate remainder to decode later.
+ *         }
+ *         
+ *         out.write(new Integer(in.getInt()));
+ * 
+ *         // Decoded one integer; CumulativeProtocolDecoder will call me again,
+ *         // so I can decode as many integers as possible.
+ *         return true;
+ *     }
+ * }
+ * </pre>
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public abstract class CumulativeProtocolDecoder implements ProtocolDecoder {
+    
+    /** Cumulation buffer */
+    private ByteBuffer buf;
+    
+    /**
+     * Creates a new instance with the specified default capacity of
+     * cumulative buffer.  Please note that the capacity increases
+     * automatically.
+     */
+    protected CumulativeProtocolDecoder( int defaultCapacity )
+    {
+        buf = ByteBuffer.allocate( defaultCapacity );
+        buf.setAutoExpand( true );
+    }
+    
+    /**
+     * Cumulates content of <tt>in</tt> into internal buffer and forwards
+     * decoding request to {@link #doDecode(IoSession, ByteBuffer, ProtocolDecoderOutput)}.
+     * <tt>doDecode()</tt> is invoked repeatedly until it returns <tt>false</tt>
+     * and the cumulative buffer is compacted after decoding ends.
+     * 
+     * @throws IllegalStateException if your <tt>doDecode()</tt> returned
+     *                               <tt>true</tt> not consuming the cumulative buffer.
+     */
+    public void decode( IoSession session, ByteBuffer in,
+                        ProtocolDecoderOutput out ) throws ProtocolViolationException
+    {
+        if( session.getTransportType().isStateless() )
+        {
+            throw new IllegalStateException(
+                    "This decoder doesn't work for stateless transport types." );
+        }
+
+        ByteBuffer buf = this.buf;
+        buf.put( in );
+        buf.flip();
+
+        try
+        {
+            for( ;; )
+            {
+                int oldPos = buf.position();
+                if( !doDecode( session, buf, out ) )
+                {
+                    break;
+                }
+                
+                if( buf.position() == oldPos )
+                {
+                    throw new IllegalStateException(
+                            "doDecode() can't return true when buffer is not consumed." );
+                }
+            }
+        }
+        finally
+        {
+            buf.compact();
+        }
+    }
+    
+    /**
+     * Implement this method to consume the specified cumulative buffer and
+     * decode its content into message(s). 
+     *  
+     * @param in the cumulative buffer
+     * @return <tt>true</tt> if and only if there's more to decode in the buffer
+     *         and you want to have <tt>doDecode</tt> method invoked again.
+     *         Return <tt>false</tt> if remaining data is not enough to decode,
+     *         then this method will be invoked again when more data is cumulated.
+     * @throws ProtocolViolationException if cannot decode <tt>in</tt>.
+     */
+    protected abstract boolean doDecode( IoSession session, ByteBuffer in,
+                                         ProtocolDecoderOutput out ) throws ProtocolViolationException;
+}

Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/CumulativeProtocolDecoder.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/DemuxingProtocolCodecFactory.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/DemuxingProtocolCodecFactory.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/DemuxingProtocolCodecFactory.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/DemuxingProtocolCodecFactory.java Mon May  9 02:21:50 2005
@@ -0,0 +1,219 @@
+/*
+ *   @(#) $Id$
+ *
+ *   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.mina.filter.codec;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+
+/**
+ * A composite {@link ProtocolCodecFactory} that consists of multiple
+ * {@link MessageEncoder}s and {@link MessageDecoder}s.
+ * {@link ProtocolEncoder} and {@link ProtocolDecoder} this factory
+ * returns demultiplex incoming messages and buffers to
+ * appropriate {@link MessageEncoder}s and {@link MessageDecoder}s. 
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ * 
+ * @see MessageEncoder
+ * @see MessageDecoder
+ */
+public class DemuxingProtocolCodecFactory implements ProtocolCodecFactory {
+
+    private MessageDecoder[] decoders = new MessageDecoder[0];
+    private final Map encoders = new HashMap();
+    
+    private final ProtocolEncoder protocolEncoder = new ProtocolEncoderImpl();
+
+    private final ProtocolDecoder protocolDecoder = new ProtocolDecoderImpl();
+    
+    public DemuxingProtocolCodecFactory()
+    {
+    }
+    
+    public void register( MessageEncoder encoder )
+    {
+        Iterator it = encoder.getMessageTypes().iterator();
+        while( it.hasNext() )
+        {
+            Class type = (Class) it.next();
+            encoders.put( type, encoder );
+        }
+    }
+    
+    public void register( MessageDecoder decoder )
+    {
+        if( decoder == null )
+        {
+            throw new NullPointerException( "decoder" );
+        }
+        MessageDecoder[] decoders = this.decoders;
+        MessageDecoder[] newDecoders = new MessageDecoder[ decoders.length + 1 ];
+        System.arraycopy( decoders, 0, newDecoders, 0, decoders.length );
+        newDecoders[ decoders.length ] = decoder;
+        this.decoders = newDecoders;
+    }
+    
+    public ProtocolEncoder newEncoder() {
+        return protocolEncoder;
+    }
+
+    public ProtocolDecoder newDecoder() {
+        return protocolDecoder;
+    }
+    
+    private class ProtocolEncoderImpl implements ProtocolEncoder
+    {
+        public void encode( IoSession session, Object message,
+                            ProtocolEncoderOutput out ) throws ProtocolViolationException
+        {
+            Class type = message.getClass();
+            MessageEncoder encoder = findEncoder( type );
+            if( encoder == null )
+            {
+                throw new ProtocolViolationException( "Unexpected message type: " + type );
+            }
+            
+            encoder.encode( session, message, out );
+        }
+        
+        private MessageEncoder findEncoder( Class type )
+        {
+            MessageEncoder encoder = ( MessageEncoder ) encoders.get( type );
+            if( encoder == null )
+            {
+                encoder = findEncoder( type, new HashSet() );
+            }
+
+            return encoder;
+        }
+
+        private MessageEncoder findEncoder( Class type, Set triedClasses )
+        {
+            MessageEncoder encoder;
+
+            if( triedClasses.contains( type ) )
+                return null;
+            triedClasses.add( type );
+
+            encoder = ( MessageEncoder ) encoders.get( type );
+            if( encoder == null )
+            {
+                encoder = findEncoder( type, triedClasses );
+                if( encoder != null )
+                    return encoder;
+
+                Class[] interfaces = type.getInterfaces();
+                for( int i = 0; i < interfaces.length; i ++ )
+                {
+                    encoder = findEncoder( interfaces[ i ], triedClasses );
+                    if( encoder != null )
+                        return encoder;
+                }
+
+                return null;
+            }
+            else
+                return encoder;
+        }
+    }
+    
+    private class ProtocolDecoderImpl extends CumulativeProtocolDecoder
+    {
+        private MessageDecoder currentDecoder;
+
+        protected ProtocolDecoderImpl()
+        {
+            super( 16 );
+        }
+
+        protected boolean doDecode( IoSession session, ByteBuffer in,
+                                    ProtocolDecoderOutput out) throws ProtocolViolationException
+        {
+            if( currentDecoder == null )
+            {
+                MessageDecoder[] decoders = DemuxingProtocolCodecFactory.this.decoders;
+                int undecodables = 0;
+                for( int i = decoders.length - 1; i >= 0; i -- ) 
+                {
+                    MessageDecoder decoder = decoders[i];
+                    int limit = in.limit();
+                    in.position( 0 );
+                    MessageDecoderResult result = decoder.decodable( session, in );
+                    in.position( 0 );
+                    in.limit( limit );
+                    
+                    if( result == MessageDecoder.OK )
+                    {
+                        currentDecoder = decoder;
+                        break;
+                    }
+                    else if( result == MessageDecoder.NOT_OK )
+                    {
+                        undecodables ++;
+                    }
+                    else if( result != MessageDecoder.NEED_DATA )
+                    {
+                        throw new IllegalStateException( "Unexpected decode result (see your decodable()): " + result );
+                    }
+                }
+                
+                if( undecodables == decoders.length )
+                {
+                    // Throw an exception if all decoders cannot decode data.
+                    in.position( in.limit() ); // Skip data
+                    throw new ProtocolViolationException(
+                            "No appropriate message decoder: " + in.getHexDump() );
+                }
+                
+                if( currentDecoder == null )
+                {
+                    // Decoder is not determined yet (i.e. we need more data)
+                    return false;
+                }
+            }
+            
+            MessageDecoderResult result = currentDecoder.decode( session, in, out );
+            if( result == MessageDecoder.OK )
+            {
+                currentDecoder = null;
+                return true;
+            }
+            else if( result == MessageDecoder.NEED_DATA )
+            {
+                return false;
+            }
+            else if( result == MessageDecoder.NOT_OK )
+            {
+                throw new ProtocolViolationException( "Message decoder returned NOT_OK." );
+            }
+            else
+            {
+                throw new IllegalStateException( "Unexpected decode result (see your decode()): " + result );
+            }
+        }
+    }
+}

Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/DemuxingProtocolCodecFactory.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/MessageDecoder.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/MessageDecoder.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/MessageDecoder.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/MessageDecoder.java Mon May  9 02:21:50 2005
@@ -0,0 +1,81 @@
+/*
+ *   @(#) $Id$
+ *
+ *   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.mina.filter.codec;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+
+/**
+ * Decodes specific messages.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ * 
+ * @see DemuxingProtocolCodecFactory
+ */
+public interface MessageDecoder {
+    /**
+     * Represents a result from {@link #decodable(IoSession, ByteBuffer)} and
+     * {@link #decode(IoSession, ByteBuffer, ProtocolDecoderOutput)}.  Please
+     * refer to each method's documentation for detailed explanation.
+     */
+    static MessageDecoderResult OK = MessageDecoderResult.OK;
+
+    /**
+     * Represents a result from {@link #decodable(IoSession, ByteBuffer)} and
+     * {@link #decode(IoSession, ByteBuffer, ProtocolDecoderOutput)}.  Please
+     * refer to each method's documentation for detailed explanation.
+     */
+    static MessageDecoderResult NEED_DATA = MessageDecoderResult.NEED_DATA;
+
+    /**
+     * Represents a result from {@link #decodable(IoSession, ByteBuffer)} and
+     * {@link #decode(IoSession, ByteBuffer, ProtocolDecoderOutput)}.  Please
+     * refer to each method's documentation for detailed explanation.
+     */
+    static MessageDecoderResult NOT_OK = MessageDecoderResult.NOT_OK;
+    
+    /**
+     * Checks the specified buffer is decodable by this decoder.
+     * 
+     * @return {@link #OK} if this decoder can decode the specified buffer.
+     *         {@link #NOT_OK} if this decoder cannot decode the specified buffer.
+     *         {@link #NEED_DATA} if more data is required to determine if the
+     *         specified buffer is decodable ({@link #OK}) or not decodable
+     *         {@link #NOT_OK}.
+     */
+    MessageDecoderResult decodable( IoSession session, ByteBuffer in );
+    
+    /**
+     * Decodes binary or protocol-specific content into higher-level message objects.
+     * MINA invokes {@link #decode(IoSession, ByteBuffer, ProtocolDecoderOutput)}
+     * method with read data, and then the decoder implementation puts decoded
+     * messages into {@link ProtocolDecoderOutput}.
+     * 
+     * @return {@link #OK} if you finished decoding messages successfully.
+     *         {@link #NEED_DATA} if you need more data to finish decoding current message.
+     *         {@link #NOT_OK} if you cannot decode current message due to protocol specification violation.
+     *         
+     * @throws ProtocolViolationException if the read data violated protocol
+     *                                    specification 
+     */
+    MessageDecoderResult decode( IoSession session, ByteBuffer in,
+                         ProtocolDecoderOutput out ) throws ProtocolViolationException;
+}

Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/MessageDecoder.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/MessageDecoderResult.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/MessageDecoderResult.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/MessageDecoderResult.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/MessageDecoderResult.java Mon May  9 02:21:50 2005
@@ -0,0 +1,66 @@
+/*
+ *   @(#) $Id$
+ *
+ *   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.mina.filter.codec;
+
+import org.apache.mina.common.ByteBuffer;
+
+/**
+ * Represents results from {@link MessageDecoder}.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ * 
+ * @see MessageDecoder
+ */
+public class MessageDecoderResult
+{
+    /**
+     * Represents a result from {@link MessageDecoder#decodable(IoSession, ByteBuffer)}
+     * and {@link MessageDecoder#decode(IoSession, ByteBuffer, ProtocolDecoderOutput)}.
+     * Please refer to each method's documentation for detailed explanation.
+     */
+    public static MessageDecoderResult OK = new MessageDecoderResult( "OK" );
+
+    /**
+     * Represents a result from {@link MessageDecoder#decodable(IoSession, ByteBuffer)}
+     * and {@link MessageDecoder#decode(IoSession, ByteBuffer, ProtocolDecoderOutput)}.
+     * Please refer to each method's documentation for detailed explanation.
+     */
+    public static MessageDecoderResult NEED_DATA = new MessageDecoderResult( "NEED_DATA" );
+
+    /**
+     * Represents a result from {@link MessageDecoder#decodable(IoSession, ByteBuffer)}
+     * and {@link MessageDecoder#decode(IoSession, ByteBuffer, ProtocolDecoderOutput)}.
+     * Please refer to each method's documentation for detailed explanation.
+     */
+    public static MessageDecoderResult NOT_OK = new MessageDecoderResult( "NOT_OK" );
+
+    private final String name;
+
+    private MessageDecoderResult( String name )
+    {
+        this.name = name;
+    }
+    
+    public String toString()
+    {
+        return name;
+    }
+}
\ No newline at end of file

Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/MessageDecoderResult.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/MessageEncoder.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/MessageEncoder.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/MessageEncoder.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/MessageEncoder.java Mon May  9 02:21:50 2005
@@ -0,0 +1,38 @@
+/*
+ *   @(#) $Id$
+ *
+ *   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.mina.filter.codec;
+
+import java.util.Set;
+
+/**
+ * Encodes messages of specific types specified by {@link #getMessageTypes()}.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ * 
+ * @see DemuxingProtocolCodecFactory
+ */
+public interface MessageEncoder extends ProtocolEncoder
+{  
+    /**
+     * Returns the set of message classes this encoder can encode.
+     */
+    Set getMessageTypes();
+}

Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/MessageEncoder.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolCodecFactory.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolCodecFactory.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolCodecFactory.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolCodecFactory.java Mon May  9 02:21:50 2005
@@ -0,0 +1,45 @@
+/*
+ *   @(#) $Id$
+ *
+ *   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.mina.filter.codec;
+
+/**
+ * Provides {@link ProtocolEncoder} and {@link ProtocolDecoder} which translates
+ * binary or protocol specific data into message object and vice versa.
+ * <p>
+ * Please refer to
+ * <a href="../../../../../xref-examples/org/apache/mina/examples/reverser/ReverseProtocolProvider.html"><code>ReverserProtocolProvider</code></a>
+ * example.
+ *  
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public interface ProtocolCodecFactory
+{
+    /**
+     * Creates a new instance of {@link ProtocolEncoder} which encodes message
+     * objects into binary or protocol-specific data.
+     */
+    ProtocolEncoder newEncoder();
+
+    /**
+     * Creates a new instance of {@link ProtocolDecoder} which decodes binary or
+     * protocol-specific data into message objects.
+     */
+    ProtocolDecoder newDecoder();
+}
\ No newline at end of file

Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolCodecFactory.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java Mon May  9 02:21:50 2005
@@ -0,0 +1,129 @@
+package org.apache.mina.filter.codec;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoFilterAdapter;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.util.Queue;
+
+public class ProtocolCodecFilter extends IoFilterAdapter
+{
+    public static final String ENCODER = ProtocolCodecFilter.class.getName() + ".encoder";
+    public static final String DECODER = ProtocolCodecFilter.class.getName() + ".decoder";
+    public static final String ENCODER_OUT = ProtocolCodecFilter.class.getName() + ".encoderOutput";
+    public static final String DECODER_OUT = ProtocolCodecFilter.class.getName() + ".decoderOutput";
+    
+    private final ProtocolCodecFactory factory;
+    
+    public ProtocolCodecFilter( ProtocolCodecFactory factory )
+    {
+        if( factory == null )
+        {
+            throw new NullPointerException( "factory" );
+        }
+        this.factory = factory;
+    }
+    
+    public void messageReceived( NextFilter nextFilter, IoSession session, Object message ) throws Exception
+    {
+        ByteBuffer in = ( ByteBuffer ) message;
+        ProtocolDecoder decoder = getDecoder( session );
+        SimpleProtocolDecoderOutput decoderOut = getDecoderOut( session );
+        
+        try
+        {
+            synchronized( decoder )
+            {
+                decoder.decode( session, in, decoderOut );
+            }
+
+            Queue queue = decoderOut.getMessageQueue();
+            synchronized( queue )
+            {
+                if( !queue.isEmpty() )
+                {
+                    do
+                    {
+                        nextFilter.messageReceived( session, queue.pop() );
+                    }
+                    while( !queue.isEmpty() );
+                }
+            }
+        }
+        catch( ProtocolViolationException pve )
+        {
+            pve.setBuffer( in );
+            throw pve;
+        }
+    }
+
+    public void messageSent( NextFilter nextFilter, IoSession session, Object message ) throws Exception
+    {
+        // FIXME message is a bytebuffer here
+        super.messageSent(nextFilter, session, message);
+    }
+    
+    public void filterWrite( NextFilter nextFilter, IoSession session, Object message ) throws Exception
+    {
+        ProtocolEncoder encoder = getEncoder( session );
+        if( message == null )
+        {
+            throw new NullPointerException( "message" );
+        }
+
+        SimpleProtocolEncoderOutput encoderOut = getEncoderOut( session );
+        Queue queue = encoderOut.getBufferQueue();
+        encoder.encode( session, message, encoderOut );
+        for( ;; )
+        {
+            ByteBuffer buf = ( ByteBuffer ) queue.pop();
+            if( buf == null )
+                break;
+            // FIXME messageSent issues
+            nextFilter.filterWrite( session, buf );
+        }
+    }
+    
+    private ProtocolEncoder getEncoder( IoSession session )
+    {
+        ProtocolEncoder encoder = ( ProtocolEncoder ) session.getAttribute( ENCODER );
+        if( encoder == null )
+        {
+            encoder = factory.newEncoder();
+            session.setAttribute( ENCODER, encoder );
+        }
+        return encoder;
+    }
+    
+    private SimpleProtocolEncoderOutput getEncoderOut( IoSession session )
+    {
+        SimpleProtocolEncoderOutput out = ( SimpleProtocolEncoderOutput ) session.getAttribute( ENCODER_OUT );
+        if( out == null )
+        {
+            out = new SimpleProtocolEncoderOutput();
+            session.setAttribute( ENCODER_OUT, out );
+        }
+        return out;
+    }
+    
+    private ProtocolDecoder getDecoder( IoSession session )
+    {
+        ProtocolDecoder decoder = ( ProtocolDecoder ) session.getAttribute( DECODER );
+        if( decoder == null )
+        {
+            decoder = factory.newDecoder();
+            session.setAttribute( DECODER, decoder );
+        }
+        return decoder;
+    }
+    
+    private SimpleProtocolDecoderOutput getDecoderOut( IoSession session )
+    {
+        SimpleProtocolDecoderOutput out = ( SimpleProtocolDecoderOutput ) session.getAttribute( DECODER_OUT );
+        if( out == null )
+        {
+            out = new SimpleProtocolDecoderOutput();
+            session.setAttribute( DECODER_OUT, out );
+        }
+        return out;
+    }
+}

Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolDecoder.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolDecoder.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolDecoder.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolDecoder.java Mon May  9 02:21:50 2005
@@ -0,0 +1,51 @@
+/*
+ *   @(#) $Id$
+ *
+ *   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.mina.filter.codec;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+
+/**
+ * Decodes binary or protocol-specific data into higher-level message objects.
+ * MINA invokes {@link #decode(IoSession, ByteBuffer, ProtocolDecoderOutput)}
+ * method with read data, and then the decoder implementation puts decoded
+ * messages into {@link ProtocolDecoderOutput} by calling
+ * {@link ProtocolDecoderOutput#write(Object)}.
+ * <p>
+ * Please refer to
+ * <a href="../../../../../xref-examples/org/apache/mina/examples/reverser/TextLineDecoder.html"><code>TextLineDecoder</code></a>
+ * example. 
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public interface ProtocolDecoder
+{
+    /**
+     * Decodes binary or protocol-specific content into higher-level message objects.
+     * MINA invokes {@link #decode(IoSession, ByteBuffer, ProtocolDecoderOutput)}
+     * method with read data, and then the decoder implementation puts decoded
+     * messages into {@link ProtocolDecoderOutput}.
+     * 
+     * @throws ProtocolViolationException if the read data violated protocol
+     *                                    specification 
+     */
+    void decode( IoSession session, ByteBuffer in,
+                 ProtocolDecoderOutput out ) throws ProtocolViolationException;
+}
\ No newline at end of file

Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolDecoder.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolDecoderOutput.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolDecoderOutput.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolDecoderOutput.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolDecoderOutput.java Mon May  9 02:21:50 2005
@@ -0,0 +1,39 @@
+/*
+ *   @(#) $Id$
+ *
+ *   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.mina.filter.codec;
+
+/**
+ * Callback for {@link ProtocolDecoder} to generate decoded messages.
+ * {@link ProtocolDecoder} must call {@link #write(Object)} for each decoded
+ * messages.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public interface ProtocolDecoderOutput
+{
+    /**
+     * Callback for {@link ProtocolDecoder} to generate decoded messages.
+     * {@link ProtocolDecoder} must call {@link #write(Object)} for each
+     * decoded messages.
+     * 
+     * @param message the decoded message
+     */
+    void write( Object message );
+}
\ No newline at end of file

Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolDecoderOutput.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolEncoder.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolEncoder.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolEncoder.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolEncoder.java Mon May  9 02:21:50 2005
@@ -0,0 +1,54 @@
+/*
+ *   @(#) $Id$
+ *
+ *   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.mina.filter.codec;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+
+/**
+ * Encodes higher-level message objects into binary or protocol-specific data.
+ * MINA invokes {@link #encode(IoSession, Object, ProtocolEncoderOutput)}
+ * method with message which is popped from the session write queue, and then
+ * the encoder implementation puts encoded {@link ByteBuffer}s into
+ * {@link ProtocolEncoderOutput} by calling
+ * {@link ProtocolEncoderOutput#write(ByteBuffer)}.
+ * <p>
+ * Please refer to
+ * <a href="../../../../../xref-examples/org/apache/mina/examples/reverser/TextLineEncoder.html"><code>TextLineEncoder</code></a>
+ * example. 
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public interface ProtocolEncoder
+{
+
+    /**
+     * Encodes higher-level message objects into binary or protocol-specific data.
+     * MINA invokes {@link #encode(IoSession, Object, ProtocolEncoderOutput)}
+     * method with message which is popped from the session write queue, and then
+     * the encoder implementation puts encoded {@link ByteBuffer}s into
+     * {@link ProtocolEncoderOutput}.
+     * 
+     * @throws ProtocolViolationException if the message violated protocol
+     *                                    specification
+     */
+    void encode( IoSession session, Object message,
+                 ProtocolEncoderOutput out ) throws ProtocolViolationException;
+}
\ No newline at end of file

Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolEncoder.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolEncoderOutput.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolEncoderOutput.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolEncoderOutput.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolEncoderOutput.java Mon May  9 02:21:50 2005
@@ -0,0 +1,49 @@
+/*
+ *   @(#) $Id$
+ *
+ *   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.mina.filter.codec;
+
+import org.apache.mina.common.ByteBuffer;
+
+/**
+ * Callback for {@link ProtocolEncoder} to generate encoded {@link ByteBuffer}s.
+ * {@link ProtocolEncoder} must call {@link #write(ByteBuffer)} for each decoded
+ * messages.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public interface ProtocolEncoderOutput
+{
+    /**
+     * Callback for {@link ProtocolEncoder} to generate encoded
+     * {@link ByteBuffer}s. {@link ProtocolEncoder} must call
+     * {@link #write(ByteBuffer)} for each decoded messages.
+     * 
+     * @param buf the buffer which contains encoded data
+     */
+    void write( ByteBuffer buf );
+    
+    /**
+     * Merges all buffers you wrote via {@link #write(ByteBuffer)} into
+     * one {@link ByteBuffer} and replaces the old fragmented ones with it.
+     * This method is useful when you want to control the way MINA generates
+     * network packets.
+     */
+    void mergeAll();
+}
\ No newline at end of file

Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolEncoderOutput.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolViolationException.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolViolationException.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolViolationException.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolViolationException.java Mon May  9 02:21:50 2005
@@ -0,0 +1,108 @@
+/*
+ *   @(#) $Id$
+ *
+ *   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.mina.filter.codec;
+
+import org.apache.mina.common.ByteBuffer;
+
+/**
+ * An exception that is thrown when {@link ProtocolEncoder} cannot understand or
+ * failed to validate the specified message, or when {@link ProtocolDecoder}
+ * cannot understand or failed to validate the specified {@link ByteBuffer}
+ * content.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public class ProtocolViolationException extends Exception
+{
+    private static final long serialVersionUID = 3545799879533408565L;
+
+	private ByteBuffer buffer;
+
+    /**
+     * Constructs a new instance.
+     */
+    public ProtocolViolationException()
+    {
+    }
+
+    /**
+     * Constructs a new instance with the specified message.
+     */
+    public ProtocolViolationException( String message )
+    {
+        super( message );
+    }
+
+    /**
+     * Constructs a new instance with the specified cause.
+     */
+    public ProtocolViolationException( Throwable cause )
+    {
+        super( cause );
+    }
+
+    /**
+     * Constructs a new instance with the specified message and the specified
+     * cause.
+     */
+    public ProtocolViolationException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+
+    /**
+     * Returns the message and the hexdump of the unknown part.
+     */
+    public String getMessage()
+    {
+        String message = super.getMessage();
+
+        if( message == null )
+        {
+            message = "";
+        }
+
+        if( buffer != null )
+        {
+            return message + ( ( message.length() > 0 ) ? " " : "" )
+                   + "(Hexdump: " + buffer.getHexDump() + ')';
+        }
+        else
+        {
+            return message;
+        }
+    }
+
+    /**
+     * Returns unknown message part.
+     */
+    public ByteBuffer getBuffer()
+    {
+        return buffer;
+    }
+
+    /**
+     * Sets unknown message part.
+     */
+    public void setBuffer( ByteBuffer buffer )
+    {
+        this.buffer = buffer;
+    }
+}
\ No newline at end of file

Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolViolationException.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/SimpleProtocolDecoderOutput.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/SimpleProtocolDecoderOutput.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/SimpleProtocolDecoderOutput.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/SimpleProtocolDecoderOutput.java Mon May  9 02:21:50 2005
@@ -0,0 +1,33 @@
+/**
+ * 
+ */
+package org.apache.mina.filter.codec;
+
+import org.apache.mina.util.Queue;
+
+/**
+ * A {@link ProtocolDecoderOutput} based on queue.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ *
+ */
+public class SimpleProtocolDecoderOutput implements ProtocolDecoderOutput
+{
+    private final Queue messageQueue = new Queue();
+    
+    public SimpleProtocolDecoderOutput()
+    {
+    }
+    
+    public Queue getMessageQueue()
+    {
+        return messageQueue;
+    }
+    
+    public void write( Object message )
+    {
+        messageQueue.push( message );
+    }
+}
\ No newline at end of file

Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/SimpleProtocolDecoderOutput.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/SimpleProtocolEncoderOutput.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/SimpleProtocolEncoderOutput.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/SimpleProtocolEncoderOutput.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/SimpleProtocolEncoderOutput.java Mon May  9 02:21:50 2005
@@ -0,0 +1,72 @@
+/**
+ * 
+ */
+package org.apache.mina.filter.codec;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.util.Queue;
+
+/**
+ * A {@link ProtocolEncoderOutput} based on queue.
+ *
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public class SimpleProtocolEncoderOutput implements ProtocolEncoderOutput
+{
+
+    private final Queue bufferQueue = new Queue();
+    
+    public SimpleProtocolEncoderOutput()
+    {
+    }
+    
+    public Queue getBufferQueue()
+    {
+        return bufferQueue;
+    }
+    
+    public void write( ByteBuffer buf )
+    {
+        bufferQueue.push( buf );
+    }
+    
+    public void mergeAll()
+    {
+        int sum = 0;
+        final int size = bufferQueue.size();
+        
+        if( size < 2 )
+        {
+            // no need to merge!
+            return;
+        }
+        
+        // Get the size of merged BB
+        for( int i = size - 1; i >= 0; i -- )
+        {
+            sum += ( ( ByteBuffer ) bufferQueue.get( i ) ).remaining();
+        }
+        
+        // Allocate a new BB that will contain all fragments
+        ByteBuffer newBuf = ByteBuffer.allocate( sum );
+        
+        // and merge all.
+        for( ;; )
+        {
+            ByteBuffer buf = ( ByteBuffer ) bufferQueue.pop();
+            if( buf == null )
+            {
+                break;
+            }
+    
+            newBuf.put( buf );
+            buf.release();
+        }
+        
+        // Push the new buffer finally.
+        newBuf.flip();
+        bufferQueue.push(newBuf);
+    }
+}
\ No newline at end of file

Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/SimpleProtocolEncoderOutput.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/branches/api_integration/src/java/org/apache/mina/handler/DemuxingIoHandler.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/handler/DemuxingIoHandler.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/handler/DemuxingIoHandler.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/handler/DemuxingIoHandler.java Mon May  9 02:21:50 2005
@@ -0,0 +1,117 @@
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.handler;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoSession;
+
+/**
+ * A {@link IoHandler} that demuxes <code>messageReceived</code> events
+ * to the appropriate {@link MessageHandler}.
+ * 
+ * You can freely register and deregister {@link MessageHandler}s using
+ * {@link #registerMessageType(Class, MessageHandler)} and
+ * {@link #deregisterMessageType(Class)}.
+ * 
+ * @author The Apache Directory Project
+ * @version $Rev$, $Date$
+ */
+public abstract class DemuxingIoHandler implements IoHandler
+{
+    private final Map type2handler = new HashMap();
+
+    /**
+     * Creates a new instance with no registered {@link MessageHandler}s.
+     */
+    protected DemuxingIoHandler()
+    {
+    }
+
+    /**
+     * Registers a {@link MessageHandler} that receives the messages of
+     * the specified <code>type</code>.
+     */
+    protected void registerMessageType( Class type, MessageHandler handler )
+    {
+        synchronized( type2handler )
+        {
+            type2handler.put( type, handler );
+        }
+    }
+
+    /**
+     * Deregisters a {@link MessageHandler} that receives the messages of
+     * the specified <code>type</code>.
+     */
+    protected void deregisterMessageType( Class clazz )
+    {
+        synchronized( type2handler )
+        {
+            type2handler.remove( clazz );
+        }
+    }
+
+    /**
+     * Forwards the received events into the appropriate {@link MessageHandler}
+     * which is registered by {@link #registerMessageType(Class, MessageHandler)}.
+     */
+    public void messageReceived( IoSession session, Object message )
+    {
+        MessageHandler handler = findHandler( message.getClass() );
+        if( handler != null )
+        {
+            handler.messageReceived( session, message );
+        }
+        else
+        {
+            throw new UnknownMessageTypeException(
+                    "No message handler found for message: " + message );
+        }
+    }
+
+    private MessageHandler findHandler( Class type )
+    {
+        MessageHandler handler = ( MessageHandler ) type2handler.get( type );
+        if( handler == null )
+        {
+            handler = findHandler( type, new HashSet() );
+        }
+
+        return handler;
+    }
+
+    private MessageHandler findHandler( Class type, Set triedClasses )
+    {
+        MessageHandler handler;
+
+        if( triedClasses.contains( type ) )
+            return null;
+        triedClasses.add( type );
+
+        handler = ( MessageHandler ) type2handler.get( type );
+        if( handler == null )
+        {
+            handler = findHandler( type, triedClasses );
+            if( handler != null )
+                return handler;
+
+            Class[] interfaces = type.getInterfaces();
+            for( int i = 0; i < interfaces.length; i ++ )
+            {
+                handler = findHandler( interfaces[ i ], triedClasses );
+                if( handler != null )
+                    return handler;
+            }
+
+            return null;
+        }
+        else
+            return handler;
+    }
+}

Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/handler/DemuxingIoHandler.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/branches/api_integration/src/java/org/apache/mina/handler/MessageHandler.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/handler/MessageHandler.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/handler/MessageHandler.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/handler/MessageHandler.java Mon May  9 02:21:50 2005
@@ -0,0 +1,50 @@
+/*
+ *   @(#) $Id$
+ *
+ *   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.mina.handler;
+
+import org.apache.mina.common.IoSession;
+
+/**
+ * A handler interface that {@link DemuxingIoHandler} forwards
+ * <code>messageReceived</code> events to.  You have to register your
+ * handler with the type of message you want to get notified using
+ * {@link DemuxingIoHandler#registerMessageType(Class, MessageHandler)}.
+ * 
+ * @author The Apache Directory Project
+ * @version $Rev$, $Date$
+ */
+public interface MessageHandler
+{
+    /**
+     * A {@link MessageHandler} that does nothing.  This is usefule when
+     * you want to ignore messages of the specific type silently.
+     */
+    static MessageHandler NOOP = new MessageHandler()
+    {
+        public void messageReceived( IoSession session, Object message )
+        {
+        }
+    };
+    
+    /**
+     * Invoked when the specific type of message is received from the
+     * specified <code>session</code>.
+     */
+    void messageReceived( IoSession session, Object message );
+}
\ No newline at end of file

Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/handler/MessageHandler.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/branches/api_integration/src/java/org/apache/mina/handler/StreamIoHandler.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/handler/StreamIoHandler.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/handler/StreamIoHandler.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/handler/StreamIoHandler.java Mon May  9 02:21:50 2005
@@ -0,0 +1,292 @@
+package org.apache.mina.handler;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PipedOutputStream;
+import java.net.SocketTimeoutException;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IdleStatus;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoHandlerAdapter;
+import org.apache.mina.common.IoSession;
+
+/**
+ * A {@link IoHandler} that adapts asynchronous MINA events to stream I/O.
+ * <p>
+ * Please extend this class and implement
+ * {@link #processStreamIo(IoSession, InputStream, OutputStream)} to
+ * execute your stream I/O logic; <b>please note that you must forward
+ * the process request to other thread or thread pool.</b>
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public abstract class StreamIoHandler extends IoHandlerAdapter
+{
+    private static final String KEY_IN = "BlockingIoHandler.in";
+    private static final String KEY_OUT = "BlockingIoHandler.out";
+    private static final String KEY_STARTED = "BlockingIoHandler.started";
+    
+    private int readTimeout;
+    
+    private int writeTimeout;
+    
+    protected StreamIoHandler()
+    {
+    }
+    
+    /**
+     * Implement this method to execute your stream I/O logic;
+     * <b>please note that you must forward the process request to other
+     * thread or thread pool.</b>
+     */
+    protected abstract void processStreamIo( IoSession session,
+                                             InputStream in, OutputStream out );
+    
+    /**
+     * Returns read timeout in seconds.
+     * The default value is <tt>0</tt> (disabled).
+     */
+    public int getReadTimeout()
+    {
+        return readTimeout;
+    }
+    
+    /**
+     * Sets read timeout in seconds.
+     * The default value is <tt>0</tt> (disabled).
+     */
+    public void setReadTimeout( int readTimeout )
+    {
+        this.readTimeout = readTimeout;
+    }
+    
+    /**
+     * Returns write timeout in seconds.
+     * The default value is <tt>0</tt> (disabled).
+     */
+    public int getWriteTimeout()
+    {
+        return writeTimeout;
+    }
+    
+    /**
+     * Sets write timeout in seconds.
+     * The default value is <tt>0</tt> (disabled).
+     */
+    public void setWriteTimeout( int writeTimeout )
+    {
+        this.writeTimeout = writeTimeout;
+    }
+
+    /**
+     * Initializes streams and timeout settings.
+     */
+    public void sessionOpened( IoSession session )
+    {
+        // Set timeouts
+        session.getConfig().setWriteTimeout( writeTimeout );
+        session.getConfig().setIdleTime( IdleStatus.READER_IDLE, readTimeout );
+
+        // Create streams
+        PipedOutputStream out = new PipedOutputStream();
+        session.setAttribute( KEY_OUT, out );
+        try
+        {
+            session.setAttribute( KEY_IN, new PipedInputStream( out ) );
+        }
+        catch( IOException e )
+        {
+            throw new StreamIoException( e );
+        }
+    }
+    
+    /**
+     * Closes input stream.
+     */
+    public void sessionClosed( IoSession session )
+    {
+        final PipedOutputStream out = ( PipedOutputStream ) session.getAttribute( KEY_OUT );
+        try {
+            out.close();
+        }
+        catch( IOException e )
+        {
+            throw new StreamIoException( e );
+        }
+    }
+
+    /**
+     * Forwards read data to input stream.
+     */
+    public void messageReceived( IoSession session, Object message )
+    {
+        ByteBuffer buf = ( ByteBuffer ) message;
+        final PipedInputStream in = ( PipedInputStream ) session.getAttribute( KEY_IN );
+        final PipedOutputStream out = ( PipedOutputStream ) session.getAttribute( KEY_OUT );
+        
+        java.nio.ByteBuffer nioBuf = buf.buf();
+        int offset = nioBuf.position();
+        int length = nioBuf.limit() - offset;
+        if( !nioBuf.hasArray() )
+        {
+            ByteBuffer heapBuf = ByteBuffer.allocate( length, false );
+            heapBuf.put( buf );
+            heapBuf.flip();
+            nioBuf = heapBuf.buf();
+            offset = 0;
+        }
+        
+        try
+        {
+            out.write( nioBuf.array(), offset, length );
+        }
+        catch( IOException e )
+        {
+            throw new StreamIoException( e );
+        }
+        finally
+        {
+            beginService( session, in );
+        }
+    }
+
+    /**
+     * Forwards caught exceptions to input stream.
+     */
+    public void exceptionCaught( IoSession session, Throwable cause )
+    {
+        final PipedInputStream in = ( PipedInputStream ) session.getAttribute( KEY_IN );
+        
+        IOException e = null;
+        if( cause instanceof StreamIoException )
+        {
+            e = ( IOException ) cause.getCause();
+        }
+        else if( cause instanceof IOException )
+        {
+            e = ( IOException ) cause;
+        }
+        
+        if( e != null && in != null )
+        {
+            in.setException( e );
+            beginService( session, in );
+        }
+        else
+        {
+            cause.printStackTrace();
+            session.close();
+        }
+    }
+
+    /**
+     * Handles read timeout.
+     */
+    public void sessionIdle( IoSession session, IdleStatus status )
+    {
+        if( status == IdleStatus.READER_IDLE )
+        {
+            throw new StreamIoException(
+                    new SocketTimeoutException( "Read timeout" ) );
+        }
+    }
+
+    private void beginService( IoSession session, PipedInputStream in )
+    {
+        if( session.getAttribute( KEY_STARTED ) == null )
+        {
+            session.setAttribute( KEY_STARTED, Boolean.TRUE );
+            processStreamIo( session, in, new ServiceOutputStream( session ) );
+        }
+    }
+
+    private static class PipedInputStream extends java.io.PipedInputStream
+    {
+        private IOException exception;
+
+        public PipedInputStream(PipedOutputStream src) throws IOException
+        {
+            super( src );
+        }
+        
+        public void setException( IOException e )
+        {
+            this.exception = e;
+        }
+
+        public synchronized int read() throws IOException
+        {
+            throwException();
+            return super.read();
+        }
+
+        public synchronized int read( byte[] b, int off, int len ) throws IOException
+        {
+            throwException();
+            return super.read( b, off, len );
+        }
+        
+        private void throwException() throws IOException
+        {
+            if( exception != null )
+            {
+                throw exception;
+            }
+        }
+    }
+
+    private static class ServiceOutputStream extends OutputStream
+    {
+        private final IoSession session;
+        
+        public ServiceOutputStream( IoSession session )
+        {
+            this.session = session;
+        }
+
+        public void close()
+        {
+            session.close( true );
+        }
+
+        public void flush()
+        {
+        }
+
+        public void write( byte[] b, int off, int len )
+        {
+            ByteBuffer buf = ByteBuffer.wrap( b, off, len );
+            buf.acquire(); // prevent from being pooled.
+            session.write( buf );
+        }
+
+        public void write( byte[] b )
+        {
+            ByteBuffer buf = ByteBuffer.wrap( b );
+            buf.acquire(); // prevent from being pooled.
+            session.write( buf );
+        }
+
+        public void write( int b )
+        {
+            ByteBuffer buf = ByteBuffer.allocate( 1 );
+            buf.put( ( byte ) b );
+            buf.flip();
+            session.write( buf );
+        }
+    }
+    
+    private static class StreamIoException extends RuntimeException
+    {
+        private static final long serialVersionUID = 3976736960742503222L;
+
+        public StreamIoException( IOException cause )
+        {
+            super(cause);
+        }
+    }
+}

Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/handler/StreamIoHandler.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/branches/api_integration/src/java/org/apache/mina/handler/UnknownMessageTypeException.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/handler/UnknownMessageTypeException.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/handler/UnknownMessageTypeException.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/handler/UnknownMessageTypeException.java Mon May  9 02:21:50 2005
@@ -0,0 +1,54 @@
+/*
+ *   @(#) $Id$
+ *
+ *   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.mina.handler;
+
+
+/**
+ * An exception that is thrown when {@link DemuxingIoHandler}
+ * cannot find any {@link MessageHandler}s associated with the specific
+ * message type.  You have to use
+ * {@link DemuxingIoHandler#registerMessageType(Class, MessageHandler)}
+ * to associate a message type and a message handler. 
+ * 
+ * @author The Apache Directory Project
+ * @version $Rev$, $Date$
+ */
+public class UnknownMessageTypeException extends RuntimeException
+{
+    private static final long serialVersionUID = 3257290227428047158L;
+
+    public UnknownMessageTypeException()
+    {
+    }
+
+    public UnknownMessageTypeException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+
+    public UnknownMessageTypeException( String message )
+    {
+        super( message );
+    }
+
+    public UnknownMessageTypeException( Throwable cause )
+    {
+        super( cause );
+    }
+}
\ No newline at end of file

Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/handler/UnknownMessageTypeException.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: directory/network/branches/api_integration/src/java/org/apache/mina/registry/Service.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/registry/Service.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/registry/Service.java (original)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/registry/Service.java Mon May  9 02:21:50 2005
@@ -23,7 +23,7 @@
 import java.net.SocketAddress;
 
 import org.apache.mina.common.TransportType;
-import org.apache.mina.protocol.vmpipe.VmPipeAddress;
+import org.apache.mina.transport.vmpipe.VmPipeAddress;
 
 /**
  * Represents a service that is registered to {@link ServiceRegistry}.

Modified: directory/network/branches/api_integration/src/java/org/apache/mina/registry/ServiceRegistry.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/registry/ServiceRegistry.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/registry/ServiceRegistry.java (original)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/registry/ServiceRegistry.java Mon May  9 02:21:50 2005
@@ -21,11 +21,9 @@
 import java.io.IOException;
 import java.util.Set;
 
+import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.TransportType;
-import org.apache.mina.io.IoAcceptor;
-import org.apache.mina.io.IoHandler;
-import org.apache.mina.protocol.ProtocolAcceptor;
-import org.apache.mina.protocol.ProtocolProvider;
 
 /**
  * Interface for the internet service registry. The registry is used by MINA
@@ -43,12 +41,6 @@
     void bind( Service service, IoHandler ioHandler ) throws IOException;
 
     /**
-     * Binds the specified protocol provider to the specified service.
-     */
-    void bind( Service service, ProtocolProvider protocolProvider )
-            throws IOException;
-
-    /**
      * Unbinds the specified service (and its aggregated I/O handler or
      * protocol provider). 
      */
@@ -83,7 +75,5 @@
      */
     Set getServices(int port);
 
-    IoAcceptor getIoAcceptor( TransportType transportType );
-    
-    ProtocolAcceptor getProtocolAcceptor( TransportType transportType );
+    IoAcceptor getAcceptor( TransportType transportType );
 }

Modified: directory/network/branches/api_integration/src/java/org/apache/mina/registry/SimpleServiceRegistry.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/registry/SimpleServiceRegistry.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/registry/SimpleServiceRegistry.java (original)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/registry/SimpleServiceRegistry.java Mon May  9 02:21:50 2005
@@ -10,18 +10,14 @@
 import java.util.Iterator;
 import java.util.Set;
 
+import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.TransportType;
-import org.apache.mina.io.IoAcceptor;
-import org.apache.mina.io.IoHandler;
-import org.apache.mina.io.datagram.DatagramAcceptor;
-import org.apache.mina.io.filter.IoThreadPoolFilter;
-import org.apache.mina.io.socket.SocketAcceptor;
-import org.apache.mina.protocol.ProtocolAcceptor;
-import org.apache.mina.protocol.ProtocolProvider;
-import org.apache.mina.protocol.filter.ProtocolThreadPoolFilter;
-import org.apache.mina.protocol.io.IoProtocolAcceptor;
-import org.apache.mina.protocol.vmpipe.VmPipeAcceptor;
-import org.apache.mina.protocol.vmpipe.VmPipeAddress;
+import org.apache.mina.filter.ThreadPoolFilter;
+import org.apache.mina.transport.socket.nio.DatagramAcceptor;
+import org.apache.mina.transport.socket.nio.SocketAcceptor;
+import org.apache.mina.transport.vmpipe.VmPipeAcceptor;
+import org.apache.mina.transport.vmpipe.VmPipeAddress;
 
 /**
  * A simple implementation of {@link ServiceRegistry}.
@@ -38,49 +34,30 @@
 
     protected final IoAcceptor datagramIoAcceptor = new DatagramAcceptor();
 
-    protected final ProtocolAcceptor socketProtocolAcceptor = new IoProtocolAcceptor(
-            socketIoAcceptor );
+    protected final IoAcceptor vmPipeAcceptor = new VmPipeAcceptor();
 
-    protected final ProtocolAcceptor datagramProtocolAcceptor = new IoProtocolAcceptor(
-            datagramIoAcceptor );
-
-    protected final ProtocolAcceptor vmPipeAcceptor = new VmPipeAcceptor();
-
-    protected final IoThreadPoolFilter ioThreadPoolFilter = new IoThreadPoolFilter();
-
-    protected final ProtocolThreadPoolFilter protocolThreadPoolFilter = new ProtocolThreadPoolFilter();
+    protected final ThreadPoolFilter threadPoolFilter = new ThreadPoolFilter();
 
     private final Set services = new HashSet();
 
     public SimpleServiceRegistry() throws IOException
     {
-        socketIoAcceptor.getFilterChain().addFirst( "threadPool", ioThreadPoolFilter );
-        datagramIoAcceptor.getFilterChain().addFirst( "threadPool", ioThreadPoolFilter );
-        socketProtocolAcceptor.getFilterChain().addFirst( "threadPool", protocolThreadPoolFilter );
-        datagramProtocolAcceptor.getFilterChain().addFirst( "threadPool", protocolThreadPoolFilter );
-        vmPipeAcceptor.getFilterChain().addFirst( "threadPool", protocolThreadPoolFilter );
+        socketIoAcceptor.getFilterChain().addFirst( "threadPool", threadPoolFilter );
+        datagramIoAcceptor.getFilterChain().addFirst( "threadPool", threadPoolFilter );
+        vmPipeAcceptor.getFilterChain().addFirst( "threadPool", threadPoolFilter );
     }
 
     public void bind( Service service, IoHandler ioHandler ) throws IOException
     {
-        IoAcceptor acceptor = findIoAcceptor( service.getTransportType() );
+        IoAcceptor acceptor = findAcceptor( service.getTransportType() );
         acceptor.bind( service.getAddress(), ioHandler );
         startThreadPools();
         services.add( service );
     }
 
-    public synchronized void bind( Service service,
-                                   ProtocolProvider protocolProvider ) throws IOException
-    {
-        ProtocolAcceptor acceptor = findProtocolAcceptor( service.getTransportType() );
-        acceptor.bind( service.getAddress(), protocolProvider );
-        startThreadPools();
-        services.add( service );
-    }
-
     public synchronized void unbind( Service service )
     {
-        ProtocolAcceptor acceptor = findProtocolAcceptor( service
+        IoAcceptor acceptor = findAcceptor( service
                 .getTransportType() );
         try
         {
@@ -114,14 +91,9 @@
         }
     }
 
-    public IoAcceptor getIoAcceptor( TransportType transportType )
+    public IoAcceptor getAcceptor( TransportType transportType )
     {
-        return findIoAcceptor( transportType );
-    }
-
-    public ProtocolAcceptor getProtocolAcceptor( TransportType transportType )
-    {
-        return findProtocolAcceptor( transportType );
+        return findAcceptor( transportType );
     }
 
     public synchronized Set getAllServices()
@@ -190,7 +162,7 @@
         return result;
     }
 
-    protected IoAcceptor findIoAcceptor( TransportType transportType )
+    protected IoAcceptor findAcceptor( TransportType transportType )
     {
         if( transportType == TransportType.SOCKET )
             return socketIoAcceptor;
@@ -202,27 +174,12 @@
 
     }
 
-    protected ProtocolAcceptor findProtocolAcceptor(
-                                                    TransportType transportType )
-    {
-        if( transportType == TransportType.SOCKET )
-            return socketProtocolAcceptor;
-        else if( transportType == TransportType.DATAGRAM )
-            return datagramProtocolAcceptor;
-        else if( transportType == TransportType.VM_PIPE )
-            return vmPipeAcceptor;
-        else
-            throw new IllegalArgumentException(
-                    "Unsupported transport type: " + transportType );
-    }
-
     private void startThreadPools()
     {
         if( !services.isEmpty() )
             return;
 
-        ioThreadPoolFilter.start();
-        protocolThreadPoolFilter.start();
+        threadPoolFilter.start();
     }
 
     private void stopThreadPools()
@@ -230,7 +187,6 @@
         if( !services.isEmpty() )
             return;
 
-        ioThreadPoolFilter.stop();
-        protocolThreadPoolFilter.stop();
+        threadPoolFilter.stop();
     }
 }



Mime
View raw message