directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r350148 - in /directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support: AbstractIoFilterChain.java IoFilterLifeCycleManager.java
Date Thu, 01 Dec 2005 04:13:22 GMT
Author: trustin
Date: Wed Nov 30 20:13:18 2005
New Revision: 350148

URL: http://svn.apache.org/viewcvs?rev=350148&view=rev
Log:
Modified AbstractFilterChain and IoFilterLifeCycleManager to call onPreAdd and onPreRemove

Modified:
    directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java
    directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/IoFilterLifeCycleManager.java

Modified: directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java?rev=350148&r1=350147&r2=350148&view=diff
==============================================================================
--- directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java
(original)
+++ directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java
Wed Nov 30 20:13:18 2005
@@ -313,7 +313,16 @@
         
         synchronized( lifeCycleManager )
         {
-            lifeCycleManager.initIfNeeded( filter );
+            lifeCycleManager.callInitIfNecessary( filter );
+
+            try
+            {
+                lifeCycleManager.callOnPreAdd( this, name, filter, newEntry.getNextFilter()
);
+            }
+            finally
+            {
+                lifeCycleManager.callDestroyIfNecessary( filter );
+            }
 
             prevEntry.nextEntry.prevEntry = newEntry;
             prevEntry.nextEntry = newEntry;
@@ -321,7 +330,7 @@
 
             try
             {
-                lifeCycleManager.add( this, name, filter, newEntry.getNextFilter() );
+                lifeCycleManager.callOnPostAdd( this, name, filter, newEntry.getNextFilter()
);
             }
             catch( IoFilterLifeCycleException e )
             {
@@ -330,25 +339,28 @@
             }
             finally
             {
-                lifeCycleManager.destroyIfNeeded( filter );
+                lifeCycleManager.callDestroyIfNecessary( filter );
             }
         }
     }
     
     private void deregister( EntryImpl entry )
     {
-        deregister0( entry );
-
         IoFilter filter = entry.getFilter();
         IoFilterLifeCycleManager lifeCycleManager = IoFilterLifeCycleManager.getInstance();
+        
+        lifeCycleManager.callOnPreRemove( this, entry.getName(), filter, entry.getNextFilter()
);
+        
+        deregister0( entry );
+
         try
         {
-            lifeCycleManager.remove(
+            lifeCycleManager.callOnPostRemove(
                     this, entry.getName(), filter, entry.getNextFilter() );
         }
         finally
         {
-            lifeCycleManager.destroyIfNeeded( filter );
+            lifeCycleManager.callDestroyIfNecessary( filter );
         }
     }
 

Modified: directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/IoFilterLifeCycleManager.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/IoFilterLifeCycleManager.java?rev=350148&r1=350147&r2=350148&view=diff
==============================================================================
--- directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/IoFilterLifeCycleManager.java
(original)
+++ directory/network/branches/chain_refactor/src/java/org/apache/mina/common/support/IoFilterLifeCycleManager.java
Wed Nov 30 20:13:18 2005
@@ -47,7 +47,7 @@
     {
     }
     
-    public synchronized void initIfNeeded( IoFilter filter )
+    public synchronized void callInitIfNecessary( IoFilter filter )
     {
         ReferenceCount count = ( ReferenceCount ) counts.get( filter );
         if( count == null )
@@ -61,12 +61,12 @@
             catch( Throwable t )
             {
                 throw new IoFilterLifeCycleException(
-                        "Failed to initilize: " + filter, t );
+                        "init(): " + filter, t );
             }
         }
     }
     
-    public synchronized void add( IoFilterChain chain, String name, IoFilter filter, NextFilter
nextFilter )
+    public synchronized void callOnPreAdd( IoFilterChain chain, String name, IoFilter filter,
NextFilter nextFilter )
     {
         ReferenceCount count = ( ReferenceCount ) counts.get( filter );
         if( count == null )
@@ -78,6 +78,46 @@
 
         try
         {
+            filter.onPreAdd( chain, name, nextFilter );
+        }
+        catch( Throwable t )
+        {
+            throw new IoFilterLifeCycleException(
+                    "onPreAdd(): " + name + ':' + filter + " in " +
+                    chain.getSession(), t );
+        }
+    }
+
+    public synchronized void callOnPreRemove( IoFilterChain chain, String name, IoFilter
filter, NextFilter nextFilter )
+    {
+        ReferenceCount count = ( ReferenceCount ) counts.get( filter );
+        if( count == null || count.get() == 0 )
+        {
+            return;
+        }
+
+        try
+        {
+            filter.onPreRemove( chain, name, nextFilter);
+        }
+        catch( Throwable t )
+        {
+            throw new IoFilterLifeCycleException(
+                    "onPreRemove(): " + name + ':' + filter + " in " +
+                    chain.getSession(), t );
+        }
+    }
+    
+    public synchronized void callOnPostAdd( IoFilterChain chain, String name, IoFilter filter,
NextFilter nextFilter )
+    {
+        ReferenceCount count = ( ReferenceCount ) counts.get( filter );
+        if( count == null )
+        {
+            throw new IllegalStateException();
+        }
+        
+        try
+        {
             filter.onPostAdd( chain, name, nextFilter );
         }
         catch( Throwable t )
@@ -86,12 +126,12 @@
             count.decrease();
 
             throw new IoFilterLifeCycleException(
-                    "Failed to add: " + name + ':' + filter + " in " +
+                    "onPostAdd(): " + name + ':' + filter + " in " +
                     chain.getSession(), t );
         }
     }
 
-    public synchronized void remove( IoFilterChain chain, String name, IoFilter filter, NextFilter
nextFilter )
+    public synchronized void callOnPostRemove( IoFilterChain chain, String name, IoFilter
filter, NextFilter nextFilter )
     {
         ReferenceCount count = ( ReferenceCount ) counts.get( filter );
         if( count == null || count.get() == 0 )
@@ -106,7 +146,7 @@
         catch( Throwable t )
         {
             throw new IoFilterLifeCycleException(
-                    "Failed to remove: " + name + ':' + filter + " in " +
+                    "onPostRemove(): " + name + ':' + filter + " in " +
                     chain.getSession(), t );
         }
         finally
@@ -115,7 +155,7 @@
         }
     }
 
-    public synchronized void destroyIfNeeded( IoFilter filter )
+    public synchronized void callDestroyIfNecessary( IoFilter filter )
     {
         ReferenceCount count = ( ReferenceCount ) counts.get( filter );
         if( count == null )



Mime
View raw message