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/11/14 06:02:15 UTC

svn commit: r344036 - /directory/network/trunk/src/java/org/apache/mina/filter/BlacklistFilter.java

Author: trustin
Date: Sun Nov 13 21:02:11 2005
New Revision: 344036

URL: http://svn.apache.org/viewcvs?rev=344036&view=rev
Log:
Applied Niklas's BlacklistFilter patch

Modified:
    directory/network/trunk/src/java/org/apache/mina/filter/BlacklistFilter.java

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=344036&r1=344035&r2=344036&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 Sun Nov 13 21:02:11 2005
@@ -21,6 +21,7 @@
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.SocketAddress;
+import java.util.Collection;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -42,10 +43,63 @@
     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 );
     }
 
@@ -54,6 +108,8 @@
      */
     public synchronized void unblock( InetAddress address )
     {
+        if( address == null )
+            throw new NullPointerException( "address" );
         blacklist.remove( address );
     }