mina-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r523143 - in /mina: branches/1.0/core/src/main/java/org/apache/mina/filter/codec/ branches/1.1/core/src/main/java/org/apache/mina/filter/codec/ trunk/core/src/main/java/org/apache/mina/filter/codec/
Date Wed, 28 Mar 2007 02:20:07 GMT
Author: trustin
Date: Tue Mar 27 19:20:04 2007
New Revision: 523143

URL: http://svn.apache.org/viewvc?view=rev&rev=523143
Log:
Fixed issue: DIRMINA-363 (Visibility problem in ProtocolCodecFilter)
* Added DECODER_LOCK attribute to store a per-session decoder lock
* Acquired appropriate lock to remove the visibility problem
* Added more JavaDoc comments to SynchronizedProtocol(Encoder|Decoder)


Modified:
    mina/branches/1.0/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
    mina/branches/1.0/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolDecoder.java
    mina/branches/1.0/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolEncoder.java
    mina/branches/1.1/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
    mina/branches/1.1/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolDecoder.java
    mina/branches/1.1/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolEncoder.java
    mina/trunk/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
    mina/trunk/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolDecoder.java
    mina/trunk/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolEncoder.java

Modified: mina/branches/1.0/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
URL: http://svn.apache.org/viewvc/mina/branches/1.0/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java?view=diff&rev=523143&r1=523142&r2=523143
==============================================================================
--- mina/branches/1.0/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
(original)
+++ mina/branches/1.0/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
Tue Mar 27 19:20:04 2007
@@ -44,6 +44,8 @@
     public static final String ENCODER = ProtocolCodecFilter.class.getName() + ".encoder";
     public static final String DECODER = ProtocolCodecFilter.class.getName() + ".decoder";
     
+    private static final String DECODER_LOCK = ProtocolCodecFilter.class.getName() + ".decoderLock";
+    
     private static final Class[] EMPTY_PARAMS = new Class[0];
     private static final ByteBuffer EMPTY_BUFFER = ByteBuffer.wrap( new byte[0] );
 
@@ -156,11 +158,15 @@
 
         ByteBuffer in = ( ByteBuffer ) message;
         ProtocolDecoder decoder = getDecoder( session );
+        Object decoderLock = getDecoderLock( session );
         ProtocolDecoderOutput decoderOut = getDecoderOut( session, nextFilter );
         
         try
         {
-            decoder.decode( session, in, decoderOut );
+            synchronized( decoderLock )
+            {
+                decoder.decode( session, in, decoderOut );
+            }
         }
         catch( Throwable t )
         {
@@ -295,6 +301,18 @@
             session.setAttribute( ENCODER, encoder );
         }
         return encoder;
+    }
+    
+    private Object getDecoderLock( IoSession session )
+    {
+        Object lock = session.getAttribute( DECODER_LOCK );
+        if( lock == null )
+        {
+            lock = new Object();
+            session.setAttribute( DECODER_LOCK, lock );
+        }
+        
+        return lock;
     }
     
     private ProtocolEncoderOutputImpl getEncoderOut( IoSession session, NextFilter nextFilter,
WriteRequest writeRequest )

Modified: mina/branches/1.0/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolDecoder.java
URL: http://svn.apache.org/viewvc/mina/branches/1.0/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolDecoder.java?view=diff&rev=523143&r1=523142&r2=523143
==============================================================================
--- mina/branches/1.0/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolDecoder.java
(original)
+++ mina/branches/1.0/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolDecoder.java
Tue Mar 27 19:20:04 2007
@@ -26,7 +26,10 @@
  * A {@link ProtocolDecoder} implementation which decorates an existing decoder
  * to be thread-safe.  Please be careful if you're going to use this decorator
  * because it can be a root of performance degradation in a multi-thread
- * environment.
+ * environment.  Also, by default, appropriate synchronization is done
+ * on a per-session basis by {@link ProtocolCodecFilter}.  Please use this
+ * decorator only when you need to synchronize on a per-decoder basis, which
+ * is not common.
  * 
  * @author The Apache Directory Project (mina-dev@directory.apache.org)
  * @version $Rev$, $Date$

