directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r325919 - in /directory/network/trunk/src: examples/org/apache/mina/examples/reverser/ java/org/apache/mina/filter/codec/
Date Mon, 17 Oct 2005 16:21:20 GMT
Author: trustin
Date: Mon Oct 17 09:21:07 2005
New Revision: 325919

URL: http://svn.apache.org/viewcvs?rev=325919&view=rev
Log:
* Added IoSession parameter to dispose() method
* Removed dispose() method from MessageEncoder and MessageDecoder to avoid performance penalty
* Added DemuxingProtocolCodecFactory.disposeCodecResources() instead

Removed:
    directory/network/trunk/src/java/org/apache/mina/filter/codec/MessageDecoderAdapter.java
    directory/network/trunk/src/java/org/apache/mina/filter/codec/MessageEncoderAdapter.java
Modified:
    directory/network/trunk/src/examples/org/apache/mina/examples/reverser/TextLineDecoder.java
    directory/network/trunk/src/examples/org/apache/mina/examples/reverser/TextLineEncoder.java
    directory/network/trunk/src/java/org/apache/mina/filter/codec/CumulativeProtocolDecoder.java
    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/MessageEncoder.java
    directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
    directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolDecoder.java
    directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolDecoderAdapter.java
    directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolEncoder.java
    directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolEncoderAdapter.java

Modified: directory/network/trunk/src/examples/org/apache/mina/examples/reverser/TextLineDecoder.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/reverser/TextLineDecoder.java?rev=325919&r1=325918&r2=325919&view=diff
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/reverser/TextLineDecoder.java
(original)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/reverser/TextLineDecoder.java
Mon Oct 17 09:21:07 2005
@@ -20,7 +20,7 @@
 
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.IoSession;
-import org.apache.mina.filter.codec.ProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolDecoderAdapter;
 import org.apache.mina.filter.codec.ProtocolDecoderException;
 import org.apache.mina.filter.codec.ProtocolDecoderOutput;
 
@@ -30,7 +30,7 @@
  * @author Trustin Lee (trustin@apache.org)
  * @version $Rev$, $Date$,
  */
-public class TextLineDecoder implements ProtocolDecoder
+public class TextLineDecoder extends ProtocolDecoderAdapter
 {
 
     private StringBuffer decodeBuf = new StringBuffer();
@@ -63,9 +63,5 @@
             }
         }
         while( in.hasRemaining() );
-    }
-
-    public void dispose() throws Exception
-    {
     }
 }

Modified: directory/network/trunk/src/examples/org/apache/mina/examples/reverser/TextLineEncoder.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/reverser/TextLineEncoder.java?rev=325919&r1=325918&r2=325919&view=diff
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/reverser/TextLineEncoder.java
(original)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/reverser/TextLineEncoder.java
Mon Oct 17 09:21:07 2005
@@ -20,7 +20,7 @@
 
 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;
 
 /**
@@ -29,7 +29,7 @@
  * @author Trustin Lee (trustin@apache.org)
  * @version $Rev$, $Date$,
  */
