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/12/01 06:19:07 UTC
svn commit: r350169 [7/16] - in /directory/network:
branches/chain_refactor/src/java/org/apache/mina/common/
trunk/src/examples/org/apache/mina/examples/echoserver/
trunk/src/examples/org/apache/mina/examples/httpserver/
trunk/src/examples/org/apache/m...
Modified: directory/network/trunk/src/java/org/apache/mina/common/support/DefaultExceptionMonitor.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/common/support/DefaultExceptionMonitor.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/common/support/DefaultExceptionMonitor.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/common/support/DefaultExceptionMonitor.java Wed Nov 30 21:17:41 2005
@@ -1,44 +1,44 @@
-/*
- * @(#) $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.support;
-
-import org.apache.mina.common.ExceptionMonitor;
-import org.apache.mina.common.IoSessionManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * A default {@link ExceptionMonitor} implementation that logs uncaught
- * exceptions using {@link Logger}.
- * <p>
- * All {@link IoSessionManager}s have this implementation as a default exception
- * monitor.
- *
- * @author The Apache Directory Project (dev@directory.apache.org)
- * @version $Rev$, $Date$
- */
-public class DefaultExceptionMonitor implements ExceptionMonitor
-{
- private static final Logger log = LoggerFactory.getLogger( DefaultExceptionMonitor.class );
-
- public void exceptionCaught( Object source, Throwable cause )
- {
- log.warn( "Unexpected exception.", cause );
- }
+/*
+ * @(#) $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.support;
+
+import org.apache.mina.common.ExceptionMonitor;
+import org.apache.mina.common.IoSessionManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A default {@link ExceptionMonitor} implementation that logs uncaught
+ * exceptions using {@link Logger}.
+ * <p>
+ * All {@link IoSessionManager}s have this implementation as a default exception
+ * monitor.
+ *
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class DefaultExceptionMonitor implements ExceptionMonitor
+{
+ private static final Logger log = LoggerFactory.getLogger( DefaultExceptionMonitor.class );
+
+ public void exceptionCaught( Object source, Throwable cause )
+ {
+ log.warn( "Unexpected exception.", cause );
+ }
}
Modified: directory/network/trunk/src/java/org/apache/mina/common/support/DelegatedIoAcceptor.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/common/support/DelegatedIoAcceptor.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/common/support/DelegatedIoAcceptor.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/common/support/DelegatedIoAcceptor.java Wed Nov 30 21:17:41 2005
@@ -1,89 +1,113 @@
-/*
- * @(#) $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.support;
-
-import java.io.IOException;
-import java.net.SocketAddress;
-
-import org.apache.mina.common.ExceptionMonitor;
-import org.apache.mina.common.IoAcceptor;
-import org.apache.mina.common.IoFilterChain;
-import org.apache.mina.common.IoHandler;
-import org.apache.mina.common.IoSession;
-
-/**
- * A delegated {@link IoAcceptor} that wraps the other {@link IoAcceptor}.
- *
- * @author The Apache Directory Project (dev@directory.apache.org)
- * @version $Rev$, $Date$
- */
-public class DelegatedIoAcceptor implements IoAcceptor
-{
- protected final IoAcceptor delegate;
-
- /**
- * Creates a new instance.
- */
- protected DelegatedIoAcceptor( IoAcceptor delegate )
- {
- this.delegate = delegate;
- }
-
- public void bind( SocketAddress address, IoHandler handler ) throws IOException
- {
- delegate.bind( address, handler );
- }
-
- public void unbind( SocketAddress address )
- {
- delegate.unbind( address );
- }
-
- public IoSession newSession( SocketAddress remoteAddress, SocketAddress localAddress )
- {
- return delegate.newSession( remoteAddress, localAddress );
- }
-
- public IoFilterChain getFilterChain()
- {
- return delegate.getFilterChain();
- }
-
- public ExceptionMonitor getExceptionMonitor()
- {
- return delegate.getExceptionMonitor();
- }
-
- public void setExceptionMonitor( ExceptionMonitor monitor )
- {
- delegate.setExceptionMonitor( monitor );
- }
-
- /* TODO: DIRMINA-93
- public boolean isDisconnectClientsOnUnbind()
- {
- return delegate.isDisconnectClientsOnUnbind();
- }
-
- public void setDisconnectClientsOnUnbind( boolean disconnectClientsOnUnbind )
- {
- delegate.setDisconnectClientsOnUnbind( disconnectClientsOnUnbind );
- }
- */
-}
+/*
+ * @(#) $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.support;
+
+import java.io.IOException;
+import java.net.SocketAddress;
+
+import org.apache.mina.common.DefaultIoFilterChainBuilder;
+import org.apache.mina.common.ExceptionMonitor;
+import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.common.IoFilterChainBuilder;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoSession;
+
+/**
+ * A delegated {@link IoAcceptor} that wraps the other {@link IoAcceptor}.
+ *
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class DelegatedIoAcceptor implements IoAcceptor
+{
+ protected IoAcceptor delegate;
+
+ /**
+ * Creates a new instance.
+ */
+ protected DelegatedIoAcceptor()
+ {
+ }
+
+ /**
+ * Sets the delegate. This method should be invoked before any operations
+ * is requested.
+ */
+ protected void init( IoAcceptor delegate )
+ {
+ this.delegate = delegate;
+ }
+
+ public void bind( SocketAddress address, IoHandler handler ) throws IOException
+ {
+ delegate.bind( address, handler );
+ }
+
+ public void bind( SocketAddress address, IoHandler handler, IoFilterChainBuilder filterChainBuilder ) throws IOException
+ {
+ delegate.bind( address, handler, filterChainBuilder );
+ }
+
+ public void unbind( SocketAddress address )
+ {
+ delegate.unbind( address );
+ }
+
+ public IoSession newSession( SocketAddress remoteAddress, SocketAddress localAddress )
+ {
+ return delegate.newSession( remoteAddress, localAddress );
+ }
+
+ public ExceptionMonitor getExceptionMonitor()
+ {
+ return delegate.getExceptionMonitor();
+ }
+
+ public void setExceptionMonitor( ExceptionMonitor monitor )
+ {
+ delegate.setExceptionMonitor( monitor );
+ }
+
+ public IoFilterChainBuilder getFilterChainBuilder()
+ {
+ return delegate.getFilterChainBuilder();
+ }
+
+ public void setFilterChainBuilder( IoFilterChainBuilder builder )
+ {
+ delegate.setFilterChainBuilder( builder );
+ }
+
+ public DefaultIoFilterChainBuilder getFilterChain()
+ {
+ return delegate.getFilterChain();
+ }
+
+ /* TODO: DIRMINA-93
+ public boolean isDisconnectClientsOnUnbind()
+ {
+ return delegate.isDisconnectClientsOnUnbind();
+ }
+
+ public void setDisconnectClientsOnUnbind( boolean disconnectClientsOnUnbind )
+ {
+ delegate.setDisconnectClientsOnUnbind( disconnectClientsOnUnbind );
+ }
+ */
+}
Modified: directory/network/trunk/src/java/org/apache/mina/common/support/DelegatedIoConnector.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/common/support/DelegatedIoConnector.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/common/support/DelegatedIoConnector.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/common/support/DelegatedIoConnector.java Wed Nov 30 21:17:41 2005
@@ -1,88 +1,117 @@
-/*
- * @(#) $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.support;
-
-import java.io.IOException;
-import java.net.SocketAddress;
-
-import org.apache.mina.common.ConnectFuture;
-import org.apache.mina.common.ExceptionMonitor;
-import org.apache.mina.common.IoConnector;
-import org.apache.mina.common.IoFilterChain;
-import org.apache.mina.common.IoHandler;
-
-/**
- * A delegated {@link IoConnector} that wraps the other {@link IoConnector}.
- *
- * @author The Apache Directory Project (dev@directory.apache.org)
- * @version $Rev$, $Date$
- */
-public class DelegatedIoConnector implements IoConnector
-{
- protected final IoConnector delegate;
-
- /**
- * Creates a new instance.
- */
- protected DelegatedIoConnector( IoConnector delegate )
- {
- this.delegate = delegate;
- }
-
- public ConnectFuture connect( SocketAddress address, IoHandler handler ) throws IOException
- {
- return delegate.connect( address, handler );
- }
-
- public ConnectFuture connect( SocketAddress address, SocketAddress localAddress,
- IoHandler handler ) throws IOException
- {
- return delegate.connect( address, localAddress, handler );
- }
-
- public IoFilterChain getFilterChain()
- {
- return delegate.getFilterChain();
- }
-
- public ExceptionMonitor getExceptionMonitor()
- {
- return delegate.getExceptionMonitor();
- }
-
- public void setExceptionMonitor( ExceptionMonitor monitor )
- {
- delegate.setExceptionMonitor( monitor );
- }
-
- public int getConnectTimeout()
- {
- return delegate.getConnectTimeout();
- }
-
- public long getConnectTimeoutMillis()
- {
- return delegate.getConnectTimeoutMillis();
- }
-
- public void setConnectTimeout( int connectTimeout )
- {
- delegate.setConnectTimeout( connectTimeout );
- }
-}
+/*
+ * @(#) $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.support;
+
+import java.net.SocketAddress;
+
+import org.apache.mina.common.ConnectFuture;
+import org.apache.mina.common.DefaultIoFilterChainBuilder;
+import org.apache.mina.common.ExceptionMonitor;
+import org.apache.mina.common.IoConnector;
+import org.apache.mina.common.IoFilterChainBuilder;
+import org.apache.mina.common.IoHandler;
+
+/**
+ * A delegated {@link IoConnector} that wraps the other {@link IoConnector}.
+ *
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class DelegatedIoConnector implements IoConnector
+{
+ protected IoConnector delegate;
+
+ /**
+ * Creates a new instance.
+ */
+ protected DelegatedIoConnector()
+ {
+ }
+
+ /**
+ * Sets the delegate. This method should be invoked before any operation
+ * is requested.
+ */
+ protected void init( IoConnector delegate )
+ {
+ this.delegate = delegate;
+ }
+
+ public ConnectFuture connect( SocketAddress address, IoHandler handler )
+ {
+ return delegate.connect( address, handler );
+ }
+
+ public ConnectFuture connect( SocketAddress address, IoHandler handler, IoFilterChainBuilder filterChainBuilder )
+ {
+ return delegate.connect( address, handler, filterChainBuilder );
+ }
+
+ public ConnectFuture connect( SocketAddress address, SocketAddress localAddress,
+ IoHandler handler )
+ {
+ return delegate.connect( address, localAddress, handler );
+ }
+
+ public ConnectFuture connect( SocketAddress address, SocketAddress localAddress,
+ IoHandler handler, IoFilterChainBuilder filterChainBuilder )
+ {
+ return delegate.connect( address, localAddress, handler, filterChainBuilder );
+ }
+
+ public ExceptionMonitor getExceptionMonitor()
+ {
+ return delegate.getExceptionMonitor();
+ }
+
+ public void setExceptionMonitor( ExceptionMonitor monitor )
+ {
+ delegate.setExceptionMonitor( monitor );
+ }
+
+ public int getConnectTimeout()
+ {
+ return delegate.getConnectTimeout();
+ }
+
+ public long getConnectTimeoutMillis()
+ {
+ return delegate.getConnectTimeoutMillis();
+ }
+
+ public void setConnectTimeout( int connectTimeout )
+ {
+ delegate.setConnectTimeout( connectTimeout );
+ }
+
+ public IoFilterChainBuilder getFilterChainBuilder()
+ {
+ return delegate.getFilterChainBuilder();
+ }
+
+ public void setFilterChainBuilder( IoFilterChainBuilder builder )
+ {
+ delegate.setFilterChainBuilder( builder );
+ }
+
+ public DefaultIoFilterChainBuilder getFilterChain()
+ {
+ return delegate.getFilterChain();
+ }
+}
Added: directory/network/trunk/src/java/org/apache/mina/common/support/IoFilterLifeCycleManager.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/common/support/IoFilterLifeCycleManager.java?rev=350169&view=auto
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/common/support/IoFilterLifeCycleManager.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/common/support/IoFilterLifeCycleManager.java Wed Nov 30 21:17:41 2005
@@ -0,0 +1,200 @@
+/*
+ * @(#) $Id: IoFilterLifeCycleManager.java 350148 2005-12-01 04:13:18Z trustin $
+ *
+ * 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.support;
+
+import java.util.IdentityHashMap;
+import java.util.Map;
+
+import org.apache.mina.common.IoFilter;
+import org.apache.mina.common.IoFilterChain;
+import org.apache.mina.common.IoFilterLifeCycleException;
+import org.apache.mina.common.IoFilter.NextFilter;
+
+/**
+ * Manages the life cycle of {@link IoFilter}s globally.
+ *
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev: 350148 $, $Date: 2005-12-01 13:13:18 +0900 $
+ */
+public class IoFilterLifeCycleManager
+{
+ private static final IoFilterLifeCycleManager INSTANCE = new IoFilterLifeCycleManager();
+
+ public static IoFilterLifeCycleManager getInstance()
+ {
+ return INSTANCE;
+ }
+
+ private Map counts = new IdentityHashMap();
+
+ private IoFilterLifeCycleManager()
+ {
+ }
+
+ public synchronized void callInitIfNecessary( IoFilter filter )
+ {
+ ReferenceCount count = ( ReferenceCount ) counts.get( filter );
+ if( count == null )
+ {
+ count = new ReferenceCount();
+ counts.put( filter, count );
+ try
+ {
+ filter.init();
+ }
+ catch( Throwable t )
+ {
+ throw new IoFilterLifeCycleException(
+ "init(): " + filter, t );
+ }
+ }
+ }
+
+ public synchronized void callOnPreAdd( IoFilterChain chain, String name, IoFilter filter, NextFilter nextFilter )
+ {
+ ReferenceCount count = ( ReferenceCount ) counts.get( filter );
+ if( count == null )
+ {
+ throw new IllegalStateException();
+ }
+
+ count.increase();
+
+ 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 )
+ {
+ // Revert back the reference count.
+ count.decrease();
+
+ throw new IoFilterLifeCycleException(
+ "onPostAdd(): " + name + ':' + filter + " in " +
+ chain.getSession(), t );
+ }
+ }
+
+ public synchronized void callOnPostRemove( IoFilterChain chain, String name, IoFilter filter, NextFilter nextFilter )
+ {
+ ReferenceCount count = ( ReferenceCount ) counts.get( filter );
+ if( count == null || count.get() == 0 )
+ {
+ return;
+ }
+
+ try
+ {
+ filter.onPostRemove( chain, name, nextFilter);
+ }
+ catch( Throwable t )
+ {
+ throw new IoFilterLifeCycleException(
+ "onPostRemove(): " + name + ':' + filter + " in " +
+ chain.getSession(), t );
+ }
+ finally
+ {
+ count.decrease();
+ }
+ }
+
+ public synchronized void callDestroyIfNecessary( IoFilter filter )
+ {
+ ReferenceCount count = ( ReferenceCount ) counts.get( filter );
+ if( count == null )
+ {
+ return;
+ }
+
+ if( count.get() == 0 )
+ {
+ counts.remove( filter );
+ try
+ {
+ filter.destroy();
+ }
+ catch( Throwable t2 )
+ {
+ throw new IoFilterLifeCycleException( "Failed to destroy: " + filter, t2 );
+ }
+ }
+ }
+
+ /** Maintains the reference count of an {@link IoFilter}. */
+ private static class ReferenceCount
+ {
+ private int count;
+
+ public int get()
+ {
+ return count;
+ }
+
+ public int increase()
+ {
+ return count ++;
+ }
+
+ public int decrease()
+ {
+ return -- count;
+ }
+ }
+}
Modified: directory/network/trunk/src/java/org/apache/mina/filter/BlacklistFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/filter/BlacklistFilter.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/BlacklistFilter.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/filter/BlacklistFilter.java Wed Nov 30 21:17:41 2005
@@ -1,214 +1,214 @@
-/*
- * @(#) $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.filter;
-
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.apache.mina.common.IdleStatus;
-import org.apache.mina.common.IoFilter;
-import org.apache.mina.common.IoFilterAdapter;
-import org.apache.mina.common.IoSession;
-import org.apache.mina.util.SessionLog;
-
-/**
- * A {@link IoFilter} which blocks connections from blacklisted remote
- * address.
- *
- * @author The Apache Directory Project (dev@directory.apache.org)
- * @version $Rev$, $Date$
- */
-public class BlacklistFilter extends IoFilterAdapter
-{
- private final Set blacklist = new HashSet();
-
- /**
- * Sets the addresses to be blacklisted.
- *
- * NOTE: this call will remove any previously blacklisted addresses.
- *
- * @param addresses an array of addresses to be blacklisted.
- */
- public void setBlacklist( InetAddress[] addresses )
- {
- if( addresses == null )
- throw new NullPointerException( "addresses" );
- blacklist.clear();
- for( int i = 0; i < addresses.length; i++ )
- {
- InetAddress addr = addresses[ i ];
- if( addr == null )
- {
- throw new NullPointerException( "addresses[" + i + ']' );
- }
- blacklist.add( addr );
- }
- }
-
- /**
- * Sets the addresses to be blacklisted.
- *
- * NOTE: this call will remove any previously blacklisted addresses.
- *
- * @param addresses a collection of InetAddress objects representing the
- * addresses to be blacklisted.
- * @throws IllegalArgumentException if the specified collections contains
- * non-{@link InetAddress} objects.
- */
- public void setBlacklist( Collection addresses )
- {
- if( addresses == null )
- throw new NullPointerException( "addresses" );
-
- InetAddress[] inetAddresses = new InetAddress[ addresses.size() ];
- try
- {
- setBlacklist( ( InetAddress[] ) addresses.toArray( inetAddresses ) );
- }
- catch ( ArrayStoreException ase )
- {
- throw new IllegalArgumentException(
- "Collection of addresses must contain only " +
- "InetAddress instances", ase );
- }
- }
-
- /**
- * Blocks the specified endpoint.
- */
- public synchronized void block( InetAddress address )
- {
- if( address == null )
- throw new NullPointerException( "address" );
- blacklist.add( address );
- }
-
- /**
- * Unblocks the specified endpoint.
- */
- public synchronized void unblock( InetAddress address )
- {
- if( address == null )
- throw new NullPointerException( "address" );
- blacklist.remove( address );
- }
-
- public void sessionCreated( NextFilter nextFilter, IoSession session )
- {
- if( !isBlocked( session ) )
- {
- // forward if not blocked
- nextFilter.sessionCreated( session );
- }
- else
- {
- blockSession( session );
- }
- }
-
- public void sessionOpened( NextFilter nextFilter, IoSession session ) throws Exception
- {
- if( !isBlocked( session ) )
- {
- // forward if not blocked
- nextFilter.sessionOpened( session );
- }
- else
- {
- blockSession( session );
- }
- }
-
- public void sessionClosed( NextFilter nextFilter, IoSession session ) throws Exception
- {
- if( !isBlocked( session ) )
- {
- // forward if not blocked
- nextFilter.sessionClosed( session );
- }
- else
- {
- blockSession( session );
- }
- }
-
- public void sessionIdle( NextFilter nextFilter, IoSession session, IdleStatus status ) throws Exception
- {
- if( !isBlocked( session ) )
- {
- // forward if not blocked
- nextFilter.sessionIdle( session, status );
- }
- else
- {
- blockSession( session );
- }
- }
-
- public void messageReceived( NextFilter nextFilter, IoSession session, Object message )
- {
- if( !isBlocked( session ) )
- {
- // forward if not blocked
- nextFilter.messageReceived( session, message );
- }
- else
- {
- blockSession( session );
- }
- }
-
- public void messageSent( NextFilter nextFilter, IoSession session, Object message ) throws Exception
- {
- if( !isBlocked( session ) )
- {
- // forward if not blocked
- nextFilter.messageSent( session, message );
- }
- else
- {
- blockSession( session );
- }
- }
-
- private void blockSession( IoSession session )
- {
- SessionLog.info( session, "Remote address in the blacklist; closing." );
- session.close();
- }
-
- private boolean isBlocked( IoSession session )
- {
- SocketAddress remoteAddress = session.getRemoteAddress();
- if( remoteAddress instanceof InetSocketAddress )
- {
- if( blacklist.contains( ( ( InetSocketAddress ) remoteAddress )
- .getAddress() ) )
- {
- return true;
- }
- }
-
- return false;
- }
+/*
+ * @(#) $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.filter;
+
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.mina.common.IdleStatus;
+import org.apache.mina.common.IoFilter;
+import org.apache.mina.common.IoFilterAdapter;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.util.SessionLog;
+
+/**
+ * A {@link IoFilter} which blocks connections from blacklisted remote
+ * address.
+ *
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class BlacklistFilter extends IoFilterAdapter
+{
+ private final Set blacklist = new HashSet();
+
+ /**
+ * Sets the addresses to be blacklisted.
+ *
+ * NOTE: this call will remove any previously blacklisted addresses.
+ *
+ * @param addresses an array of addresses to be blacklisted.
+ */
+ public void setBlacklist( InetAddress[] addresses )
+ {
+ if( addresses == null )
+ throw new NullPointerException( "addresses" );
+ blacklist.clear();
+ for( int i = 0; i < addresses.length; i++ )
+ {
+ InetAddress addr = addresses[ i ];
+ if( addr == null )
+ {
+ throw new NullPointerException( "addresses[" + i + ']' );
+ }
+ blacklist.add( addr );
+ }
+ }
+
+ /**
+ * Sets the addresses to be blacklisted.
+ *
+ * NOTE: this call will remove any previously blacklisted addresses.
+ *
+ * @param addresses a collection of InetAddress objects representing the
+ * addresses to be blacklisted.
+ * @throws IllegalArgumentException if the specified collections contains
+ * non-{@link InetAddress} objects.
+ */
+ public void setBlacklist( Collection addresses )
+ {
+ if( addresses == null )
+ throw new NullPointerException( "addresses" );
+
+ InetAddress[] inetAddresses = new InetAddress[ addresses.size() ];
+ try
+ {
+ setBlacklist( ( InetAddress[] ) addresses.toArray( inetAddresses ) );
+ }
+ catch ( ArrayStoreException ase )
+ {
+ throw new IllegalArgumentException(
+ "Collection of addresses must contain only " +
+ "InetAddress instances", ase );
+ }
+ }
+
+ /**
+ * Blocks the specified endpoint.
+ */
+ public synchronized void block( InetAddress address )
+ {
+ if( address == null )
+ throw new NullPointerException( "address" );
+ blacklist.add( address );
+ }
+
+ /**
+ * Unblocks the specified endpoint.
+ */
+ public synchronized void unblock( InetAddress address )
+ {
+ if( address == null )
+ throw new NullPointerException( "address" );
+ blacklist.remove( address );
+ }
+
+ public void sessionCreated( NextFilter nextFilter, IoSession session )
+ {
+ if( !isBlocked( session ) )
+ {
+ // forward if not blocked
+ nextFilter.sessionCreated( session );
+ }
+ else
+ {
+ blockSession( session );
+ }
+ }
+
+ public void sessionOpened( NextFilter nextFilter, IoSession session ) throws Exception
+ {
+ if( !isBlocked( session ) )
+ {
+ // forward if not blocked
+ nextFilter.sessionOpened( session );
+ }
+ else
+ {
+ blockSession( session );
+ }
+ }
+
+ public void sessionClosed( NextFilter nextFilter, IoSession session ) throws Exception
+ {
+ if( !isBlocked( session ) )
+ {
+ // forward if not blocked
+ nextFilter.sessionClosed( session );
+ }
+ else
+ {
+ blockSession( session );
+ }
+ }
+
+ public void sessionIdle( NextFilter nextFilter, IoSession session, IdleStatus status ) throws Exception
+ {
+ if( !isBlocked( session ) )
+ {
+ // forward if not blocked
+ nextFilter.sessionIdle( session, status );
+ }
+ else
+ {
+ blockSession( session );
+ }
+ }
+
+ public void messageReceived( NextFilter nextFilter, IoSession session, Object message )
+ {
+ if( !isBlocked( session ) )
+ {
+ // forward if not blocked
+ nextFilter.messageReceived( session, message );
+ }
+ else
+ {
+ blockSession( session );
+ }
+ }
+
+ public void messageSent( NextFilter nextFilter, IoSession session, Object message ) throws Exception
+ {
+ if( !isBlocked( session ) )
+ {
+ // forward if not blocked
+ nextFilter.messageSent( session, message );
+ }
+ else
+ {
+ blockSession( session );
+ }
+ }
+
+ private void blockSession( IoSession session )
+ {
+ SessionLog.info( session, "Remote address in the blacklist; closing." );
+ session.close();
+ }
+
+ private boolean isBlocked( IoSession session )
+ {
+ SocketAddress remoteAddress = session.getRemoteAddress();
+ if( remoteAddress instanceof InetSocketAddress )
+ {
+ if( blacklist.contains( ( ( InetSocketAddress ) remoteAddress )
+ .getAddress() ) )
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
}
Modified: directory/network/trunk/src/java/org/apache/mina/filter/LoggingFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/filter/LoggingFilter.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/LoggingFilter.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/filter/LoggingFilter.java Wed Nov 30 21:17:41 2005
@@ -1,124 +1,107 @@
-/*
- * @(#) $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.filter;
-
-import org.apache.mina.common.CloseFuture;
-import org.apache.mina.common.IdleStatus;
-import org.apache.mina.common.IoFilter;
-import org.apache.mina.common.IoFilterChain;
-import org.apache.mina.common.IoSession;
-import org.apache.mina.util.SessionLog;
-import org.slf4j.Logger;
-
-/**
- * Logs all MINA protocol events to {@link Logger}.
- *
- * @author The Apache Directory Project (dev@directory.apache.org)
- * @version $Rev$, $Date$
- *
- * @see SessionLog
- */
-public class LoggingFilter implements IoFilter
-{
- /**
- * Session attribute key: prefix string
- */
- public static final String PREFIX = SessionLog.PREFIX;
-
- /**
- * Session attribute key: {@link Logger}
- */
- public static final String LOGGER = SessionLog.LOGGER;
-
- /**
- * Creates a new instance.
- */
- public LoggingFilter()
- {
- }
-
- public void init()
- {
- }
-
- public void destroy()
- {
- }
-
- public void sessionCreated( NextFilter nextFilter, IoSession session )
- {
- nextFilter.sessionCreated( session );
- }
-
- public void sessionOpened( NextFilter nextFilter, IoSession session )
- {
- SessionLog.info( session, "OPENED" );
- nextFilter.sessionOpened( session );
- }
-
- public void sessionClosed( NextFilter nextFilter, IoSession session )
- {
- SessionLog.info( session, "CLOSED" );
- nextFilter.sessionClosed( session );
- }
-
- public void sessionIdle( NextFilter nextFilter, IoSession session, IdleStatus status )
- {
- SessionLog.info( session, "IDLE: " + status );
- nextFilter.sessionIdle( session, status );
- }
-
- public void exceptionCaught( NextFilter nextFilter, IoSession session, Throwable cause )
- {
- SessionLog.error( session, "EXCEPTION:", cause );
- nextFilter.exceptionCaught( session, cause );
- }
-
- public void messageReceived( NextFilter nextFilter, IoSession session, Object message )
- {
- SessionLog.info( session, "RECEIVED: " + message );
- nextFilter.messageReceived( session, message );
- }
-
- public void messageSent( NextFilter nextFilter, IoSession session, Object message )
- {
- SessionLog.info( session, "SENT: " + message );
- nextFilter.messageSent( session, message );
- }
-
- public void filterWrite( NextFilter nextFilter, IoSession session, WriteRequest writeRequest )
- {
- SessionLog.info( session, "WRITE: " + writeRequest );
- nextFilter.filterWrite( session, writeRequest );
- }
-
- public void filterClose( NextFilter nextFilter, IoSession session, CloseFuture closeFuture ) throws Exception
- {
- SessionLog.info( session, "CLOSE" );
- nextFilter.filterClose( session, closeFuture );
- }
-
- public void init( IoFilterChain parent, NextFilter nextFilter ) throws Exception
- {
- }
-
- public void destroy( IoFilterChain parent, NextFilter nextFilter ) throws Exception
- {
- }
-}
+/*
+ * @(#) $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.filter;
+
+import org.apache.mina.common.CloseFuture;
+import org.apache.mina.common.IdleStatus;
+import org.apache.mina.common.IoFilterAdapter;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.util.SessionLog;
+import org.slf4j.Logger;
+
+/**
+ * Logs all MINA protocol events to {@link Logger}.
+ *
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ *
+ * @see SessionLog
+ */
+public class LoggingFilter extends IoFilterAdapter
+{
+ /**
+ * Session attribute key: prefix string
+ */
+ public static final String PREFIX = SessionLog.PREFIX;
+
+ /**
+ * Session attribute key: {@link Logger}
+ */
+ public static final String LOGGER = SessionLog.LOGGER;
+
+ /**
+ * Creates a new instance.
+ */
+ public LoggingFilter()
+ {
+ }
+
+ public void sessionCreated( NextFilter nextFilter, IoSession session )
+ {
+ nextFilter.sessionCreated( session );
+ }
+
+ public void sessionOpened( NextFilter nextFilter, IoSession session )
+ {
+ SessionLog.info( session, "OPENED" );
+ nextFilter.sessionOpened( session );
+ }
+
+ public void sessionClosed( NextFilter nextFilter, IoSession session )
+ {
+ SessionLog.info( session, "CLOSED" );
+ nextFilter.sessionClosed( session );
+ }
+
+ public void sessionIdle( NextFilter nextFilter, IoSession session, IdleStatus status )
+ {
+ SessionLog.info( session, "IDLE: " + status );
+ nextFilter.sessionIdle( session, status );
+ }
+
+ public void exceptionCaught( NextFilter nextFilter, IoSession session, Throwable cause )
+ {
+ SessionLog.error( session, "EXCEPTION:", cause );
+ nextFilter.exceptionCaught( session, cause );
+ }
+
+ public void messageReceived( NextFilter nextFilter, IoSession session, Object message )
+ {
+ SessionLog.info( session, "RECEIVED: " + message );
+ nextFilter.messageReceived( session, message );
+ }
+
+ public void messageSent( NextFilter nextFilter, IoSession session, Object message )
+ {
+ SessionLog.info( session, "SENT: " + message );
+ nextFilter.messageSent( session, message );
+ }
+
+ public void filterWrite( NextFilter nextFilter, IoSession session, WriteRequest writeRequest )
+ {
+ SessionLog.info( session, "WRITE: " + writeRequest );
+ nextFilter.filterWrite( session, writeRequest );
+ }
+
+ public void filterClose( NextFilter nextFilter, IoSession session, CloseFuture closeFuture ) throws Exception
+ {
+ SessionLog.info( session, "CLOSE" );
+ nextFilter.filterClose( session, closeFuture );
+ }
+}
Modified: directory/network/trunk/src/java/org/apache/mina/filter/SSLFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/filter/SSLFilter.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/SSLFilter.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/filter/SSLFilter.java Wed Nov 30 21:17:41 2005
@@ -113,10 +113,9 @@
*/
public static final SSLFilterMessage SESSION_UNSECURED = new SSLFilterMessage( "SESSION_UNSECURED" );
+ private static final String NEXT_FILTER = SSLFilter.class.getName() + ".NextFilter";
private static final String SSL_HANDLER = SSLFilter.class.getName() + ".SSLHandler";
- private IoFilterChain parent;
-
// SSL Context
private SSLContext sslContext;
@@ -179,7 +178,7 @@
}
}
- createSSLSessionHandler( parent.getNextFilter( this ), session );
+ createSSLSessionHandler( ( NextFilter ) session.getAttribute( NEXT_FILTER ), session );
return true;
}
}
@@ -228,7 +227,7 @@
throw new IllegalArgumentException( "Not managed by this filter." );
}
- NextFilter nextFilter = parent.getNextFilter( this );
+ NextFilter nextFilter = ( NextFilter ) session.getAttribute( NEXT_FILTER );
return initiateClosure( nextFilter, session );
}
}
@@ -331,19 +330,27 @@
this.enabledProtocols = protocols;
}
- public void init( IoFilterChain parent, NextFilter nextFilter ) throws SSLException
+ public void onPreAdd( IoFilterChain parent, String name, NextFilter nextFilter ) throws SSLException
+ {
+ if( parent.contains( SSLFilter.class ) )
+ {
+ throw new IllegalStateException( "A filter chain cannot contain more than one SSLFilter." );
+ }
+ }
+
+ public void onPostAdd( IoFilterChain parent, String name, NextFilter nextFilter ) throws SSLException
{
- this.parent = parent;
- Object managerOrSession = parent.getParent();
+ parent.getSession().setAttribute( NEXT_FILTER, nextFilter );
+ Object managerOrSession = parent.getSession();
if( managerOrSession instanceof IoSession )
{
createSSLSessionHandler( nextFilter, ( IoSession ) managerOrSession );
}
}
- public void destroy( IoFilterChain parent, NextFilter nextFilter )
+ public void onPreRemove( IoFilterChain parent, String name, NextFilter nextFilter ) throws SSLException
{
-
+ stopSSL( parent.getSession() ).join();
}
// IoFilter impl.