Modified: mina/branches/1.0/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolEncoder.java
URL: http://svn.apache.org/viewvc/mina/branches/1.0/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolEncoder.java?view=diff&rev=523143&r1=523142&r2=523143
==============================================================================
--- mina/branches/1.0/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolEncoder.java
(original)
+++ mina/branches/1.0/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolEncoder.java
Tue Mar 27 19:20:04 2007
@@ -25,7 +25,9 @@
  * A {@link ProtocolEncoder} implementation which decorates an existing encoder
  * to be thread-safe.  Please be careful if you're going to use this decorator
  * because it can be a root of performance degradation in a multi-thread
- * environment.
+ * environment.  Please use this decorator only when you need to synchronize
+ * on a per-encoder basis instead of on a per-session basis, which is not
+ * common.
  * 
  * @author The Apache Directory Project (mina-dev@directory.apache.org)
  * @version $Rev$, $Date$

Modified: mina/branches/1.1/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
URL: http://svn.apache.org/viewvc/mina/branches/1.1/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java?view=diff&rev=523143&r1=523142&r2=523143
==============================================================================
--- mina/branches/1.1/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
(original)
+++ mina/branches/1.1/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
Tue Mar 27 19:20:04 2007
@@ -43,7 +43,9 @@
 {
     public static final String ENCODER = ProtocolCodecFilter.class.getName() + ".encoder";
     public static final String DECODER = ProtocolCodecFilter.class.getName() + ".decoder";
-
+    
+    private static final String DECODER_LOCK = ProtocolCodecFilter.class.getName() + ".decoderLock";
+    
     private static final Class[] EMPTY_PARAMS = new Class[0];
     private static final ByteBuffer EMPTY_BUFFER = ByteBuffer.wrap( new byte[0] );
 
@@ -83,7 +85,9 @@
         };
     }
 