-public class TextLineEncoder implements ProtocolEncoder
+public class TextLineEncoder extends ProtocolEncoderAdapter
 {
 
     public void encode( IoSession session, Object message,

Modified: directory/network/trunk/src/java/org/apache/mina/filter/codec/CumulativeProtocolDecoder.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/filter/codec/CumulativeProtocolDecoder.java?rev=325919&r1=325918&r2=325919&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/codec/CumulativeProtocolDecoder.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/filter/codec/CumulativeProtocolDecoder.java
Mon Oct 17 09:21:07 2005
@@ -55,7 +55,7 @@
  * @author Trustin Lee (trustin@apache.org)
  * @version $Rev$, $Date$
  */
-public abstract class CumulativeProtocolDecoder implements ProtocolDecoder {
+public abstract class CumulativeProtocolDecoder extends ProtocolDecoderAdapter {
     
     /** Cumulation buffer */
     private ByteBuffer buf;

Modified: 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/DemuxingProtocolCodecFactory.java?rev=325919&r1=325918&r2=325919&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/DemuxingProtocolCodecFactory.java
Mon Oct 17 09:21:07 2005
@@ -23,7 +23,6 @@
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
-import java.util.logging.Logger;
 
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.IoSession;
@@ -35,6 +34,17 @@
  * returns demultiplex incoming messages and buffers to
  * appropriate {@link MessageEncoder}s and {@link MessageDecoder}s. 
  * 
+ * <h2>Disposing resources acquired by {@link MessageEncoder} and {@link MessageDecoder}</h2>
+ * <p>
+ * Make your {@link MessageEncoder} and {@link MessageDecoder} to put all
+ * resources that need to be released as a session attribute.  {@link #disposeCodecResources(IoSession)}
+ * method will be invoked when a session is closed.  Override {@link #disposeCodecResources(IoSession)}
+ * to release the resources you've put as an attribute.
+ * <p>
+ * We didn't provide any <tt>dispose</tt> method for {@link MessageEncoder} and
{@link MessageDecoder}
+ * because they can give you a big performance penalty in case you have a lot of
+ * message types to handle.
+ * 
  * @author The Apache Directory Project (dev@directory.apache.org)
  * @author Trustin Lee (trustin@apache.org)
  * @version $Rev$, $Date$
@@ -43,8 +53,6 @@
  * @see MessageDecoder
  */
 public class DemuxingProtocolCodecFactory implements ProtocolCodecFactory {
-    private static final Logger log = Logger.getLogger( DemuxingProtocolCodecFactory.class.getName()
);
-
     private MessageDecoderFactory[] decoderFactories = new MessageDecoderFactory[0];
     private MessageEncoderFactory[] encoderFactories = new MessageEncoderFactory[0];
     
@@ -123,6 +131,18 @@
         return new ProtocolDecoderImpl();
     }
     
+    /**
+     * Implement this method to release all resources acquired to perform
+     * encoding and decoding messages for the specified <tt>session</tt>.
+     * By default, this method does nothing.
+     * 
+     * @param session the session that requires resource deallocation now
+     */
+    protected void disposeCodecResources( IoSession session )
+    {
+        // Do nothing by default; let users implement it as they want.
+    }
+    
     private class ProtocolEncoderImpl implements ProtocolEncoder
     {
         private final Map encoders = new IdentityHashMap();
@@ -195,22 +215,9 @@
                 return encoder;
         }
 
-        public void dispose() throws Exception
+        public void dispose( IoSession session ) throws Exception
         {
-            for( Iterator i = encoders.values().iterator(); i.hasNext(); )
-            {
-                MessageEncoder encoder = ( MessageEncoder ) i.next();
-                try
-                {
-                    encoder.dispose();
-                }
-                catch( Throwable t )
-                {
-                    log.warning(
-                            "Failed to dispose: " + encoder.getClass().getName() +
-                            " (" + encoder + ')' );
-                }
-            }
+            DemuxingProtocolCodecFactory.this.disposeCodecResources( session );
         }
     }
     
@@ -305,22 +312,9 @@
             }
         }
 
-        public void dispose() throws Exception
+        public void dispose( IoSession session ) throws Exception
         {
-            for( int i = decoders.length - 1; i >= 0; i -- )
-            {
-                MessageDecoder decoder = decoders[ i ];
-                try
-                {
-                    decoder.dispose();
-                }
-                catch( Throwable t )
-                {
-                    log.warning(
-                            "Failed to dispose: " + decoder.getClass().getName() +
-                            " (" + decoder + ')' );
-                }
-            }
+            // ProtocolEncoder.dispose() already called disposeCodec().
         }
     }
     

Modified: 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/MessageDecoder.java?rev=325919&r1=325918&r2=325919&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/MessageDecoder.java Mon
Oct 17 09:21:07 2005
@@ -78,11 +78,4 @@
      */
     MessageDecoderResult decode( IoSession session, ByteBuffer in,
                          ProtocolDecoderOutput out ) throws Exception;
-    
-    /**
-     * Releases all resources related with this decoder.
-     * 
-     * @throws Exception if failed to dispose all resources
-     */
-    void dispose() throws Exception;
 }

Modified: 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/MessageEncoder.java?rev=325919&r1=325918&r2=325919&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/MessageEncoder.java Mon
Oct 17 09:21:07 2005
@@ -51,12 +51,4 @@
      */
     void encode( IoSession session, Object message,
                  ProtocolEncoderOutput out ) throws Exception;
-    
-    
-    /**
-     * Releases all resources related with this encoder.
-     * 
-     * @throws Exception if failed to dispose all resources
-     */
-    void dispose() throws Exception;
 }

Modified: directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java?rev=325919&r1=325918&r2=325919&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
Mon Oct 17 09:21:07 2005
@@ -200,7 +200,7 @@
 
         try
         {
-            encoder.dispose();
+            encoder.dispose( session );
         }
         catch( Throwable t )
         {
@@ -220,7 +220,7 @@
 
         try
         {
-            decoder.dispose();
+            decoder.dispose( session );
         }
         catch( Throwable t )
         {

Modified: directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolDecoder.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolDecoder.java?rev=325919&r1=325918&r2=325919&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolDecoder.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolDecoder.java Mon
Oct 17 09:21:07 2005
@@ -53,5 +53,5 @@
      * 
      * @throws Exception if failed to dispose all resources
      */
-    void dispose() throws Exception;
+    void dispose( IoSession session ) throws Exception;
 }

Modified: directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolDecoderAdapter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolDecoderAdapter.java?rev=325919&r1=325918&r2=325919&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolDecoderAdapter.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolDecoderAdapter.java
Mon Oct 17 09:21:07 2005
@@ -18,6 +18,8 @@
  */
 package org.apache.mina.filter.codec;
 
+import org.apache.mina.common.IoSession;
+
 /**
  * An abstract {@link ProtocolDecoder} implementation for those who don't have any
  * resources to dispose.
@@ -31,7 +33,7 @@
      * Override this method dispose all resources related with this decoder.
      * The default implementation does nothing.
      */
-    public void dispose() throws Exception
+    public void dispose( IoSession session ) throws Exception
     {
     }
 }

Modified: directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolEncoder.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolEncoder.java?rev=325919&r1=325918&r2=325919&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolEncoder.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolEncoder.java Mon
Oct 17 09:21:07 2005
@@ -57,5 +57,5 @@
      * 
      * @throws Exception if failed to dispose all resources
      */
-    void dispose() throws Exception;
+    void dispose( IoSession session ) throws Exception;
 }

Modified: directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolEncoderAdapter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolEncoderAdapter.java?rev=325919&r1=325918&r2=325919&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolEncoderAdapter.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/filter/codec/ProtocolEncoderAdapter.java
Mon Oct 17 09:21:07 2005
@@ -18,6 +18,8 @@
  */
 package org.apache.mina.filter.codec;
 
+import org.apache.mina.common.IoSession;
+
 /**
  * An abstract {@link ProtocolEncoder} implementation for those who don't have any
  * resources to dispose.
@@ -31,7 +33,7 @@
      * Override this method dispose all resources related with this encoder.
      * The default implementation does nothing.
      */
-    public void dispose() throws Exception
+    public void dispose( IoSession session ) throws Exception
     {
     }
 }



Mime
View raw message