directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r165116 - in /directory/network/trunk/src/java/org/apache/mina: io/AbstractIoHandlerFilterChain.java protocol/AbstractProtocolHandlerFilterChain.java
Date Thu, 28 Apr 2005 08:35:07 GMT
Author: trustin
Date: Thu Apr 28 01:35:05 2005
New Revision: 165116

URL: http://svn.apache.org/viewcvs?rev=165116&view=rev
Log:
* Made Abstract(Io/Protocol)FilterChains more extensible

Modified:
    directory/network/trunk/src/java/org/apache/mina/io/AbstractIoHandlerFilterChain.java
    directory/network/trunk/src/java/org/apache/mina/protocol/AbstractProtocolHandlerFilterChain.java

Modified: directory/network/trunk/src/java/org/apache/mina/io/AbstractIoHandlerFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/AbstractIoHandlerFilterChain.java?rev=165116&r1=165115&r2=165116&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/AbstractIoHandlerFilterChain.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/io/AbstractIoHandlerFilterChain.java
Thu Apr 28 01:35:05 2005
@@ -50,94 +50,6 @@
  */
 public abstract class AbstractIoHandlerFilterChain implements IoHandlerFilterChain
 {
-    private final IoHandlerFilter HEAD_FILTER = new IoHandlerFilter()
-    {
-        public void sessionOpened( NextFilter nextFilter, IoSession session )
-        {
-            nextFilter.sessionOpened( session );
-        }
-
-        public void sessionClosed( NextFilter nextFilter, IoSession session )
-        {
-            nextFilter.sessionClosed( session );
-        }
-
-        public void sessionIdle( NextFilter nextFilter, IoSession session,
-                                IdleStatus status )
-        {
-            nextFilter.sessionIdle( session, status );
-        }
-
-        public void exceptionCaught( NextFilter nextFilter,
-                                    IoSession session, Throwable cause )
-        {
-            nextFilter.exceptionCaught( session, cause );
-        }
-
-        public void dataRead( NextFilter nextFilter, IoSession session,
-                             ByteBuffer buf )
-        {
-            nextFilter.dataRead( session, buf );
-        }
-
-        public void dataWritten( NextFilter nextFilter, IoSession session,
-                                Object marker )
-        {
-            nextFilter.dataWritten( session, marker );
-        }
-        
-        public void filterWrite( NextFilter nextFilter, IoSession session,
-                                 ByteBuffer buf, Object marker )
-        {
-            doWrite( session, buf, marker );
-        }
-    };
-    
-    private final IoHandlerFilter TAIL_FILTER = new IoHandlerFilter()
-    {
-        public void sessionOpened( NextFilter nextFilter, IoSession session )
-        {
-            session.getHandler().sessionOpened( session );
-        }
-
-        public void sessionClosed( NextFilter nextFilter, IoSession session )
-        {
-            session.getHandler().sessionClosed( session );
-        }
-
-        public void sessionIdle( NextFilter nextFilter, IoSession session,
-                                IdleStatus status )
-        {
-            session.getHandler().sessionIdle( session, status );
-        }
-
-        public void exceptionCaught( NextFilter nextFilter,
-                                    IoSession session, Throwable cause )
-        {
-            session.getHandler().exceptionCaught( session, cause );
-        }
-
-        public void dataRead( NextFilter nextFilter, IoSession session,
-                             ByteBuffer buf )
-        {
-            IoHandler handler = session.getHandler();
-            handler.dataRead( session, buf );
-            buf.release();
-        }
-
-        public void dataWritten( NextFilter nextFilter, IoSession session,
-                                Object marker )
-        {
-            session.getHandler().dataWritten( session, marker );
-        }
-
-        public void filterWrite( NextFilter nextFilter,
-                                 IoSession session, ByteBuffer buf, Object marker )
-        {
-            nextFilter.filterWrite( session, buf, marker );
-        }
-    };
-    
     private final Map name2entry = new HashMap();
 
     private final Map filter2entry = new IdentityHashMap();
@@ -148,9 +60,109 @@
 
     protected AbstractIoHandlerFilterChain()
     {
-        head = new Entry( null, null, "head", HEAD_FILTER );
-        tail = new Entry( head, null, "tail", TAIL_FILTER );
+        head = new Entry( null, null, "head", createHeadFilter() );
+        tail = new Entry( head, null, "tail", createTailFilter() );
         head.nextEntry = tail;
+    }
+    
+    /**
+     * Override this method to create custom head of this filter chain.
+     */
+    protected IoHandlerFilter createHeadFilter()
+    {
+        return new IoHandlerFilter()
+        {
+            public void sessionOpened( NextFilter nextFilter, IoSession session )
+            {
+                nextFilter.sessionOpened( session );
+            }
+
+            public void sessionClosed( NextFilter nextFilter, IoSession session )
+            {
+                nextFilter.sessionClosed( session );
+            }
+
+            public void sessionIdle( NextFilter nextFilter, IoSession session,
+                                    IdleStatus status )
+            {
+                nextFilter.sessionIdle( session, status );
+            }
+
+            public void exceptionCaught( NextFilter nextFilter,
+                                        IoSession session, Throwable cause )
+            {
+                nextFilter.exceptionCaught( session, cause );
+            }
+
+            public void dataRead( NextFilter nextFilter, IoSession session,
+                                 ByteBuffer buf )
+            {
+                nextFilter.dataRead( session, buf );
+            }
+
+            public void dataWritten( NextFilter nextFilter, IoSession session,
+                                    Object marker )
+            {
+                nextFilter.dataWritten( session, marker );
+            }
+            
+            public void filterWrite( NextFilter nextFilter, IoSession session,
+                                     ByteBuffer buf, Object marker )
+            {
+                doWrite( session, buf, marker );
+            }
+        };
+    }
+    
+    /**
+     * Override this method to create custom tail of this filter chain.
+     */
+    protected IoHandlerFilter createTailFilter()
+    {
+        return new IoHandlerFilter()
+        {
+            public void sessionOpened( NextFilter nextFilter, IoSession session )
+            {
+                session.getHandler().sessionOpened( session );
+            }
+
+            public void sessionClosed( NextFilter nextFilter, IoSession session )
+            {
+                session.getHandler().sessionClosed( session );
+            }
+
+            public void sessionIdle( NextFilter nextFilter, IoSession session,
+                                    IdleStatus status )
+            {
+                session.getHandler().sessionIdle( session, status );
+            }
+
+            public void exceptionCaught( NextFilter nextFilter,
+                                        IoSession session, Throwable cause )
+            {
+                session.getHandler().exceptionCaught( session, cause );
+            }
+
+            public void dataRead( NextFilter nextFilter, IoSession session,
+                                 ByteBuffer buf )
+            {
+                IoHandler handler = session.getHandler();
+                handler.dataRead( session, buf );
+                buf.release();
+            }
+
+            public void dataWritten( NextFilter nextFilter, IoSession session,
+                                    Object marker )
+            {
+                session.getHandler().dataWritten( session, marker );
+            }
+
+            public void filterWrite( NextFilter nextFilter,
+                                     IoSession session, ByteBuffer buf, Object marker )
+            {
+                nextFilter.filterWrite( session, buf, marker );
+            }
+        };
     }
     
     public IoHandlerFilter getChild( String name )

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/AbstractProtocolHandlerFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/AbstractProtocolHandlerFilterChain.java?rev=165116&r1=165115&r2=165116&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/AbstractProtocolHandlerFilterChain.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/AbstractProtocolHandlerFilterChain.java
Thu Apr 28 01:35:05 2005
@@ -49,93 +49,6 @@
  */
 public abstract class AbstractProtocolHandlerFilterChain implements ProtocolHandlerFilterChain
 {
-    private final ProtocolHandlerFilter HEAD_FILTER = new ProtocolHandlerFilter()
-    {
-        public void sessionOpened( NextFilter nextFilter, ProtocolSession session )
-        {
-            nextFilter.sessionOpened( session );
-        }
-
-        public void sessionClosed( NextFilter nextFilter, ProtocolSession session )
-        {
-            nextFilter.sessionClosed( session );
-        }
-
-        public void sessionIdle( NextFilter nextFilter, ProtocolSession session,
-                                IdleStatus status )
-        {
-            nextFilter.sessionIdle( session, status );
-        }
-
-        public void exceptionCaught( NextFilter nextFilter,
-                                    ProtocolSession session, Throwable cause )
-        {
-            nextFilter.exceptionCaught( session, cause );
-        }
-
-        public void messageReceived( NextFilter nextFilter, ProtocolSession session,
-                                     Object message )
-        {
-            nextFilter.messageReceived( session, message );
-        }
-
-        public void messageSent( NextFilter nextFilter, ProtocolSession session,
-                                 Object message )
-        {
-            nextFilter.messageSent( session, message );
-        }
-        
-        public void filterWrite( NextFilter nextFilter, ProtocolSession session,
-                                 Object message )
-        {
-            doWrite( session, message );
-        }
-    };
-    
-    private final ProtocolHandlerFilter TAIL_FILTER = new ProtocolHandlerFilter()
-    {
-        public void sessionOpened( NextFilter nextFilter, ProtocolSession session )
-        {
-            session.getHandler().sessionOpened( session );
-        }
-
-        public void sessionClosed( NextFilter nextFilter, ProtocolSession session )
-        {
-            session.getHandler().sessionClosed( session );
-        }
-
-        public void sessionIdle( NextFilter nextFilter, ProtocolSession session,
-                                IdleStatus status )
-        {
-            session.getHandler().sessionIdle( session, status );
-        }
-
-        public void exceptionCaught( NextFilter nextFilter,
-                                    ProtocolSession session, Throwable cause )
-        {
-            session.getHandler().exceptionCaught( session, cause );
-        }
-
-        public void messageReceived( NextFilter nextFilter, ProtocolSession session,
-                                     Object message )
-        {
-            ProtocolHandler handler = session.getHandler();
-            handler.messageReceived( session, message );
-        }
-
-        public void messageSent( NextFilter nextFilter, ProtocolSession session,
-                                 Object message )
-        {
-            session.getHandler().messageSent( session, message );
-        }
-
-        public void filterWrite( NextFilter nextFilter,
-                                 ProtocolSession session, Object message )
-        {
-            nextFilter.filterWrite( session, message );
-        }
-    };
-
     private final Map name2entry = new HashMap();
 
     private final Map filter2entry = new IdentityHashMap();
@@ -146,9 +59,108 @@
 
     protected AbstractProtocolHandlerFilterChain()
     {
-        head = new Entry( null, null, "head", HEAD_FILTER );
-        tail = new Entry( head, null, "tail", TAIL_FILTER );
+        head = new Entry( null, null, "head", createHeadFilter() );
+        tail = new Entry( head, null, "tail", createTailFilter() );
         head.nextEntry = tail;
+    }
+    
+    /**
+     * Override this method to create custom head of this filter chain.
+     */
+    protected ProtocolHandlerFilter createHeadFilter()
+    {
+        return new ProtocolHandlerFilter()
+        {
+            public void sessionOpened( NextFilter nextFilter, ProtocolSession session )
+            {
+                nextFilter.sessionOpened( session );
+            }
+
+            public void sessionClosed( NextFilter nextFilter, ProtocolSession session )
+            {
+                nextFilter.sessionClosed( session );
+            }
+
+            public void sessionIdle( NextFilter nextFilter, ProtocolSession session,
+                                    IdleStatus status )
+            {
+                nextFilter.sessionIdle( session, status );
+            }
+
+            public void exceptionCaught( NextFilter nextFilter,
+                                        ProtocolSession session, Throwable cause )
+            {
+                nextFilter.exceptionCaught( session, cause );
+            }
+
+            public void messageReceived( NextFilter nextFilter, ProtocolSession session,
+                                         Object message )
+            {
+                nextFilter.messageReceived( session, message );
+            }
+
+            public void messageSent( NextFilter nextFilter, ProtocolSession session,
+                                     Object message )
+            {
+                nextFilter.messageSent( session, message );
+            }
+            
+            public void filterWrite( NextFilter nextFilter, ProtocolSession session,
+                                     Object message )
+            {
+                doWrite( session, message );
+            }
+        };
+    }
+    
+    /**
+     * Override this method to create custom head of this filter chain.
+     */
+    protected ProtocolHandlerFilter createTailFilter()
+    {
+        return new ProtocolHandlerFilter()
+        {
+            public void sessionOpened( NextFilter nextFilter, ProtocolSession session )
+            {
+                session.getHandler().sessionOpened( session );
+            }
+
+            public void sessionClosed( NextFilter nextFilter, ProtocolSession session )
+            {
+                session.getHandler().sessionClosed( session );
+            }
+
+            public void sessionIdle( NextFilter nextFilter, ProtocolSession session,
+                                    IdleStatus status )
+            {
+                session.getHandler().sessionIdle( session, status );
+            }
+
+            public void exceptionCaught( NextFilter nextFilter,
+                                        ProtocolSession session, Throwable cause )
+            {
+                session.getHandler().exceptionCaught( session, cause );
+            }
+
+            public void messageReceived( NextFilter nextFilter, ProtocolSession session,
+                                         Object message )
+            {
+                ProtocolHandler handler = session.getHandler();
+                handler.messageReceived( session, message );
+            }
+
+            public void messageSent( NextFilter nextFilter, ProtocolSession session,
+                                     Object message )
+            {
+                session.getHandler().messageSent( session, message );
+            }
+
+            public void filterWrite( NextFilter nextFilter,
+                                     ProtocolSession session, Object message )
+            {
+                nextFilter.filterWrite( session, message );
+            }
+        };
     }
     
     public ProtocolHandlerFilter getChild( String name )



Mime
View raw message