-    public ProtocolCodecFilter( final Class encoderClass, final Class decoderClass )
+    public ProtocolCodecFilter(
+            final Class<? extends ProtocolEncoder> encoderClass,
+            final Class<? extends ProtocolDecoder> decoderClass )
     {
         if( encoderClass == null )
         {
@@ -122,12 +126,12 @@
         {
             public ProtocolEncoder getEncoder() throws Exception
             {
-                return ( ProtocolEncoder ) encoderClass.newInstance();
+                return encoderClass.newInstance();
             }
 
             public ProtocolDecoder getDecoder() throws Exception
             {
-                return ( ProtocolDecoder ) decoderClass.newInstance();
+                return decoderClass.newInstance();
             }
         };
     }
@@ -158,11 +162,15 @@
 
         ByteBuffer in = ( ByteBuffer ) message;
         ProtocolDecoder decoder = getDecoder( session );
+        Object decoderLock = getDecoderLock( session );
         ProtocolDecoderOutput decoderOut = getDecoderOut( session, nextFilter );
 
         try
         {
-            decoder.decode( session, in, decoderOut );
+            synchronized( decoderLock )
+            {
+                decoder.decode( session, in, decoderOut );
+            }
         }
         catch( Throwable t )
         {
@@ -318,6 +326,18 @@
         return decoder;
     }
 
+    private Object getDecoderLock( IoSession session )
+    {
+        Object lock = session.getAttribute( DECODER_LOCK );
+        if( lock == null )
+        {
+            lock = new Object();
+            session.setAttribute( DECODER_LOCK, lock );
+        }
+
+        return lock;
+    }
+    
     private ProtocolDecoderOutput getDecoderOut( IoSession session, NextFilter nextFilter
)
     {
         return new SimpleProtocolDecoderOutput( session, nextFilter );

Modified: mina/branches/1.1/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolDecoder.java
URL: http://svn.apache.org/viewvc/mina/branches/1.1/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolDecoder.java?view=diff&rev=523143&r1=523142&r2=523143
==============================================================================
--- mina/branches/1.1/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolDecoder.java
(original)
+++ mina/branches/1.1/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolDecoder.java
Tue Mar 27 19:20:04 2007
@@ -26,7 +26,10 @@
  * A {@link ProtocolDecoder} implementation which decorates an existing decoder
  * to be thread-safe.  Please be careful if you're going to use this decorator
  * because it can be a root of performance degradation in a multi-thread
- * environment.
+ * environment.  Also, by default, appropriate synchronization is done
+ * on a per-session basis by {@link ProtocolCodecFilter}.  Please use this
+ * decorator only when you need to synchronize on a per-decoder basis, which
+ * is not common.
  * 
  * @author The Apache Directory Project (mina-dev@directory.apache.org)
  * @version $Rev$, $Date$

Modified: mina/branches/1.1/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolEncoder.java
URL: http://svn.apache.org/viewvc/mina/branches/1.1/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolEncoder.java?view=diff&rev=523143&r1=523142&r2=523143
==============================================================================
--- mina/branches/1.1/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolEncoder.java
(original)
+++ mina/branches/1.1/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolEncoder.java
Tue Mar 27 19:20:04 2007
@@ -25,7 +25,9 @@
  * A {@link ProtocolEncoder} implementation which decorates an existing encoder
  * to be thread-safe.  Please be careful if you're going to use this decorator
  * because it can be a root of performance degradation in a multi-thread
- * environment.
+ * environment.  Please use this decorator only when you need to synchronize
+ * on a per-encoder basis instead of on a per-session basis, which is not
+ * common.
  * 
  * @author The Apache Directory Project (mina-dev@directory.apache.org)
  * @version $Rev$, $Date$

Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java?view=diff&rev=523143&r1=523142&r2=523143
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java Tue
Mar 27 19:20:04 2007
@@ -44,6 +44,8 @@
     public static final String ENCODER = ProtocolCodecFilter.class.getName() + ".encoder";
     public static final String DECODER = ProtocolCodecFilter.class.getName() + ".decoder";
     
+    private static final String DECODER_LOCK = ProtocolCodecFilter.class.getName() + ".decoderLock";
+    
     private static final Class[] EMPTY_PARAMS = new Class[0];
     private static final ByteBuffer EMPTY_BUFFER = ByteBuffer.wrap( new byte[0] );
 
@@ -158,11 +160,15 @@
 
         ByteBuffer in = ( ByteBuffer ) message;
         ProtocolDecoder decoder = getDecoder( session );
+        Object decoderLock = getDecoderLock( session );
         ProtocolDecoderOutput decoderOut = getDecoderOut( session, nextFilter );
         
         try
         {
-            decoder.decode( session, in, decoderOut );
+            synchronized( decoderLock )
+            {
+                decoder.decode( session, in, decoderOut );
+            }
         }
         catch( Throwable t )
         {
@@ -310,6 +316,18 @@
             session.setAttribute( DECODER, decoder );
         }
         return decoder;
+    }
+    
+    private Object getDecoderLock( IoSession session )
+    {
+        Object lock = session.getAttribute( DECODER_LOCK );
+        if( lock == null )
+        {
+            lock = new Object();
+            session.setAttribute( DECODER_LOCK, lock );
+        }
+
+        return lock;
     }
     
     private ProtocolDecoderOutput getDecoderOut( IoSession session, NextFilter nextFilter
)

Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolDecoder.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolDecoder.java?view=diff&rev=523143&r1=523142&r2=523143
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolDecoder.java
(original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolDecoder.java
Tue Mar 27 19:20:04 2007
@@ -26,7 +26,10 @@
  * A {@link ProtocolDecoder} implementation which decorates an existing decoder
  * to be thread-safe.  Please be careful if you're going to use this decorator
  * because it can be a root of performance degradation in a multi-thread
- * environment.
+ * environment.  Also, by default, appropriate synchronization is done
+ * on a per-session basis by {@link ProtocolCodecFilter}.  Please use this
+ * decorator only when you need to synchronize on a per-decoder basis, which
+ * is not common.
  * 
  * @author The Apache MINA Project (dev@mina.apache.org)
  * @version $Rev$, $Date$

Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolEncoder.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolEncoder.java?view=diff&rev=523143&r1=523142&r2=523143
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolEncoder.java
(original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/codec/SynchronizedProtocolEncoder.java
Tue Mar 27 19:20:04 2007
@@ -25,7 +25,9 @@
  * A {@link ProtocolEncoder} implementation which decorates an existing encoder
  * to be thread-safe.  Please be careful if you're going to use this decorator
  * because it can be a root of performance degradation in a multi-thread
- * environment.
+ * environment.  Please use this decorator only when you need to synchronize
+ * on a per-encoder basis instead of on a per-session basis, which is not
+ * common.
  * 
  * @author The Apache MINA Project (dev@mina.apache.org)
  * @version $Rev$, $Date$



Mime
View raw message