directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r349650 - in /directory/network/trunk/src: examples/org/apache/mina/examples/sumup/ examples/org/apache/mina/examples/sumup/codec/ examples/org/apache/mina/examples/sumup/message/ java/org/apache/mina/filter/codec/ java/org/apache/mina/filt...
Date Tue, 29 Nov 2005 05:11:29 GMT
Author: trustin
Date: Mon Nov 28 21:11:07 2005
New Revision: 349650

URL: http://svn.apache.org/viewcvs?rev=349650&view=rev
Log:
Resolved issue: DIRMINA-51 Object serialization filter
* This filter is required to perform a demonstration in ApacheCon, so I implemented it quickly.
* Added ObjectSerializationCodecFactory
* Added ObjectSerializationEncoder
* Added ObjectSerializationDecoder
* Modified SumUp example to support both custom codec and object serialization codec

Added:
    directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/
    directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/DemuxingProtocolCodecFactory.java
      - copied, changed from r349561, directory/network/trunk/src/java/org/apache/mina/filter/codec/DemuxingProtocolCodecFactory.java
    directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/MessageDecoder.java
      - copied, changed from r349561, directory/network/trunk/src/java/org/apache/mina/filter/codec/MessageDecoder.java
    directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/MessageDecoderFactory.java
      - copied, changed from r349561, directory/network/trunk/src/java/org/apache/mina/filter/codec/MessageDecoderFactory.java
    directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/MessageDecoderResult.java
      - copied, changed from r349561, directory/network/trunk/src/java/org/apache/mina/filter/codec/MessageDecoderResult.java
    directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/MessageEncoder.java
      - copied, changed from r349561, directory/network/trunk/src/java/org/apache/mina/filter/codec/MessageEncoder.java
    directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/MessageEncoderFactory.java
      - copied, changed from r349561, directory/network/trunk/src/java/org/apache/mina/filter/codec/MessageEncoderFactory.java
    directory/network/trunk/src/java/org/apache/mina/filter/codec/serialization/
    directory/network/trunk/src/java/org/apache/mina/filter/codec/serialization/ObjectSerializationCodecFactory.java
  (with props)
    directory/network/trunk/src/java/org/apache/mina/filter/codec/serialization/ObjectSerializationDecoder.java
  (with props)
    directory/network/trunk/src/java/org/apache/mina/filter/codec/serialization/ObjectSerializationEncoder.java
  (with props)
Removed:
    directory/network/trunk/src/java/org/apache/mina/filter/codec/DemuxingProtocolCodecFactory.java
    directory/network/trunk/src/java/org/apache/mina/filter/codec/MessageDecoder.java
    directory/network/trunk/src/java/org/apache/mina/filter/codec/MessageDecoderFactory.java
    directory/network/trunk/src/java/org/apache/mina/filter/codec/MessageDecoderResult.java
    directory/network/trunk/src/java/org/apache/mina/filter/codec/MessageEncoder.java
    directory/network/trunk/src/java/org/apache/mina/filter/codec/MessageEncoderFactory.java
Modified:
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Client.java
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/ClientSessionHandler.java
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Server.java
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/ServerSessionHandler.java
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AbstractMessageDecoder.java
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AbstractMessageEncoder.java
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AddMessageDecoder.java
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AddMessageEncoder.java
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/ResultMessageDecoder.java
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/ResultMessageEncoder.java
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/SumUpProtocolCodecFactory.java
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/AbstractMessage.java
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/AddMessage.java
    directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/ResultMessage.java

Modified: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Client.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Client.java?rev=349650&r1=349649&r2=349650&view=diff
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Client.java (original)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Client.java Mon Nov
28 21:11:07 2005
@@ -38,6 +38,8 @@
     private static final String HOSTNAME = "localhost";
     private static final int PORT = 8080;
     private static final int CONNECT_TIMEOUT = 30; // seconds
