You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by tr...@apache.org on 2005/10/26 08:44:21 UTC
svn commit: r328578 - in
/directory/network/trunk/src/java/org/apache/mina/common:
IoFilterChain.java support/AbstractIoFilterChain.java
Author: trustin
Date: Tue Oct 25 23:44:17 2005
New Revision: 328578
URL: http://svn.apache.org/viewcvs?rev=328578&view=rev
Log:
* Added extra utility methods to IoFilterChain
* Moved JavaDoc from AbstractIoFilterChain to IoFilterChain
Modified:
directory/network/trunk/src/java/org/apache/mina/common/IoFilterChain.java
directory/network/trunk/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java
Modified: directory/network/trunk/src/java/org/apache/mina/common/IoFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/common/IoFilterChain.java?rev=328578&r1=328577&r2=328578&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/common/IoFilterChain.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/common/IoFilterChain.java Tue Oct 25 23:44:17 2005
@@ -1,17 +1,119 @@
+/*
+ * @(#) $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.common;
import java.util.List;
+import org.apache.mina.common.IoFilter.NextFilter;
+/**
+ * A container of {@link IoFilter}s that forwards {@link IoHandler} events
+ * to the consisting filters and terminal {@link IoHandler} sequentially.
+ *
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
public interface IoFilterChain {
+ /**
+ * Returns the parent of this chain.
+ * @return {@link IoSessionManager} or {@link IoSession}
+ */
Object getParent();
+
+ /**
+ * Returns the {@link IoFilter} with the specified <tt>name</tt> in this chain.
+ * @return <tt>null</tt> if there's no such filter in this chain
+ */
IoFilter get( String name );
+
+ /**
+ * Returns the name of the specified {@link IoFilter} in this chain.
+ * @return <tt>null</tt> if there's no such filter in this chain.
+ */
+
+ String getName( IoFilter filter );
+
+ /**
+ * Returns the list of all filters this chain contains.
+ */
List getAll();
+
+ /**
+ * Returns the reversed list of all filters this chain contains.
+ */
List getAllReversed();
+
+ /**
+ * Adds the specified filter with the specified name at the beginning of this chain.
+ * @throws Exception if {@link IoFilter#filterAdded(NextFilter, Object)} thrown an exception.
+ */
void addFirst( String name, IoFilter filter ) throws Exception;
+
+ /**
+ * Adds the specified filter with the specified name at the end of this chain.
+ * @throws Exception if {@link IoFilter#filterAdded(NextFilter, Object)} thrown an exception.
+ */
void addLast( String name, IoFilter filter ) throws Exception;
+
+ /**
+ * Adds the specified filter with the specified name just before the filter whose name is
+ * <code>baseName</code> in this chain.
+ * @throws Exception if {@link IoFilter#filterAdded(NextFilter, Object)} thrown an exception.
+ */
void addBefore( String baseName, String name, IoFilter filter ) throws Exception;
+
+ /**
+ * Adds the specified filter with the specified name just before the specified
+ * <code>baseFilter</code> in this chain.
+ * @throws Exception if {@link IoFilter#filterAdded(NextFilter, Object)} thrown an exception.
+ */
+ void addBefore( IoFilter baseFilter, String name, IoFilter filter ) throws Exception;
+
+ /**
+ * Adds the specified filter with the specified name just after the filter whose name is
+ * <code>baseName</code> in this chain.
+ * @throws Exception if {@link IoFilter#filterAdded(NextFilter, Object)} thrown an exception.
+ */
void addAfter( String baseName, String name, IoFilter filter ) throws Exception;
+
+ /**
+ * Adds the specified filter with the specified name just after the
+ * specified <tt>baseFilter</tt> in this chain.
+ * @throws Exception if {@link IoFilter#filterAdded(NextFilter, Object)} thrown an exception.
+ */
+ void addAfter( IoFilter baseFilter, String name, IoFilter filter ) throws Exception;
+
+ /**
+ * Removes the filter with the specified name from this chain.
+ * @throws Exception if {@link IoFilter#filterRemoved(NextFilter, Object)} thrown an exception.
+ */
IoFilter remove( String name ) throws Exception;
+
+ /**
+ * Removes the specifiec <tt>filter</tt> from this chain.
+ * @throws Exception if {@link IoFilter#filterRemoved(NextFilter, Object)} thrown an exception.
+ */
+ void remove( IoFilter filter ) throws Exception;
+
+ /**
+ * Removes all filters added to this chain.
+ * @throws Exception if {@link IoFilter#filterRemoved(NextFilter, Object)} thrown an exception.
+ */
void clear() throws Exception;
}
Modified: directory/network/trunk/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java?rev=328578&r1=328577&r2=328578&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/common/support/AbstractIoFilterChain.java Tue Oct 25 23:44:17 2005
@@ -38,13 +38,6 @@
* An abstract implementation of {@link IoFilterChain} that provides
* common operations for developers to extend protocol layer.
* <p>
- * All methods has been implemented. The list of filters is maintained
- * as a doublely linked list. You can fire any MINA events which is filtered
- * by this chain using these public methods:
- * <ul>
- * <li></li>
- * </ul>
- *
* The only method a developer should implement is
* {@link #doWrite(IoSession, WriteRequest)}. This method is invoked
* when filter chain is evaluated for
@@ -257,10 +250,17 @@
return e.filter;
}
- /**
- * Adds the specified interceptor with the specified name at the beginning of this chain.
- * @throws Exception if {@link IoFilter#filterAdded(NextFilter, Object)} thrown an exception.
- */
+ public String getName( IoFilter filter )
+ {
+ Entry e = ( Entry ) filter2entry.get( filter );
+ if( e == null )
+ {
+ return null;
+ }
+
+ return e.name;
+ }
+
public synchronized void addFirst( String name,
IoFilter filter ) throws Exception
{
@@ -268,11 +268,6 @@
register( head, name, filter );
}
-
- /**
- * Adds the specified interceptor with the specified name at the end of this chain.
- * @throws Exception if {@link IoFilter#filterAdded(NextFilter, Object)} thrown an exception.
- */
public synchronized void addLast( String name,
IoFilter filter ) throws Exception
{
@@ -280,12 +275,6 @@
register( tail.prevEntry, name, filter );
}
-
- /**
- * Adds the specified interceptor with the specified name just before the interceptor whose name is
- * <code>baseName</code> in this chain.
- * @throws Exception if {@link IoFilter#filterAdded(NextFilter, Object)} thrown an exception.
- */
public synchronized void addBefore( String baseName,
String name,
IoFilter filter ) throws Exception
@@ -295,12 +284,15 @@
register( baseEntry, name, filter );
}
+ public synchronized void addBefore( IoFilter baseFilter,
+ String name,
+ IoFilter filter ) throws Exception
+ {
+ Entry baseEntry = getEntry( baseFilter );
+ checkAddable( name );
+ register( baseEntry, name, filter );
+ }
- /**
- * Adds the specified interceptor with the specified name just after the interceptor whose name is
- * <code>baseName</code> in this chain.
- * @throws Exception if {@link IoFilter#filterAdded(NextFilter, Object)} thrown an exception.
- */
public synchronized void addAfter( String baseName,
String name,
IoFilter filter ) throws Exception
@@ -310,34 +302,28 @@
register( baseEntry.prevEntry, name, filter );
}
+ public synchronized void addAfter( IoFilter baseFilter,
+ String name,
+ IoFilter filter ) throws Exception
+ {
+ Entry baseEntry = getEntry( baseFilter );
+ checkAddable( name );
+ register( baseEntry.prevEntry, name, filter );
+ }
- /**
- * Removes the interceptor with the specified name from this chain.
- * @throws Exception if {@link IoFilter#filterRemoved(NextFilter, Object)} thrown an exception.
- */
public synchronized IoFilter remove( String name ) throws Exception
{
Entry entry = checkOldName( name );
-
- Entry prevEntry = entry.prevEntry;
- Entry nextEntry = entry.nextEntry;
- prevEntry.nextEntry = nextEntry;
- nextEntry.prevEntry = prevEntry;
-
- name2entry.remove( name );
- IoFilter filter = entry.filter;
- filter2entry.remove( filter );
-
- filter.filterRemoved( entry.nextFilter, parent );
-
- return filter;
+ deregister( entry );
+ return entry.filter;
}
+ public synchronized void remove( IoFilter filter ) throws Exception
+ {
+ Entry entry = getEntry( filter );
+ deregister( entry );
+ }
- /**
- * Removes all interceptors added to this chain.
- * @throws Exception if {@link IoFilter#filterRemoved(NextFilter, Object)} thrown an exception.
- */
public synchronized void clear() throws Exception
{
Iterator it = new ArrayList( name2entry.keySet() ).iterator();
@@ -358,18 +344,44 @@
name2entry.put( name, newEntry );
filter2entry.put( filter, newEntry );
}
+
+ private void deregister( Entry entry ) throws Exception
+ {
+ Entry prevEntry = entry.prevEntry;
+ Entry nextEntry = entry.nextEntry;
+ prevEntry.nextEntry = nextEntry;
+ nextEntry.prevEntry = prevEntry;
+
+ name2entry.remove( entry.name );
+ IoFilter filter = entry.filter;
+ filter2entry.remove( filter );
+
+ filter.filterRemoved( entry.nextFilter, parent );
+ }
+
+ private Entry getEntry( IoFilter filter )
+ {
+ Entry entry = ( Entry ) filter2entry.get( filter );
+ if( entry == null )
+ {
+ throw new IllegalArgumentException(
+ "The specified filter doesn't belong to this filter chain." );
+ }
+
+ return entry;
+ }
/**
- * Throws an exception when the specified interceptor name is not registered in this chain.
+ * Throws an exception when the specified filter name is not registered in this chain.
*
- * @return An interceptor entry with the specified name.
+ * @return An filter entry with the specified name.
*/
private Entry checkOldName( String baseName )
{
Entry e = ( Entry ) name2entry.get( baseName );
if ( e == null )
{
- throw new IllegalArgumentException( "Unknown interceptor name:" +
+ throw new IllegalArgumentException( "Unknown filter name:" +
baseName );
}
return e;
@@ -377,13 +389,13 @@
/**
- * Checks the specified interceptor name is already taken and throws an exception if already taken.
+ * Checks the specified filter name is already taken and throws an exception if already taken.
*/
private void checkAddable( String name )
{
if ( name2entry.containsKey( name ) )
{
- throw new IllegalArgumentException( "Other interceptor is using name '" + name + "'" );
+ throw new IllegalArgumentException( "Other filter is using the same name '" + name + "'" );
}
}