+    // Set this to false to use object serialization instead of custom codec.
+    private static final boolean USE_CUSTOM_CODEC = true;
 
     public static void main( String[] args ) throws Throwable
     {
@@ -75,7 +77,7 @@
             {
                 ConnectFuture future = connector.connect(
                         new InetSocketAddress( HOSTNAME, PORT ),
-                        new ClientSessionHandler( values ) );
+                        new ClientSessionHandler( USE_CUSTOM_CODEC, values ) );
                 
                 future.join();
                 session = future.getSession();

Modified: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/ClientSessionHandler.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/ClientSessionHandler.java?rev=349650&r1=349649&r2=349650&view=diff
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/ClientSessionHandler.java
(original)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/ClientSessionHandler.java
Mon Nov 28 21:11:07 2005
@@ -25,7 +25,9 @@
 import org.apache.mina.examples.sumup.message.AddMessage;
 import org.apache.mina.examples.sumup.message.ResultMessage;
 import org.apache.mina.filter.LoggingFilter;
+import org.apache.mina.filter.codec.ProtocolCodecFactory;
 import org.apache.mina.filter.codec.ProtocolCodecFilter;
+import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory;
 import org.apache.mina.util.SessionLog;
 
 /**
@@ -36,11 +38,13 @@
  */
 public class ClientSessionHandler extends IoHandlerAdapter
 {
+    private final boolean useCustomCodec;
     private final int[] values;
     private boolean finished;
 
-    public ClientSessionHandler( int[] values )
+    public ClientSessionHandler( boolean useCustomCodec, int[] values )
     {
+        this.useCustomCodec = useCustomCodec;
         this.values = values;
     }
 
@@ -51,9 +55,18 @@
 
     public void sessionCreated( IoSession session ) throws Exception
     {
-        session.getFilterChain().addFirst(
-                "protocolFilter", new ProtocolCodecFilter(
-                        new SumUpProtocolCodecFactory( false ) ) );
+        ProtocolCodecFactory codec;
+        if( useCustomCodec )
+        {
+            codec = new SumUpProtocolCodecFactory( true );
+        }
+        else
+        {
+            codec = new ObjectSerializationCodecFactory();
+        }
+
+        session.getFilterChain().addLast(
+                "protocolFilter", new ProtocolCodecFilter( codec ) );
         session.getFilterChain().addLast(
                 "logger", new LoggingFilter() );
     }

Modified: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Server.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Server.java?rev=349650&r1=349649&r2=349650&view=diff
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Server.java (original)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/Server.java Mon Nov
28 21:11:07 2005
@@ -32,6 +32,8 @@
 public class Server
 {
     private static final int SERVER_PORT = 8080;
+    // Set this to false to use object serialization instead of custom codec.
+    private static final boolean USE_CUSTOM_CODEC = true;
 
     public static void main( String[] args ) throws Throwable
     {
@@ -40,7 +42,7 @@
 
         registry.bind(
                 new Service( "sumUp", TransportType.SOCKET, SERVER_PORT ),
-                new ServerSessionHandler() );
+                new ServerSessionHandler( USE_CUSTOM_CODEC ) );
 
         System.out.println( "Listening on port " + SERVER_PORT );
     }

Modified: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/ServerSessionHandler.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/ServerSessionHandler.java?rev=349650&r1=349649&r2=349650&view=diff
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/ServerSessionHandler.java
(original)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/ServerSessionHandler.java
Mon Nov 28 21:11:07 2005
@@ -25,7 +25,9 @@
 import org.apache.mina.examples.sumup.message.AddMessage;
 import org.apache.mina.examples.sumup.message.ResultMessage;
 import org.apache.mina.filter.LoggingFilter;
+import org.apache.mina.filter.codec.ProtocolCodecFactory;
 import org.apache.mina.filter.codec.ProtocolCodecFilter;
+import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory;
 import org.apache.mina.util.SessionLog;
 
 /**
@@ -36,16 +38,27 @@
  */
 public class ServerSessionHandler implements IoHandler
 {
+    private final boolean useCustomCodec;
 
-    public ServerSessionHandler()
+    public ServerSessionHandler( boolean useCustomCodec )
     {
+        this.useCustomCodec = useCustomCodec;
     }
 
     public void sessionCreated( IoSession session ) throws Exception
     {
+        ProtocolCodecFactory codec;
+        if( useCustomCodec )
+        {
+            codec = new SumUpProtocolCodecFactory( true );
+        }
+        else
+        {
+            codec = new ObjectSerializationCodecFactory();
+        }
+
         session.getFilterChain().addFirst(
-                "protocolFilter", new ProtocolCodecFilter(
-                        new SumUpProtocolCodecFactory( true ) ) );
+                "protocolFilter", new ProtocolCodecFilter( codec ) );
         session.getFilterChain().addLast(
                 "logger", new LoggingFilter() );
     }

Modified: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AbstractMessageDecoder.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AbstractMessageDecoder.java?rev=349650&r1=349649&r2=349650&view=diff
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AbstractMessageDecoder.java
(original)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AbstractMessageDecoder.java
Mon Nov 28 21:11:07 2005
@@ -21,9 +21,9 @@
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.examples.sumup.message.AbstractMessage;
-import org.apache.mina.filter.codec.MessageDecoder;
-import org.apache.mina.filter.codec.MessageDecoderResult;
 import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+import org.apache.mina.filter.codec.demux.MessageDecoder;
+import org.apache.mina.filter.codec.demux.MessageDecoderResult;
 
 /**
  * A {@link MessageDecoder} that decodes message header and forwards

Modified: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AbstractMessageEncoder.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AbstractMessageEncoder.java?rev=349650&r1=349649&r2=349650&view=diff
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AbstractMessageEncoder.java
(original)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AbstractMessageEncoder.java
Mon Nov 28 21:11:07 2005
@@ -21,8 +21,8 @@
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.examples.sumup.message.AbstractMessage;
-import org.apache.mina.filter.codec.MessageEncoder;
 import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+import org.apache.mina.filter.codec.demux.MessageEncoder;
 
 /**
  * A {@link MessageEncoder} that encodes message header and forwards

Modified: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AddMessageDecoder.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AddMessageDecoder.java?rev=349650&r1=349649&r2=349650&view=diff
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AddMessageDecoder.java
(original)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AddMessageDecoder.java
Mon Nov 28 21:11:07 2005
@@ -22,7 +22,7 @@
 import org.apache.mina.common.IoSession;
 import org.apache.mina.examples.sumup.message.AbstractMessage;
 import org.apache.mina.examples.sumup.message.AddMessage;
-import org.apache.mina.filter.codec.MessageDecoder;
+import org.apache.mina.filter.codec.demux.MessageDecoder;
 
 /**
  * A {@link MessageDecoder} that decodes {@link AddMessage}.

Modified: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AddMessageEncoder.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AddMessageEncoder.java?rev=349650&r1=349649&r2=349650&view=diff
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AddMessageEncoder.java
(original)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/AddMessageEncoder.java
Mon Nov 28 21:11:07 2005
@@ -26,7 +26,7 @@
 import org.apache.mina.common.IoSession;
 import org.apache.mina.examples.sumup.message.AbstractMessage;
 import org.apache.mina.examples.sumup.message.AddMessage;
-import org.apache.mina.filter.codec.MessageEncoder;
+import org.apache.mina.filter.codec.demux.MessageEncoder;
 
 /**
  * A {@link MessageEncoder} that encodes {@link AddMessage}.

Modified: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/ResultMessageDecoder.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/ResultMessageDecoder.java?rev=349650&r1=349649&r2=349650&view=diff
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/ResultMessageDecoder.java
(original)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/ResultMessageDecoder.java
Mon Nov 28 21:11:07 2005
@@ -22,7 +22,7 @@
 import org.apache.mina.common.IoSession;
 import org.apache.mina.examples.sumup.message.AbstractMessage;
 import org.apache.mina.examples.sumup.message.ResultMessage;
-import org.apache.mina.filter.codec.MessageDecoder;
+import org.apache.mina.filter.codec.demux.MessageDecoder;
 
 /**
  * A {@link MessageDecoder} that decodes {@link ResultMessage}.

Modified: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/ResultMessageEncoder.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/ResultMessageEncoder.java?rev=349650&r1=349649&r2=349650&view=diff
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/ResultMessageEncoder.java
(original)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/ResultMessageEncoder.java
Mon Nov 28 21:11:07 2005
@@ -26,7 +26,7 @@
 import org.apache.mina.common.IoSession;
 import org.apache.mina.examples.sumup.message.AbstractMessage;
 import org.apache.mina.examples.sumup.message.ResultMessage;
-import org.apache.mina.filter.codec.MessageEncoder;
+import org.apache.mina.filter.codec.demux.MessageEncoder;
 
 /**
  * A {@link MessageEncoder} that encodes {@link ResultMessage}.

Modified: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/SumUpProtocolCodecFactory.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/SumUpProtocolCodecFactory.java?rev=349650&r1=349649&r2=349650&view=diff
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/SumUpProtocolCodecFactory.java
(original)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/codec/SumUpProtocolCodecFactory.java
Mon Nov 28 21:11:07 2005
@@ -18,8 +18,8 @@
  */
 package org.apache.mina.examples.sumup.codec;
 
-import org.apache.mina.filter.codec.DemuxingProtocolCodecFactory;
 import org.apache.mina.filter.codec.ProtocolCodecFactory;
+import org.apache.mina.filter.codec.demux.DemuxingProtocolCodecFactory;
 
 /**
  * A {@link ProtocolCodecFactory} that provides a protocol codec for

Modified: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/AbstractMessage.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/AbstractMessage.java?rev=349650&r1=349649&r2=349650&view=diff
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/AbstractMessage.java
(original)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/AbstractMessage.java
Mon Nov 28 21:11:07 2005
@@ -18,13 +18,15 @@
  */
 package org.apache.mina.examples.sumup.message;
 
+import java.io.Serializable;
+
 /**
  * A base message for SumUp protocol messages.
  * 
  * @author The Apache Directory Project
  * @version $Rev$, $Date$
  */
-public abstract class AbstractMessage
+public abstract class AbstractMessage implements Serializable
 {
     private int sequence;
 

Modified: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/AddMessage.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/AddMessage.java?rev=349650&r1=349649&r2=349650&view=diff
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/AddMessage.java
(original)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/AddMessage.java
Mon Nov 28 21:11:07 2005
@@ -26,6 +26,8 @@
  */
 public class AddMessage extends AbstractMessage
 {
+    private static final long serialVersionUID = -940833727168119141L;
+
     private int value;
 
     public AddMessage()

Modified: directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/ResultMessage.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/ResultMessage.java?rev=349650&r1=349649&r2=349650&view=diff
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/ResultMessage.java
(original)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/sumup/message/ResultMessage.java
Mon Nov 28 21:11:07 2005
@@ -26,6 +26,8 @@
  */
 public class ResultMessage extends AbstractMessage
 {
+    private static final long serialVersionUID = 7371210248110219946L;
+
     private boolean ok;
     private int value;
 

Copied: directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/DemuxingProtocolCodecFactory.java
(from r349561, directory/network/trunk/src/java/org/apache/mina/filter/codec/DemuxingProtocolCodecFactory.java)
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/DemuxingProtocolCodecFactory.java?p2=directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/DemuxingProtocolCodecFactory.java&p1=directory/network/trunk/src/java/org/apache/mina/filter/codec/DemuxingProtocolCodecFactory.java&r1=349561&r2=349650&rev=349650&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/codec/DemuxingProtocolCodecFactory.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/DemuxingProtocolCodecFactory.java
Mon Nov 28 21:11:07 2005
@@ -16,7 +16,7 @@
  *   limitations under the License.
  *
  */
-package org.apache.mina.filter.codec;
+package org.apache.mina.filter.codec.demux;
 
 import java.util.IdentityHashMap;
 import java.util.Iterator;
@@ -25,6 +25,14 @@
 
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolCodecFactory;
+import org.apache.mina.filter.codec.ProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolDecoderException;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+import org.apache.mina.filter.codec.ProtocolEncoder;
+import org.apache.mina.filter.codec.ProtocolEncoderException;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
 import org.apache.mina.util.IdentityHashSet;
 
 /**

Copied: directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/MessageDecoder.java
(from r349561, directory/network/trunk/src/java/org/apache/mina/filter/codec/MessageDecoder.java)
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/MessageDecoder.java?p2=directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/MessageDecoder.java&p1=directory/network/trunk/src/java/org/apache/mina/filter/codec/MessageDecoder.java&r1=349561&r2=349650&rev=349650&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/codec/MessageDecoder.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/MessageDecoder.java
Mon Nov 28 21:11:07 2005
@@ -16,10 +16,11 @@
  *   limitations under the License.
  *
  */
-package org.apache.mina.filter.codec;
+package org.apache.mina.filter.codec.demux;
 
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
 
 /**
  * Decodes specific messages.

Copied: directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/MessageDecoderFactory.java
(from r349561, directory/network/trunk/src/java/org/apache/mina/filter/codec/MessageDecoderFactory.java)
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/MessageDecoderFactory.java?p2=directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/MessageDecoderFactory.java&p1=directory/network/trunk/src/java/org/apache/mina/filter/codec/MessageDecoderFactory.java&r1=349561&r2=349650&rev=349650&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/codec/MessageDecoderFactory.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/MessageDecoderFactory.java
Mon Nov 28 21:11:07 2005
@@ -16,7 +16,7 @@
  *   limitations under the License.
  *
  */
-package org.apache.mina.filter.codec;
+package org.apache.mina.filter.codec.demux;
 
 /**
  * A factory that creates a new instance of {@link MessageDecoder}.

Copied: directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/MessageDecoderResult.java
(from r349561, directory/network/trunk/src/java/org/apache/mina/filter/codec/MessageDecoderResult.java)
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/MessageDecoderResult.java?p2=directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/MessageDecoderResult.java&p1=directory/network/trunk/src/java/org/apache/mina/filter/codec/MessageDecoderResult.java&r1=349561&r2=349650&rev=349650&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/codec/MessageDecoderResult.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/MessageDecoderResult.java
Mon Nov 28 21:11:07 2005
@@ -16,10 +16,11 @@
  *   limitations under the License.
  *
  */
-package org.apache.mina.filter.codec;
+package org.apache.mina.filter.codec.demux;
 
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
 
 /**
  * Represents results from {@link MessageDecoder}.

Copied: directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/MessageEncoder.java
(from r349561, directory/network/trunk/src/java/org/apache/mina/filter/codec/MessageEncoder.java)
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/MessageEncoder.java?p2=directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/MessageEncoder.java&p1=directory/network/trunk/src/java/org/apache/mina/filter/codec/MessageEncoder.java&r1=349561&r2=349650&rev=349650&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/codec/MessageEncoder.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/MessageEncoder.java
Mon Nov 28 21:11:07 2005
@@ -16,12 +16,13 @@
  *   limitations under the License.
  *
  */
-package org.apache.mina.filter.codec;
+package org.apache.mina.filter.codec.demux;
 
 import java.util.Set;
 
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
 
 /**
  * Encodes messages of specific types specified by {@link #getMessageTypes()}.

Copied: directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/MessageEncoderFactory.java
(from r349561, directory/network/trunk/src/java/org/apache/mina/filter/codec/MessageEncoderFactory.java)
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/MessageEncoderFactory.java?p2=directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/MessageEncoderFactory.java&p1=directory/network/trunk/src/java/org/apache/mina/filter/codec/MessageEncoderFactory.java&r1=349561&r2=349650&rev=349650&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/codec/MessageEncoderFactory.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/filter/codec/demux/MessageEncoderFactory.java
Mon Nov 28 21:11:07 2005
@@ -16,7 +16,7 @@
  *   limitations under the License.
  *
  */
-package org.apache.mina.filter.codec;
+package org.apache.mina.filter.codec.demux;
 
 /**
  * A factory that creates a new instance of {@link MessageEncoder}.

Added: directory/network/trunk/src/java/org/apache/mina/filter/codec/serialization/ObjectSerializationCodecFactory.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/filter/codec/serialization/ObjectSerializationCodecFactory.java?rev=349650&view=auto
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/codec/serialization/ObjectSerializationCodecFactory.java
(added)
+++ directory/network/trunk/src/java/org/apache/mina/filter/codec/serialization/ObjectSerializationCodecFactory.java
Mon Nov 28 21:11:07 2005
@@ -0,0 +1,118 @@
+/*
+ *   @(#) $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.serialization;
+
+import org.apache.mina.common.BufferDataException;
+import org.apache.mina.filter.codec.ProtocolCodecFactory;
+import org.apache.mina.filter.codec.ProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolEncoder;
+
+/**
+ * A {@link ProtocolCodecFactory} that serializes and deserializes Java objects.
+ * This codec is very useful when you have to prototype your application rapidly
+ * without any specific codec.
+ *
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class ObjectSerializationCodecFactory implements ProtocolCodecFactory
+{
+    private final ObjectSerializationEncoder encoder;
+    private final ObjectSerializationDecoder decoder;
+    
+    /**
+     * Creates a new instance with the {@link ClassLoader} of
+     * the current thread.
+     */
+    public ObjectSerializationCodecFactory()
+    {
+        this( Thread.currentThread().getContextClassLoader() );
+    }
+    
+    /**
+     * Creates a new instance with the specified {@link ClassLoader}.
+     */
+    public ObjectSerializationCodecFactory( ClassLoader classLoader )
+    {
+        encoder = new ObjectSerializationEncoder();
+        decoder = new ObjectSerializationDecoder( classLoader );
+    }
+
+    public ProtocolEncoder getEncoder()
+    {
+        return encoder;
+    }
+
+    public ProtocolDecoder getDecoder()
+    {
+        return decoder;
+    }
+    
+    /**
+     * Returns the allowed maximum size of the encoded object.
+     * If the size of the encoded object exceeds this value, the encoder
+     * will throw a {@link IllegalArgumentException}.  The default value
+     * is {@link Integer#MAX_VALUE}.
+     * <p>
+     * This method does the same job with {@link ObjectSerializationEncoder#setMaxObjectSize(int)}.
+     */
+    public int gerEncoderMaxObjectSize()
+    {
+        return encoder.getMaxObjectSize();
+    }
+    
+    /**
+     * Sets the allowed maximum size of the encoded object.
+     * If the size of the encoded object exceeds this value, the encoder
+     * will throw a {@link IllegalArgumentException}.  The default value
+     * is {@link Integer#MAX_VALUE}.
+     * <p>
+     * This method does the same job with {@link ObjectSerializationEncoder#setMaxObjectSize(int)}.
+     */
+    public void setEncoderMaxObjectSize( int maxObjectSize )
+    {
+        encoder.setMaxObjectSize( maxObjectSize );
+    }
+    
+    /**
+     * Returns the allowed maximum size of the object to be decoded.
+     * If the size of the object to be decoded exceeds this value, the
+     * decoder will throw a {@link BufferDataException}.  The default
+     * value is <tt>1048576</tt> (1MB).
+     * <p>
+     * This method does the same job with {@link ObjectSerializationDecoder#getMaxObjectSize()}.
+     */
+    public int gerDecoderMaxObjectSize()
+    {
+        return decoder.getMaxObjectSize();
+    }
+    
+    /**
+     * Sets the allowed maximum size of the object to be decoded.
+     * If the size of the object to be decoded exceeds this value, the
+     * decoder will throw a {@link BufferDataException}.  The default
+     * value is <tt>1048576</tt> (1MB).
+     * <p>
+     * This method does the same job with {@link ObjectSerializationDecoder#setMaxObjectSize(int)}.
+     */
+    public void setDecoderMaxObjectSize( int maxObjectSize )
+    {
+        decoder.setMaxObjectSize( maxObjectSize );
+    }
+}

Propchange: directory/network/trunk/src/java/org/apache/mina/filter/codec/serialization/ObjectSerializationCodecFactory.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/java/org/apache/mina/filter/codec/serialization/ObjectSerializationDecoder.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/filter/codec/serialization/ObjectSerializationDecoder.java?rev=349650&view=auto
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/codec/serialization/ObjectSerializationDecoder.java
(added)
+++ directory/network/trunk/src/java/org/apache/mina/filter/codec/serialization/ObjectSerializationDecoder.java
Mon Nov 28 21:11:07 2005
@@ -0,0 +1,118 @@
+/*
+ *   @(#) $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.serialization;
+
+import java.io.Serializable;
+
+import org.apache.mina.common.BufferDataException;
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+
+/**
+ * A {@link ProtocolDecoder} which deserializes {@link Serializable} Java
+ * objects using {@link ByteBuffer#getObject(ClassLoader)}.
+ *
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class ObjectSerializationDecoder extends CumulativeProtocolDecoder
+{
+    private final ClassLoader classLoader;
+    private int maxObjectSize = 1048576; // 1MB
+    
+    /**
+     * Creates a new instance with the {@link ClassLoader} of
+     * the current thread.
+     */
+    public ObjectSerializationDecoder()
+    {
+        this( Thread.currentThread().getContextClassLoader() );
+    }
+    
+    /**
+     * Creates a new instance with the specified {@link ClassLoader}.
+     */
+    public ObjectSerializationDecoder( ClassLoader classLoader )
+    {
+        if( classLoader == null )
+        {
+            throw new NullPointerException( "classLoader" );
+        }
+        this.classLoader = classLoader;
+    }
+
+    /**
+     * Returns the allowed maximum size of the object to be decoded.
+     * If the size of the object to be decoded exceeds this value, this
+     * decoder will throw a {@link BufferDataException}.  The default
+     * value is <tt>1048576</tt> (1MB).
+     */
+    public int getMaxObjectSize()
+    {
+        return maxObjectSize;
+    }
+    
+    /**
+     * Sets the allowed maximum size of the object to be decoded.
+     * If the size of the object to be decoded exceeds this value, this
+     * decoder will throw a {@link BufferDataException}.  The default
+     * value is <tt>1048576</tt> (1MB).
+     */
+    public void setMaxObjectSize( int maxObjectSize )
+    {
+        if( maxObjectSize <= 0 )
+        {
+            throw new IllegalArgumentException( "maxObjectSize: " + maxObjectSize );
+        }
+        
+        this.maxObjectSize = maxObjectSize;
+    }
+
+    protected boolean doDecode( IoSession session, ByteBuffer in, ProtocolDecoderOutput out
) throws Exception
+    {
+        if( in.remaining() < 4 )
+        {
+            return false;
+        }
+        
+        int baseIndex = in.position();
+        int objectSize = in.getInt( baseIndex );
+        if( objectSize <= 4 )
+        {
+            throw new BufferDataException( "Invalid object length: " + objectSize );
+        }
+        if( objectSize > maxObjectSize )
+        {
+            throw new BufferDataException( "The object to decode is too big: " + objectSize
+ " (> " + maxObjectSize + ')' );
+        }
+        
+        if( objectSize + 4 > in.remaining() )
+        {
+            return false;
+        }
+        else
+        {
+            out.write( in.getObject( classLoader ) );
+            return true;
+        }
+    }
+}

Propchange: directory/network/trunk/src/java/org/apache/mina/filter/codec/serialization/ObjectSerializationDecoder.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/java/org/apache/mina/filter/codec/serialization/ObjectSerializationEncoder.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/filter/codec/serialization/ObjectSerializationEncoder.java?rev=349650&view=auto
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/codec/serialization/ObjectSerializationEncoder.java
(added)
+++ directory/network/trunk/src/java/org/apache/mina/filter/codec/serialization/ObjectSerializationEncoder.java
Mon Nov 28 21:11:07 2005
@@ -0,0 +1,96 @@
+/*
+ *   @(#) $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.serialization;
+
+import java.io.NotSerializableException;
+import java.io.Serializable;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolEncoder;
+import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+
+/**
+ * A {@link ProtocolEncoder} which serializes {@link Serializable} Java objects
+ * using {@link ByteBuffer#putObject(Object)}.
+ *
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class ObjectSerializationEncoder extends ProtocolEncoderAdapter
+{
+    private int maxObjectSize = Integer.MAX_VALUE; // 2GB
+    
+    /**
+     * Creates a new instance.
+     */
+    public ObjectSerializationEncoder()
+    {
+    }
+    
+    /**
+     * Returns the allowed maximum size of the encoded object.
+     * If the size of the encoded object exceeds this value, this encoder
+     * will throw a {@link IllegalArgumentException}.  The default value
+     * is {@link Integer#MAX_VALUE}.
+     */
+    public int getMaxObjectSize()
+    {
+        return maxObjectSize;
+    }
+    
+    /**
+     * Sets the allowed maximum size of the encoded object.
+     * If the size of the encoded object exceeds this value, this encoder
+     * will throw a {@link IllegalArgumentException}.  The default value
+     * is {@link Integer#MAX_VALUE}.
+     */
+    public void setMaxObjectSize( int maxObjectSize )
+    {
+        if( maxObjectSize <= 0 )
+        {
+            throw new IllegalArgumentException( "maxObjectSize: " + maxObjectSize );
+        }
+        
+        this.maxObjectSize = maxObjectSize;
+    }
+
+    public void encode( IoSession session, Object message, ProtocolEncoderOutput out ) throws
Exception
+    {
+        if( !( message instanceof Serializable ) )
+        {
+            throw new NotSerializableException();
+        }
+
+        ByteBuffer buf = ByteBuffer.allocate( 64 );
+        buf.setAutoExpand( true );
+        buf.putObject( message );
+        
+        int objectSize = buf.position() - 4;
+        if( objectSize > maxObjectSize )
+        {
+            buf.release();
+            throw new IllegalArgumentException( "The encoded object is too big: " + objectSize
+ " (> " + maxObjectSize + ')' );
+        }
+        
+        buf.flip();
+        out.write( buf );
+    }
+}

Propchange: directory/network/trunk/src/java/org/apache/mina/filter/codec/serialization/ObjectSerializationEncoder.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision



Mime
View raw message