directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r359355 [1/4] - in /directory/network/trunk: ./ src/java/org/apache/mina/common/ src/java/org/apache/mina/transport/socket/nio/support/ src/java/org/apache/mina/transport/vmpipe/support/ src/test/org/apache/mina/common/ xdocs/
Date Wed, 28 Dec 2005 02:49:51 GMT
Author: trustin
Date: Tue Dec 27 18:49:31 2005
New Revision: 359355

URL: http://svn.apache.org/viewcvs?rev=359355&view=rev
Log:
Converted DOS text files into UNIX text file format


Modified:
    directory/network/trunk/project.xml
    directory/network/trunk/src/java/org/apache/mina/common/DefaultIoFilterChainBuilder.java
    directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
    directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java
    directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramFilterChain.java
    directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketAcceptorDelegate.java
    directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketConnectorDelegate.java
    directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketFilterChain.java
    directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketIoProcessor.java
    directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketSessionImpl.java
    directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeFilterChain.java
    directory/network/trunk/src/test/org/apache/mina/common/DefaultIoFilterChainBuilderTest.java
    directory/network/trunk/xdocs/features.xml
    directory/network/trunk/xdocs/getting_started.xml
    directory/network/trunk/xdocs/history.xml
    directory/network/trunk/xdocs/index.xml
    directory/network/trunk/xdocs/navigation.xml
    directory/network/trunk/xdocs/testimonials.xml

Modified: directory/network/trunk/project.xml
URL: http://svn.apache.org/viewcvs/directory/network/trunk/project.xml?rev=359355&r1=359354&r2=359355&view=diff
==============================================================================
--- directory/network/trunk/project.xml (original)
+++ directory/network/trunk/project.xml Tue Dec 27 18:49:31 2005
@@ -1,226 +1,226 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<project>
-
-  <groupId>directory-network</groupId>
-  <id>mina</id>
-  <name>MINA</name>
-  <package>org.apache.mina</package>
-  <currentVersion>0.9.1-SNAPSHOT</currentVersion>
-  <inceptionYear>2004</inceptionYear>
-
-  <logo>http://directory.apache.org/images/apache-directory-logo.png</logo>
-  <url>http://directory.apache.org/</url>
-
-  <issueTrackingUrl>
-    http://issues.apache.org/jira/
-  </issueTrackingUrl>
-  <siteAddress>minotaur.apache.org</siteAddress>
-  <siteDirectory>
-    /www/directory.apache.org/subprojects/network
-  </siteDirectory>
-  <distributionDirectory>
-    /www/cvs.apache.org/dist/directory
-  </distributionDirectory>
-
-  <developers>
-    <developer>
-      <name>Trustin Lee</name>
-      <id>trustin</id>
-      <email>trustin@gmail.com</email>
-      <organization>Solarsis LLC</organization>
-      <url>http://gleamynode.net/</url>
-      <timezone>+9</timezone>
-    </developer>
-    <developer>
-      <name>Niklas Therning</name>
-      <id>niklas</id>
-      <email>niklas(at)trillian(dot)se</email>
-      <organization>Trillian AB</organization>
-      <url>http://therning.org/niklas</url>
-      <timezone>+1</timezone>
-    </developer>
-  </developers>
-  <contributors>
-    <contributor>
-      <name>Jan Andersson</name>
-    </contributor>
-    <contributor>
-      <name>Vinod Panicker</name>
-    </contributor>
-  </contributors>
-
-  <repository>
-    <connection>
-      scm:svn:http://svn.apache.org/repos/asf/directory/network/trunk
-    </connection>
-    <url>
-      http://svn.apache.org/viewcvs.cgi/directory/network/trunk/?root=Apache-SVN
-    </url>
-    <developerConnection>
-      scm:svn:https://svn.apache.org/repos/asf/directory/network/trunk
-    </developerConnection>
-  </repository>
-
-  <gumpRepositoryId>directory</gumpRepositoryId>
-
-  <shortDescription>
-    A Multipurpose Infrastructure for Network Applications
-  </shortDescription>
-
-  <description>
-    MINA (Multipurpose Infrastructure for Network Applications) is a
-    network application framework which helps users develop high
-    performance and high scalability network applications easily.
-  </description>
-
-  <mailingLists>
-    <mailingList>
-      <name>Apache Directory Developement - use [mina] prefix</name>
-      <subscribe>
-        dev-subscribe@directory.apache.org
-      </subscribe>
-      <unsubscribe>
-        dev-unsubscribe@directory.apache.org
-      </unsubscribe>
-      <archive>
-        http://www.archivum.info/dev@directory.apache.org/
-      </archive>
-    </mailingList>
-  </mailingLists>
-
-  <licenses>
-    <license>
-      <name>Apache 2.0 License</name>
-      <url>http://www.apache.org/licenses/LICENSE-2.0</url>
-      <distribution>repo</distribution>
-    </license>
-  </licenses>
-
-  <dependencies>
-
-    <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-simple</artifactId>
-      <version>1.0-beta9</version>
-      <url>http://www.slf4j.org/</url>
-    </dependency>
-
-    <dependency>
-      <groupId>springframework</groupId>
-      <artifactId>spring-core</artifactId>
-      <version>1.2.5</version>
-      <url>http://www.springframework.org/</url>
-    </dependency>
-
-    <dependency>
-      <groupId>springframework</groupId>
-      <artifactId>spring-beans</artifactId>
-      <version>1.2.5</version>
-      <url>http://www.springframework.org/</url>
-    </dependency>
-
-    <!-- ========================================================= -->
-    <!-- Dependencies required for running test cases and examples -->
-    <!-- ========================================================= -->
-
-    <dependency>
-      <groupId>commons-net</groupId>
-      <artifactId>commons-net</artifactId>
-      <version>1.3.0</version>
-      <url>http://jakarta.apache.org/commons/net/</url>
-    </dependency>
-
-    <dependency>
-      <groupId>easymock</groupId>
-      <artifactId>easymock</artifactId>
-      <version>1.2_Java1.3</version>
-      <url>http://www.easymock.org/</url>
-    </dependency>
-    
-    <dependency>
-      <groupId>easymock</groupId>
-      <artifactId>easymockclassextension</artifactId>
-      <version>1.2</version>
-      <url>http://www.easymock.org/</url>
-    </dependency>
-    
-    <dependency>
-      <groupId>cglib</groupId>
-      <artifactId>cglib-nodep</artifactId>
-      <version>2.1</version>
-      <url>http://cglib.sourceforge.net/</url>
-    </dependency>
-
-    <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>jcl104-over-slf4j</artifactId>
-      <version>1.0-beta9</version>
-      <url>http://www.slf4j.org/</url>
-    </dependency>
-    
-    <dependency>
-      <groupId>emma</groupId>
-      <artifactId>emma</artifactId>
-      <version>2.0.latest</version>
-      <url>http://emma.sourceforge.net/</url>
-    </dependency>
-
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <version>3.8.1</version>
-      <url>http://junit.org/</url>
-    </dependency>
-
-    <dependency>
-      <groupId>emma</groupId>
-      <artifactId>maven-emma-plugin</artifactId>
-      <version>0.4</version>
-      <url>http://emma.sourceforge.net/</url>
-      <type>plugin</type>
-    </dependency>
-    
-    <dependency>
-      <artifactId>maven-site-plugin</artifactId>
-      <groupId>maven</groupId>
-      <version>1.6.1</version>
-      <type>plugin</type>
-    </dependency>
-
-  </dependencies>
-
-
-  <build>
-    <nagEmailAddress>dev@directory.apache.org</nagEmailAddress>
-    <sourceDirectory>${basedir}/src/java</sourceDirectory>
-    <sourceModifications>
-      <sourceModification>
-        <className>javax.swing.SwingGraphics</className>
-        <excludes>
-          <exclude>org/apache/mina/io/filter/SSLFilter.java</exclude>
-          <exclude>org/apache/mina/io/filter/SSLHandler.java</exclude>
-          <exclude>org/apache/mina/io/filter/SSLByteBufferPool.java</exclude>
-        </excludes>
-      </sourceModification>
-    </sourceModifications>
-    <unitTestSourceDirectory>${basedir}/src/test</unitTestSourceDirectory>
-    <integrationUnitTestSourceDirectory/>
-    <aspectSourceDirectory/>
-
-    <unitTest>
-      <includes>
-        <include>**/*Test*</include>
-        <include>**/*TestCase*</include>
-      </includes>
-
-      <excludes>
-        <exclude>**/Abstract*</exclude>
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<project>
+
+  <groupId>directory-network</groupId>
+  <id>mina</id>
+  <name>MINA</name>
+  <package>org.apache.mina</package>
+  <currentVersion>0.9.1-SNAPSHOT</currentVersion>
+  <inceptionYear>2004</inceptionYear>
+
+  <logo>http://directory.apache.org/images/apache-directory-logo.png</logo>
+  <url>http://directory.apache.org/</url>
+
+  <issueTrackingUrl>
+    http://issues.apache.org/jira/
+  </issueTrackingUrl>
+  <siteAddress>minotaur.apache.org</siteAddress>
+  <siteDirectory>
+    /www/directory.apache.org/subprojects/network
+  </siteDirectory>
+  <distributionDirectory>
+    /www/cvs.apache.org/dist/directory
+  </distributionDirectory>
+
+  <developers>
+    <developer>
+      <name>Trustin Lee</name>
+      <id>trustin</id>
+      <email>trustin@gmail.com</email>
+      <organization>Solarsis LLC</organization>
+      <url>http://gleamynode.net/</url>
+      <timezone>+9</timezone>
+    </developer>
+    <developer>
+      <name>Niklas Therning</name>
+      <id>niklas</id>
+      <email>niklas(at)trillian(dot)se</email>
+      <organization>Trillian AB</organization>
+      <url>http://therning.org/niklas</url>
+      <timezone>+1</timezone>
+    </developer>
+  </developers>
+  <contributors>
+    <contributor>
+      <name>Jan Andersson</name>
+    </contributor>
+    <contributor>
+      <name>Vinod Panicker</name>
+    </contributor>
+  </contributors>
+
+  <repository>
+    <connection>
+      scm:svn:http://svn.apache.org/repos/asf/directory/network/trunk
+    </connection>
+    <url>
+      http://svn.apache.org/viewcvs.cgi/directory/network/trunk/?root=Apache-SVN
+    </url>
+    <developerConnection>
+      scm:svn:https://svn.apache.org/repos/asf/directory/network/trunk
+    </developerConnection>
+  </repository>
+
+  <gumpRepositoryId>directory</gumpRepositoryId>
+
+  <shortDescription>
+    A Multipurpose Infrastructure for Network Applications
+  </shortDescription>
+
+  <description>
+    MINA (Multipurpose Infrastructure for Network Applications) is a
+    network application framework which helps users develop high
+    performance and high scalability network applications easily.
+  </description>
+
+  <mailingLists>
+    <mailingList>
+      <name>Apache Directory Developement - use [mina] prefix</name>
+      <subscribe>
+        dev-subscribe@directory.apache.org
+      </subscribe>
+      <unsubscribe>
+        dev-unsubscribe@directory.apache.org
+      </unsubscribe>
+      <archive>
+        http://www.archivum.info/dev@directory.apache.org/
+      </archive>
+    </mailingList>
+  </mailingLists>
+
+  <licenses>
+    <license>
+      <name>Apache 2.0 License</name>
+      <url>http://www.apache.org/licenses/LICENSE-2.0</url>
+      <distribution>repo</distribution>
+    </license>
+  </licenses>
+
+  <dependencies>
+
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-simple</artifactId>
+      <version>1.0-beta9</version>
+      <url>http://www.slf4j.org/</url>
+    </dependency>
+
+    <dependency>
+      <groupId>springframework</groupId>
+      <artifactId>spring-core</artifactId>
+      <version>1.2.5</version>
+      <url>http://www.springframework.org/</url>
+    </dependency>
+
+    <dependency>
+      <groupId>springframework</groupId>
+      <artifactId>spring-beans</artifactId>
+      <version>1.2.5</version>
+      <url>http://www.springframework.org/</url>
+    </dependency>
+
+    <!-- ========================================================= -->
+    <!-- Dependencies required for running test cases and examples -->
+    <!-- ========================================================= -->
+
+    <dependency>
+      <groupId>commons-net</groupId>
+      <artifactId>commons-net</artifactId>
+      <version>1.3.0</version>
+      <url>http://jakarta.apache.org/commons/net/</url>
+    </dependency>
+
+    <dependency>
+      <groupId>easymock</groupId>
+      <artifactId>easymock</artifactId>
+      <version>1.2_Java1.3</version>
+      <url>http://www.easymock.org/</url>
+    </dependency>
+    
+    <dependency>
+      <groupId>easymock</groupId>
+      <artifactId>easymockclassextension</artifactId>
+      <version>1.2</version>
+      <url>http://www.easymock.org/</url>
+    </dependency>
+    
+    <dependency>
+      <groupId>cglib</groupId>
+      <artifactId>cglib-nodep</artifactId>
+      <version>2.1</version>
+      <url>http://cglib.sourceforge.net/</url>
+    </dependency>
+
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>jcl104-over-slf4j</artifactId>
+      <version>1.0-beta9</version>
+      <url>http://www.slf4j.org/</url>
+    </dependency>
+    
+    <dependency>
+      <groupId>emma</groupId>
+      <artifactId>emma</artifactId>
+      <version>2.0.latest</version>
+      <url>http://emma.sourceforge.net/</url>
+    </dependency>
+
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <url>http://junit.org/</url>
+    </dependency>
+
+    <dependency>
+      <groupId>emma</groupId>
+      <artifactId>maven-emma-plugin</artifactId>
+      <version>0.4</version>
+      <url>http://emma.sourceforge.net/</url>
+      <type>plugin</type>
+    </dependency>
+    
+    <dependency>
+      <artifactId>maven-site-plugin</artifactId>
+      <groupId>maven</groupId>
+      <version>1.6.1</version>
+      <type>plugin</type>
+    </dependency>
+
+  </dependencies>
+
+
+  <build>
+    <nagEmailAddress>dev@directory.apache.org</nagEmailAddress>
+    <sourceDirectory>${basedir}/src/java</sourceDirectory>
+    <sourceModifications>
+      <sourceModification>
+        <className>javax.swing.SwingGraphics</className>
+        <excludes>
+          <exclude>org/apache/mina/io/filter/SSLFilter.java</exclude>
+          <exclude>org/apache/mina/io/filter/SSLHandler.java</exclude>
+          <exclude>org/apache/mina/io/filter/SSLByteBufferPool.java</exclude>
+        </excludes>
+      </sourceModification>
+    </sourceModifications>
+    <unitTestSourceDirectory>${basedir}/src/test</unitTestSourceDirectory>
+    <integrationUnitTestSourceDirectory/>
+    <aspectSourceDirectory/>
+
+    <unitTest>
+      <includes>
+        <include>**/*Test*</include>
+        <include>**/*TestCase*</include>
+      </includes>
+
+      <excludes>
+        <exclude>**/Abstract*</exclude>
     <!--
-        <exclude>**/DatagramBindTest*</exclude>
+        <exclude>**/DatagramBindTest*</exclude>
     -->
-        <exclude>**/*RegressionTest*</exclude>
-      </excludes>
-      
+        <exclude>**/*RegressionTest*</exclude>
+      </excludes>
+      
       <resources>
         <resource>
           <directory>${basedir}/src/test</directory>
@@ -228,36 +228,36 @@
             <include>**/*.cert</include>
           </includes>
         </resource>
-      </resources>
-    </unitTest>
-
-    <resources>
-      <resource>
-        <directory>${basedir}/src/java</directory>
-        <includes>
-          <include>**/package.html</include>
-        </includes>
-      </resource>
-      <resource>
-        <directory>${basedir}/src/examples</directory>
-        <includes>
-          <include>**/*.cert</include>
-        </includes>
-      </resource>
-    </resources>
-  </build>
-
-  <reports>
-    <report>maven-license-plugin</report>
-    <report>maven-javadoc-plugin</report>
-    <report>maven-changes-plugin</report>
-    <report>maven-jxr-plugin</report>
-    <report>maven-junit-report-plugin</report>
-    <report>maven-emma-plugin</report>
-    <report>maven-jdepend-plugin</report>
-    <report>maven-simian-plugin</report>
-    <report>maven-tasklist-plugin</report>
-    <report>maven-faq-plugin</report>
-  </reports>
-
-</project>
+      </resources>
+    </unitTest>
+
+    <resources>
+      <resource>
+        <directory>${basedir}/src/java</directory>
+        <includes>
+          <include>**/package.html</include>
+        </includes>
+      </resource>
+      <resource>
+        <directory>${basedir}/src/examples</directory>
+        <includes>
+          <include>**/*.cert</include>
+        </includes>
+      </resource>
+    </resources>
+  </build>
+
+  <reports>
+    <report>maven-license-plugin</report>
+    <report>maven-javadoc-plugin</report>
+    <report>maven-changes-plugin</report>
+    <report>maven-jxr-plugin</report>
+    <report>maven-junit-report-plugin</report>
+    <report>maven-emma-plugin</report>
+    <report>maven-jdepend-plugin</report>
+    <report>maven-simian-plugin</report>
+    <report>maven-tasklist-plugin</report>
+    <report>maven-faq-plugin</report>
+  </reports>
+
+</project>

Modified: directory/network/trunk/src/java/org/apache/mina/common/DefaultIoFilterChainBuilder.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/common/DefaultIoFilterChainBuilder.java?rev=359355&r1=359354&r2=359355&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/common/DefaultIoFilterChainBuilder.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/common/DefaultIoFilterChainBuilder.java Tue Dec 27 18:49:31 2005
@@ -1,349 +1,349 @@
-/*
- *   @(#) $Id: DefaultIoFilterChainBuilder.java 350135 2005-12-01 03:43:29Z 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;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Map;
-
-import org.apache.mina.common.IoFilter.NextFilter;
-import org.apache.mina.common.IoFilterChain.Entry;
-
-/**
- * The default implementation of {@link IoFilterChainBuilder} which is useful
- * in most cases.  {@link DefaultIoFilterChainBuilder} has an identical interface
- * with {@link IoFilter}; it contains a list of {@link IoFilter}s that you can
- * modify. The {@link IoFilter}s which are added to this builder will be appended
- * to the {@link IoFilterChain} when {@link #buildFilterChain(IoFilterChain)} is
- * invoked.
- * <p>
- * However, the identical interface doesn't mean that it behaves in an exactly
- * same way with {@link IoFilterChain}.  {@link DefaultIoFilterChainBuilder}
- * doesn't manage the life cycle of the {@link IoFilter}s at all, and the
- * existing {@link IoSession}s won't get affected by the changes in this builder.
- * {@link IoFilterChainBuilder}s affect only newly created {@link IoSession}s.
- * 
- * <pre>
- * IoAcceptor acceptor = ...;
- * DefaultIoFilterChainBuilder builder = acceptor.getFilterChain();
- * builder.addLast( "myFilter", new MyFilter() );
- * ...
- * </pre>
- *
- * @author The Apache Directory Project (dev@directory.apache.org)
- * @version $Rev: 350135 $, $Date: 2005-12-01 12:43:29 +0900 $
- */
-public class DefaultIoFilterChainBuilder implements IoFilterChainBuilder
-{
-    private List entries = new ArrayList();
-    private final Map entriesByName = new HashMap();
-    
-    /**
-     * Creates a new instance with an empty filter list.
-     */
-    public DefaultIoFilterChainBuilder()
-    {
-    }
-
-    /**
-     * @see IoFilterChain#getEntry(String)
-     */
-    public synchronized Entry getEntry( String name )
-    {
-        return ( Entry ) entriesByName.get( name );
-    }
-
-    /**
-     * @see IoFilterChain#get(String)
-     */
-    public synchronized IoFilter get( String name )
-    {
-        Entry e = getEntry( name );
-        if( e == null )
-        {
-            return null;
-        }
-        
-        return e.getFilter();
-    }
-    
-    /**
-     * @see IoFilterChain#getAll()
-     */
-    public List getAll()
-    {
-        return new ArrayList( entries );
-    }
-    
-    /**
-     * @see IoFilterChain#getAllReversed()
-     */
-    public List getAllReversed()
-    {
-        List result = getAll();
-        Collections.reverse( result );
-        return result;
-    }
-
-    /**
-     * @see IoFilterChain#contains(String)
-     */
-    public boolean contains( String name )
-    {
-        return getEntry( name ) != null;
-    }
-    
-    /**
-     * @see IoFilterChain#contains(IoFilter)
-     */
-    public boolean contains( IoFilter filter )
-    {
-        for( Iterator i = entries.iterator(); i.hasNext(); )
-        {
-            Entry e = ( Entry ) i.next();
-            if( e.getFilter() == filter )
-            {
-                return true;
-            }
-        }
-        
-        return false;
-    }
-    
-    /**
-     * @see IoFilterChain#contains(Class)
-     */
-    public boolean contains( Class filterType )
-    {
-        for( Iterator i = entries.iterator(); i.hasNext(); )
-        {
-            Entry e = ( Entry ) i.next();
-            if( filterType.isAssignableFrom( e.getFilter().getClass() ) )
-            {
-                return true;
-            }
-        }
-        
-        return false;
-    }
-    
-    /**
-     * @see IoFilterChain#addFirst(String, IoFilter)
-     */
-    public synchronized void addFirst( String name, IoFilter filter )
-    {
-        register( 0, new EntryImpl( name, filter ) );
-    }
-    
-    /**
-     * @see IoFilterChain#addLast(String, IoFilter)
-     */
-    public synchronized void addLast( String name, IoFilter filter )
-    {
-        register( entries.size(), new EntryImpl( name, filter ) );
-    }
-
-    /**
-     * @see IoFilterChain#addBefore(String, String, IoFilter)
-     */
-    public synchronized void addBefore( String baseName, String name, IoFilter filter )
-    {
-        checkBaseName( baseName );
-        
-        for( ListIterator i = entries.listIterator(); i.hasNext(); )
-        {
-            Entry base = ( Entry ) i.next();
-            if( base.getName().equals( baseName ) )
-            {
-                register( i.previousIndex(), new EntryImpl( name, filter ) );
-                break;
-            }
-        }
-    }
-
-    /**
-     * @see IoFilterChain#addAfter(String, String, IoFilter)
-     */
-    public synchronized void addAfter( String baseName, String name, IoFilter filter )
-    {
-        checkBaseName( baseName );
-        
-        List entries = new ArrayList( this.entries );
-        
-        for( ListIterator i = entries.listIterator(); i.hasNext(); )
-        {
-            Entry base = ( Entry ) i.next();
-            if( base.getName().equals( baseName ) )
-            {
-                register( i.nextIndex(), new EntryImpl( name, filter ) );
-                break;
-            }
-        }
-    }
-
-    /**
-     * @see IoFilterChain#remove(String)
-     */
-    public synchronized IoFilter remove( String name )
-    {
-        if( name == null )
-        {
-            throw new NullPointerException( "name" );
-        }
-
-        for( ListIterator i = entries.listIterator(); i.hasNext(); )
-        {
-            Entry e = ( Entry ) i.next();
-            if( e.getName().equals( name ) )
-            {
-                deregister( i.previousIndex(), e );
-                return e.getFilter();
-            }
-        }
-        
-        throw new IllegalArgumentException( "Unknown filter name: " + name );
-    }
-
-    /**
-     * @see IoFilterChain#clear()
-     */
-    public synchronized void clear() throws Exception
-    {
-        entries = new ArrayList();
-        entriesByName.clear();
-    }
-    
-    public void buildFilterChain( IoFilterChain chain ) throws Exception
-    {
-        for( Iterator i = entries.iterator(); i.hasNext(); )
-        {
-            Entry e = ( Entry ) i.next();
-            chain.addLast( e.getName(), e.getFilter() );
-        }
-    }
-    
-    public String toString()
-    {
-        StringBuffer buf = new StringBuffer();
-        buf.append( "{ " );
-        
-        boolean empty = true;
-        
-        for( Iterator i = entries.iterator(); i.hasNext(); )
-        {
-            Entry e = ( Entry ) i.next();
-            if( !empty )
-            {
-                buf.append( ", " );
-            }
-            else
-            {
-                empty = false;
-            }
-            
-            buf.append( '(' );
-            buf.append( e.getName() );
-            buf.append( ':' );
-            buf.append( e.getFilter() );
-            buf.append( ')' );
-        }
-        
-        if( empty )
-        {
-            buf.append( "empty" );
-        }
-        
-        buf.append( " }" );
-        
-        return buf.toString();
-    }
-
-    private void checkBaseName( String baseName )
-    {
-        if( baseName == null )
-        {
-            throw new NullPointerException( "baseName" );
-        }
-        if( !entriesByName.containsKey( baseName ) )
-        {
-            throw new IllegalArgumentException( "Unknown filter name: " + baseName );
-        }
-    }
-
-    private void register( int index, Entry e )
-    {
-        if( entriesByName.containsKey( e.getName() ) )
-        {
-            throw new IllegalArgumentException( "Other filter is using the same name: " + e.getName() );
-        }
-
-        List newEntries = new ArrayList( entries );
-        newEntries.add( index, e );
-        this.entries = newEntries;
-        entriesByName.put( e.getName(), e );
-    }
-    
-    private void deregister( int index, Entry e )
-    {
-        List newEntries = new ArrayList( entries );
-        newEntries.remove( index );
-        this.entries = newEntries;
-        entriesByName.remove( e.getName() );
-    }
-
-    private static class EntryImpl implements Entry
-    {
-        private final String name;
-        private final IoFilter filter;
-        
-        private EntryImpl( String name, IoFilter filter )
-        {
-            if( name == null )
-            {
-                throw new NullPointerException( "name" );
-            }
-            if( filter == null )
-            {
-                throw new NullPointerException( "filter" );
-            }
-            
-            this.name = name;
-            this.filter = filter;
-        }
-
-        public String getName()
-        {
-            return name;
-        }
-        
-        public IoFilter getFilter()
-        {
-            return filter;
-        }
-
-        public NextFilter getNextFilter()
-        {
-            throw new IllegalStateException();
-        }
-    }
-}
+/*
+ *   @(#) $Id: DefaultIoFilterChainBuilder.java 350135 2005-12-01 03:43:29Z 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;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+
+import org.apache.mina.common.IoFilter.NextFilter;
+import org.apache.mina.common.IoFilterChain.Entry;
+
+/**
+ * The default implementation of {@link IoFilterChainBuilder} which is useful
+ * in most cases.  {@link DefaultIoFilterChainBuilder} has an identical interface
+ * with {@link IoFilter}; it contains a list of {@link IoFilter}s that you can
+ * modify. The {@link IoFilter}s which are added to this builder will be appended
+ * to the {@link IoFilterChain} when {@link #buildFilterChain(IoFilterChain)} is
+ * invoked.
+ * <p>
+ * However, the identical interface doesn't mean that it behaves in an exactly
+ * same way with {@link IoFilterChain}.  {@link DefaultIoFilterChainBuilder}
+ * doesn't manage the life cycle of the {@link IoFilter}s at all, and the
+ * existing {@link IoSession}s won't get affected by the changes in this builder.
+ * {@link IoFilterChainBuilder}s affect only newly created {@link IoSession}s.
+ * 
+ * <pre>
+ * IoAcceptor acceptor = ...;
+ * DefaultIoFilterChainBuilder builder = acceptor.getFilterChain();
+ * builder.addLast( "myFilter", new MyFilter() );
+ * ...
+ * </pre>
+ *
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev: 350135 $, $Date: 2005-12-01 12:43:29 +0900 $
+ */
+public class DefaultIoFilterChainBuilder implements IoFilterChainBuilder
+{
+    private List entries = new ArrayList();
+    private final Map entriesByName = new HashMap();
+    
+    /**
+     * Creates a new instance with an empty filter list.
+     */
+    public DefaultIoFilterChainBuilder()
+    {
+    }
+
+    /**
+     * @see IoFilterChain#getEntry(String)
+     */
+    public synchronized Entry getEntry( String name )
+    {
+        return ( Entry ) entriesByName.get( name );
+    }
+
+    /**
+     * @see IoFilterChain#get(String)
+     */
+    public synchronized IoFilter get( String name )
+    {
+        Entry e = getEntry( name );
+        if( e == null )
+        {
+            return null;
+        }
+        
+        return e.getFilter();
+    }
+    
+    /**
+     * @see IoFilterChain#getAll()
+     */
+    public List getAll()
+    {
+        return new ArrayList( entries );
+    }
+    
+    /**
+     * @see IoFilterChain#getAllReversed()
+     */
+    public List getAllReversed()
+    {
+        List result = getAll();
+        Collections.reverse( result );
+        return result;
+    }
+
+    /**
+     * @see IoFilterChain#contains(String)
+     */
+    public boolean contains( String name )
+    {
+        return getEntry( name ) != null;
+    }
+    
+    /**
+     * @see IoFilterChain#contains(IoFilter)
+     */
+    public boolean contains( IoFilter filter )
+    {
+        for( Iterator i = entries.iterator(); i.hasNext(); )
+        {
+            Entry e = ( Entry ) i.next();
+            if( e.getFilter() == filter )
+            {
+                return true;
+            }
+        }
+        
+        return false;
+    }
+    
+    /**
+     * @see IoFilterChain#contains(Class)
+     */
+    public boolean contains( Class filterType )
+    {
+        for( Iterator i = entries.iterator(); i.hasNext(); )
+        {
+            Entry e = ( Entry ) i.next();
+            if( filterType.isAssignableFrom( e.getFilter().getClass() ) )
+            {
+                return true;
+            }
+        }
+        
+        return false;
+    }
+    
+    /**
+     * @see IoFilterChain#addFirst(String, IoFilter)
+     */
+    public synchronized void addFirst( String name, IoFilter filter )
+    {
+        register( 0, new EntryImpl( name, filter ) );
+    }
+    
+    /**
+     * @see IoFilterChain#addLast(String, IoFilter)
+     */
+    public synchronized void addLast( String name, IoFilter filter )
+    {
+        register( entries.size(), new EntryImpl( name, filter ) );
+    }
+
+    /**
+     * @see IoFilterChain#addBefore(String, String, IoFilter)
+     */
+    public synchronized void addBefore( String baseName, String name, IoFilter filter )
+    {
+        checkBaseName( baseName );
+        
+        for( ListIterator i = entries.listIterator(); i.hasNext(); )
+        {
+            Entry base = ( Entry ) i.next();
+            if( base.getName().equals( baseName ) )
+            {
+                register( i.previousIndex(), new EntryImpl( name, filter ) );
+                break;
+            }
+        }
+    }
+
+    /**
+     * @see IoFilterChain#addAfter(String, String, IoFilter)
+     */
+    public synchronized void addAfter( String baseName, String name, IoFilter filter )
+    {
+        checkBaseName( baseName );
+        
+        List entries = new ArrayList( this.entries );
+        
+        for( ListIterator i = entries.listIterator(); i.hasNext(); )
+        {
+            Entry base = ( Entry ) i.next();
+            if( base.getName().equals( baseName ) )
+            {
+                register( i.nextIndex(), new EntryImpl( name, filter ) );
+                break;
+            }
+        }
+    }
+
+    /**
+     * @see IoFilterChain#remove(String)
+     */
+    public synchronized IoFilter remove( String name )
+    {
+        if( name == null )
+        {
+            throw new NullPointerException( "name" );
+        }
+
+        for( ListIterator i = entries.listIterator(); i.hasNext(); )
+        {
+            Entry e = ( Entry ) i.next();
+            if( e.getName().equals( name ) )
+            {
+                deregister( i.previousIndex(), e );
+                return e.getFilter();
+            }
+        }
+        
+        throw new IllegalArgumentException( "Unknown filter name: " + name );
+    }
+
+    /**
+     * @see IoFilterChain#clear()
+     */
+    public synchronized void clear() throws Exception
+    {
+        entries = new ArrayList();
+        entriesByName.clear();
+    }
+    
+    public void buildFilterChain( IoFilterChain chain ) throws Exception
+    {
+        for( Iterator i = entries.iterator(); i.hasNext(); )
+        {
+            Entry e = ( Entry ) i.next();
+            chain.addLast( e.getName(), e.getFilter() );
+        }
+    }
+    
+    public String toString()
+    {
+        StringBuffer buf = new StringBuffer();
+        buf.append( "{ " );
+        
+        boolean empty = true;
+        
+        for( Iterator i = entries.iterator(); i.hasNext(); )
+        {
+            Entry e = ( Entry ) i.next();
+            if( !empty )
+            {
+                buf.append( ", " );
+            }
+            else
+            {
+                empty = false;
+            }
+            
+            buf.append( '(' );
+            buf.append( e.getName() );
+            buf.append( ':' );
+            buf.append( e.getFilter() );
+            buf.append( ')' );
+        }
+        
+        if( empty )
+        {
+            buf.append( "empty" );
+        }
+        
+        buf.append( " }" );
+        
+        return buf.toString();
+    }
+
+    private void checkBaseName( String baseName )
+    {
+        if( baseName == null )
+        {
+            throw new NullPointerException( "baseName" );
+        }
+        if( !entriesByName.containsKey( baseName ) )
+        {
+            throw new IllegalArgumentException( "Unknown filter name: " + baseName );
+        }
+    }
+
+    private void register( int index, Entry e )
+    {
+        if( entriesByName.containsKey( e.getName() ) )
+        {
+            throw new IllegalArgumentException( "Other filter is using the same name: " + e.getName() );
+        }
+
+        List newEntries = new ArrayList( entries );
+        newEntries.add( index, e );
+        this.entries = newEntries;
+        entriesByName.put( e.getName(), e );
+    }
+    
+    private void deregister( int index, Entry e )
+    {
+        List newEntries = new ArrayList( entries );
+        newEntries.remove( index );
+        this.entries = newEntries;
+        entriesByName.remove( e.getName() );
+    }
+
+    private static class EntryImpl implements Entry
+    {
+        private final String name;
+        private final IoFilter filter;
+        
+        private EntryImpl( String name, IoFilter filter )
+        {
+            if( name == null )
+            {
+                throw new NullPointerException( "name" );
+            }
+            if( filter == null )
+            {
+                throw new NullPointerException( "filter" );
+            }
+            
+            this.name = name;
+            this.filter = filter;
+        }
+
+        public String getName()
+        {
+            return name;
+        }
+        
+        public IoFilter getFilter()
+        {
+            return filter;
+        }
+
+        public NextFilter getNextFilter()
+        {
+            throw new IllegalStateException();
+        }
+    }
+}

Modified: directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java?rev=359355&r1=359354&r2=359355&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java Tue Dec 27 18:49:31 2005
@@ -1,687 +1,687 @@
-/*
- *   @(#) $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.transport.socket.nio.support;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
-import java.nio.channels.DatagramChannel;
-import java.nio.channels.SelectionKey;
-import java.nio.channels.Selector;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.mina.common.ByteBuffer;
-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;
-import org.apache.mina.common.IoFilter.WriteRequest;
-import org.apache.mina.common.support.BaseIoAcceptor;
-import org.apache.mina.util.ExceptionUtil;
-import org.apache.mina.util.Queue;
-
-/**
- * {@link IoAcceptor} for datagram transport (UDP/IP).
- * 
- * @author The Apache Directory Project (dev@directory.apache.org)
- * @version $Rev$, $Date$
- */
-public class DatagramAcceptorDelegate extends BaseIoAcceptor implements IoAcceptor, DatagramSessionManager
-{
-    private static volatile int nextId = 0;
-
-    private final IoAcceptor wrapper;
-    private final int id = nextId ++ ;
-    private Selector selector;
-    private boolean broadcast;
-    private boolean reuseAddress;
-    private int receiveBufferSize = -1;
-    private int sendBufferSize = -1;
-    private int trafficClass = -1;
-    private final Map channels = new HashMap();
-    private final Queue registerQueue = new Queue();
-    private final Queue cancelQueue = new Queue();
-    private final Queue flushingSessions = new Queue();
-    private Worker worker;
-
-    /**
-     * Creates a new instance.
-     */
-    public DatagramAcceptorDelegate( IoAcceptor wrapper )
-    {
-        this.wrapper = wrapper;
-    }
-
-    public void bind( SocketAddress address, IoHandler handler, IoFilterChainBuilder filterChainBuilder )
-            throws IOException
-    {
-        if( address == null )
-            throw new NullPointerException( "address" );
-        if( handler == null )
-            throw new NullPointerException( "handler" );
-
-        if( !( address instanceof InetSocketAddress ) )
-            throw new IllegalArgumentException( "Unexpected address type: "
-                                                + address.getClass() );
-        if( ( ( InetSocketAddress ) address ).getPort() == 0 )
-            throw new IllegalArgumentException( "Unsupported port number: 0" );
-        
-        if( filterChainBuilder == null )
-        {
-            filterChainBuilder = IoFilterChainBuilder.NOOP;
-        }
-
-        RegistrationRequest request = new RegistrationRequest( address, handler, filterChainBuilder );
-        synchronized( this )
-        {
-            synchronized( registerQueue )
-            {
-                registerQueue.push( request );
-            }
-            startupWorker();
-        }
-        selector.wakeup();
-        
-        synchronized( request )
-        {
-            while( !request.done )
-            {
-                try
-                {
-                    request.wait();
-                }
-                catch( InterruptedException e )
-                {
-                }
-            }
-        }
-        
-        if( request.exception != null )
-        {
-            ExceptionUtil.throwException( request.exception );
-        }
-    }
-
-    public void unbind( SocketAddress address )
-    {
-        // TODO: DIRMINA-93
-        if( address == null )
-            throw new NullPointerException( "address" );
-
-        CancellationRequest request = new CancellationRequest( address );
-        synchronized( this )
-        {
-            try
-            {
-                startupWorker();
-            }
-            catch( IOException e )
-            {
-                // IOException is thrown only when Worker thread is not
-                // running and failed to open a selector.  We simply throw
-                // IllegalArgumentException here because we can simply
-                // conclude that nothing is bound to the selector.
-                throw new IllegalArgumentException( "Address not bound: " + address );
-            }
-
-            synchronized( cancelQueue )
-            {
-                cancelQueue.push( request );
-            }
-        }
-        selector.wakeup();
-        
-        synchronized( request )
-        {
-            while( !request.done )
-            {
-                try
-                {
-                    request.wait();
-                }
-                catch( InterruptedException e )
-                {
-                }
-            }
-        }
-        
-        if( request.exception != null )
-        {
-            request.exception.fillInStackTrace();
-            throw request.exception;
-        }
-    }
-    
-    public IoSession newSession( SocketAddress remoteAddress, SocketAddress localAddress )
-    {
-        if( remoteAddress == null )
-        {
-            throw new NullPointerException( "remoteAddress" );
-        }
-        if( localAddress == null )
-        {
-            throw new NullPointerException( "localAddress" );
-        }
-        
-        Selector selector = this.selector;
-        DatagramChannel ch = ( DatagramChannel ) channels.get( localAddress );
-        if( selector == null || ch == null )
-        {
-            throw new IllegalArgumentException( "Unknown localAddress: " + localAddress );
-        }
-            
-        SelectionKey key = ch.keyFor( selector );
-        if( key == null )
-        {
-            throw new IllegalArgumentException( "Unknown localAddress: " + localAddress );
-        }
-
-        RegistrationRequest req = ( RegistrationRequest ) key.attachment();
-        DatagramSessionImpl s = new DatagramSessionImpl( wrapper, this, ch, req.handler );
-        s.setRemoteAddress( remoteAddress );
-        s.setSelectionKey( key );
-        
-        try
-        {
-            this.filterChainBuilder.buildFilterChain( s.getFilterChain() );
-            req.filterChainBuilder.buildFilterChain( s.getFilterChain() );
-            ( ( DatagramFilterChain ) s.getFilterChain() ).sessionCreated( s );
-        }
-        catch( Throwable t )
-        {
-            ExceptionMonitor.getInstance().exceptionCaught( t );
-        }
-        
-        return s;
-    }
-    
-    public boolean getBroadcast()
-    {
-        return broadcast;
-    }
-    
-    public void setBroadcast( boolean broadcast )
-    {
-        this.broadcast = broadcast;
-    }
-    
-    public boolean getReuseAddress()
-    {
-        return reuseAddress;
-    }
-    
-    public void setReuseAddress( boolean reuseAddress )
-    {
-        this.reuseAddress = reuseAddress;
-    }
-
-
-    public int getReceiveBufferSize()
-    {
-        return receiveBufferSize;
-    }
-
-    public void setReceiveBufferSize( int receiveBufferSize )
-    {
-        this.receiveBufferSize = receiveBufferSize;
-    }
-
-    public int getSendBufferSize()
-    {
-        return sendBufferSize;
-    }
-
-    public void setSendBufferSize( int sendBufferSize )
-    {
-        this.sendBufferSize = sendBufferSize;
-    }
-
-    public int getTrafficClass()
-    {
-        return trafficClass;
-    }
-
-    public void setTrafficClass( int trafficClass )
-    {
-        this.trafficClass = trafficClass;
-    }
-
-    private synchronized void startupWorker() throws IOException
-    {
-        if( worker == null )
-        {
-            selector = Selector.open();
-            worker = new Worker();
-            worker.start();
-        }
-    }
-
-    public void flushSession( DatagramSessionImpl session )
-    {
-        scheduleFlush( session );
-        Selector selector = this.selector;
-        if( selector != null )
-        {
-            selector.wakeup();
-        }
-    }
-
-    public void closeSession( DatagramSessionImpl session )
-    {
-    }
-
-    private void scheduleFlush( DatagramSessionImpl session )
-    {
-        synchronized( flushingSessions )
-        {
-            flushingSessions.push( session );
-        }
-    }
-
-    private class Worker extends Thread
-    {
-        public Worker()
-        {
-            super( "DatagramAcceptor-" + id );
-        }
-
-        public void run()
-        {
-            for( ;; )
-            {
-                try
-                {
-                    int nKeys = selector.select();
-
-                    registerNew();
-
-                    if( nKeys > 0 )
-                    {
-                        processReadySessions( selector.selectedKeys() );
-                    }
-
-                    flushSessions();
-                    cancelKeys();
-
-                    if( selector.keys().isEmpty() )
-                    {
-                        synchronized( DatagramAcceptorDelegate.this )
-                        {
-                            if( selector.keys().isEmpty() &&
-                                registerQueue.isEmpty() &&
-                                cancelQueue.isEmpty() )
-                            {
-                                worker = null;
-                                try
-                                {
-                                    selector.close();
-                                }
-                                catch( IOException e )
-                                {
-                                    ExceptionMonitor.getInstance().exceptionCaught( e );
-                                }
-                                finally
-                                {
-                                    selector = null;
-                                }
-                                break;
-                            }
-                        }
-                    }
-                }
-                catch( IOException e )
-                {
-                    ExceptionMonitor.getInstance().exceptionCaught( e );
-
-                    try
-                    {
-                        Thread.sleep( 1000 );
-                    }
-                    catch( InterruptedException e1 )
-                    {
-                    }
-                }
-            }
-        }
-    }
-
-    private void processReadySessions( Set keys )
-    {
-        Iterator it = keys.iterator();
-        while( it.hasNext() )
-        {
-            SelectionKey key = ( SelectionKey ) it.next();
-            it.remove();
-
-            DatagramChannel ch = ( DatagramChannel ) key.channel();
-
-            RegistrationRequest req = ( RegistrationRequest ) key.attachment();
-            DatagramSessionImpl session =
-                new DatagramSessionImpl( wrapper, this, ch, req.handler );
-            session.setSelectionKey( key );
-            
-            try
-            {
-                ( ( DatagramFilterChain ) session.getFilterChain() ).sessionCreated( session );
-
-                if( key.isReadable() )
-                {
-                    readSession( session );
-                }
-
-                if( key.isWritable() )
-                {
-                    scheduleFlush( session );
-                }
-            }
-            catch( Throwable t )
-            {
-                ExceptionMonitor.getInstance().exceptionCaught( t );
-            }
-        }
-    }
-
-    private void readSession( DatagramSessionImpl session )
-    {
-
-        ByteBuffer readBuf = ByteBuffer.allocate( 2048 );
-        try
-        {
-            SocketAddress remoteAddress = session.getChannel().receive(
-                    readBuf.buf() );
-            if( remoteAddress != null )
-            {
-                readBuf.flip();
-                session.setRemoteAddress( remoteAddress );
-
-                ByteBuffer newBuf = ByteBuffer.allocate( readBuf.limit() );
-                newBuf.put( readBuf );
-                newBuf.flip();
-
-                session.increaseReadBytes( newBuf.remaining() );
-                ( ( DatagramFilterChain ) session.getFilterChain() ).messageReceived( session, newBuf );
-            }
-        }
-        catch( IOException e )
-        {
-            ( ( DatagramFilterChain ) session.getFilterChain() ).exceptionCaught( session, e );
-        }
-        finally
-        {
-            readBuf.release();
-        }
-    }
-
-    private void flushSessions()
-    {
-        if( flushingSessions.size() == 0 )
-            return;
-
-        for( ;; )
-        {
-            DatagramSessionImpl session;
-
-            synchronized( flushingSessions )
-            {
-                session = ( DatagramSessionImpl ) flushingSessions.pop();
-            }
-
-            if( session == null )
-                break;
-
-            try
-            {
-                flush( session );
-            }
-            catch( IOException e )
-            {
-                ( ( DatagramFilterChain ) session.getFilterChain() ).exceptionCaught( session, e );
-            }
-        }
-    }
-
-    private void flush( DatagramSessionImpl session ) throws IOException
-    {
-        DatagramChannel ch = session.getChannel();
-
-        Queue writeRequestQueue = session.getWriteRequestQueue();
-
-        WriteRequest req;
-        for( ;; )
-        {
-            synchronized( writeRequestQueue )
-            {
-                req = ( WriteRequest ) writeRequestQueue.first();
-            }
-
-            if( req == null )
-                break;
-
-            ByteBuffer buf = ( ByteBuffer ) req.getMessage();
-            if( buf.remaining() == 0 )
-            {
-                // pop and fire event
-                synchronized( writeRequestQueue )
-                {
-                    writeRequestQueue.pop();
-                }
-
-                req.getFuture().setWritten( true );
-                session.increaseWrittenWriteRequests();
-                ( ( DatagramFilterChain ) session.getFilterChain() ).messageSent( session, buf );
-                continue;
-            }
-
-            SelectionKey key = session.getSelectionKey();
-            if( key == null )
-            {
-                scheduleFlush( session );
-                break;
-            }
-            if( !key.isValid() )
-            {
-                continue;
-            }
-
-            int pos = buf.position();
-            int writtenBytes = ch
-                    .send( buf.buf(), session.getRemoteAddress() );
-
-            if( writtenBytes == 0 )
-            {
-                // Kernel buffer is full
-                key.interestOps( key.interestOps() | SelectionKey.OP_WRITE );
-            }
-            else if( writtenBytes > 0 )
-            {
-                key.interestOps( key.interestOps()
-                                 & ( ~SelectionKey.OP_WRITE ) );
-
-                // pop and fire event
-                synchronized( writeRequestQueue )
-                {
-                    writeRequestQueue.pop();
-                }
-
-                session.increaseWrittenBytes( writtenBytes );
-                req.getFuture().setWritten( true );
-                session.increaseWrittenWriteRequests();
-                ( ( DatagramFilterChain ) session.getFilterChain() ).messageSent( session, buf.position( pos ) );
-            }
-        }
-    }
-
-    private void registerNew()
-    {
-        if( registerQueue.isEmpty() )
-            return;
-
-        for( ;; )
-        {
-            RegistrationRequest req;
-            synchronized( registerQueue )
-            {
-                req = ( RegistrationRequest ) registerQueue.pop();
-            }
-
-            if( req == null )
-                break;
-
-            DatagramChannel ch = null;
-            try
-            {
-                ch = DatagramChannel.open();
-                ch.socket().setReuseAddress( reuseAddress );
-                ch.socket().setBroadcast( broadcast );
-                if( receiveBufferSize > 0 )
-                {
-                    ch.socket().setReceiveBufferSize( receiveBufferSize );
-                }
-                if( sendBufferSize > 0 )
-                {
-                    ch.socket().setSendBufferSize( sendBufferSize );
-                }
-                if( trafficClass > 0 )
-                {
-                    ch.socket().setTrafficClass( trafficClass );
-                }
-                ch.configureBlocking( false );
-                ch.socket().bind( req.address );
-                ch.register( selector, SelectionKey.OP_READ, req );
-                channels.put( req.address, ch );
-            }
-            catch( Throwable t )
-            {
-                req.exception = t;
-            }
-            finally
-            {
-                synchronized( req )
-                {
-                    req.done = true;
-                    req.notify();
-                }
-
-                if( ch != null && req.exception != null )
-                {
-                    try
-                    {
-                        ch.disconnect();
-                        ch.close();
-                    }
-                    catch( Throwable e )
-                    {
-                        ExceptionMonitor.getInstance().exceptionCaught( e );
-                    }
-                }
-            }
-        }
-    }
-
-    private void cancelKeys()
-    {
-        if( cancelQueue.isEmpty() )
-            return;
-
-        for( ;; )
-        {
-            CancellationRequest request;
-            synchronized( cancelQueue )
-            {
-                request = ( CancellationRequest ) cancelQueue.pop();
-            }
-            
-            if( request == null )
-            {
-                break;
-            }
-
-            DatagramChannel ch = ( DatagramChannel ) channels.remove( request.address );
-            // close the channel
-            try
-            {
-                if( ch == null )
-                {
-                    request.exception = new IllegalArgumentException(
-                            "Address not bound: " + request.address );
-                }
-                else
-                {
-                    SelectionKey key = ch.keyFor( selector );
-                    key.cancel();
-                    selector.wakeup(); // wake up again to trigger thread death
-                    ch.disconnect();
-                    ch.close();
-                }
-            }
-            catch( Throwable t )
-            {
-                ExceptionMonitor.getInstance().exceptionCaught( t );
-            }
-            finally
-            {
-                synchronized( request )
-                {
-                    request.done = true;
-                    request.notify();
-                }
-            }
-        }
-    }
-    
-    public void updateTrafficMask( DatagramSessionImpl session )
-    {
-        // There's no point in changing the traffic mask for sessions originating
-        // from this acceptor since new sessions are created every time data is
-        // received.
-    }
-
-    private static class RegistrationRequest
-    {
-        private final SocketAddress address;
-        private final IoHandler handler;
-        private final IoFilterChainBuilder filterChainBuilder;
-
-        private Throwable exception; 
-        private boolean done;
-        
-        private RegistrationRequest( SocketAddress address, IoHandler handler, IoFilterChainBuilder filterChainBuilder )
-        {
-            this.address = address;
-            this.handler = handler;
-            this.filterChainBuilder = filterChainBuilder;
-        }
-    }
-
-    private static class CancellationRequest
-    {
-        private final SocketAddress address;
-        private boolean done;
-        private RuntimeException exception;
-        
-        private CancellationRequest( SocketAddress address )
-        {
-            this.address = address;
-        }
-    }
-}
+/*
+ *   @(#) $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.transport.socket.nio.support;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.nio.channels.DatagramChannel;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.mina.common.ByteBuffer;
+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;
+import org.apache.mina.common.IoFilter.WriteRequest;
+import org.apache.mina.common.support.BaseIoAcceptor;
+import org.apache.mina.util.ExceptionUtil;
+import org.apache.mina.util.Queue;
+
+/**
+ * {@link IoAcceptor} for datagram transport (UDP/IP).
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class DatagramAcceptorDelegate extends BaseIoAcceptor implements IoAcceptor, DatagramSessionManager
+{
+    private static volatile int nextId = 0;
+
+    private final IoAcceptor wrapper;
+    private final int id = nextId ++ ;
+    private Selector selector;
+    private boolean broadcast;
+    private boolean reuseAddress;
+    private int receiveBufferSize = -1;
+    private int sendBufferSize = -1;
+    private int trafficClass = -1;
+    private final Map channels = new HashMap();
+    private final Queue registerQueue = new Queue();
+    private final Queue cancelQueue = new Queue();
+    private final Queue flushingSessions = new Queue();
+    private Worker worker;
+
+    /**
+     * Creates a new instance.
+     */
+    public DatagramAcceptorDelegate( IoAcceptor wrapper )
+    {
+        this.wrapper = wrapper;
+    }
+
+    public void bind( SocketAddress address, IoHandler handler, IoFilterChainBuilder filterChainBuilder )
+            throws IOException
+    {
+        if( address == null )
+            throw new NullPointerException( "address" );
+        if( handler == null )
+            throw new NullPointerException( "handler" );
+
+        if( !( address instanceof InetSocketAddress ) )
+            throw new IllegalArgumentException( "Unexpected address type: "
+                                                + address.getClass() );
+        if( ( ( InetSocketAddress ) address ).getPort() == 0 )
+            throw new IllegalArgumentException( "Unsupported port number: 0" );
+        
+        if( filterChainBuilder == null )
+        {
+            filterChainBuilder = IoFilterChainBuilder.NOOP;
+        }
+
+        RegistrationRequest request = new RegistrationRequest( address, handler, filterChainBuilder );
+        synchronized( this )
+        {
+            synchronized( registerQueue )
+            {
+                registerQueue.push( request );
+            }
+            startupWorker();
+        }
+        selector.wakeup();
+        
+        synchronized( request )
+        {
+            while( !request.done )
+            {
+                try
+                {
+                    request.wait();
+                }
+                catch( InterruptedException e )
+                {
+                }
+            }
+        }
+        
+        if( request.exception != null )
+        {
+            ExceptionUtil.throwException( request.exception );
+        }
+    }
+
+    public void unbind( SocketAddress address )
+    {
+        // TODO: DIRMINA-93
+        if( address == null )
+            throw new NullPointerException( "address" );
+
+        CancellationRequest request = new CancellationRequest( address );
+        synchronized( this )
+        {
+            try
+            {
+                startupWorker();
+            }
+            catch( IOException e )
+            {
+                // IOException is thrown only when Worker thread is not
+                // running and failed to open a selector.  We simply throw
+                // IllegalArgumentException here because we can simply
+                // conclude that nothing is bound to the selector.
+                throw new IllegalArgumentException( "Address not bound: " + address );
+            }
+
+            synchronized( cancelQueue )
+            {
+                cancelQueue.push( request );
+            }
+        }
+        selector.wakeup();
+        
+        synchronized( request )
+        {
+            while( !request.done )
+            {
+                try
+                {
+                    request.wait();
+                }
+                catch( InterruptedException e )
+                {
+                }
+            }
+        }
+        
+        if( request.exception != null )
+        {
+            request.exception.fillInStackTrace();
+            throw request.exception;
+        }
+    }
+    
+    public IoSession newSession( SocketAddress remoteAddress, SocketAddress localAddress )
+    {
+        if( remoteAddress == null )
+        {
+            throw new NullPointerException( "remoteAddress" );
+        }
+        if( localAddress == null )
+        {
+            throw new NullPointerException( "localAddress" );
+        }
+        
+        Selector selector = this.selector;
+        DatagramChannel ch = ( DatagramChannel ) channels.get( localAddress );
+        if( selector == null || ch == null )
+        {
+            throw new IllegalArgumentException( "Unknown localAddress: " + localAddress );
+        }
+            
+        SelectionKey key = ch.keyFor( selector );
+        if( key == null )
+        {
+            throw new IllegalArgumentException( "Unknown localAddress: " + localAddress );
+        }
+
+        RegistrationRequest req = ( RegistrationRequest ) key.attachment();
+        DatagramSessionImpl s = new DatagramSessionImpl( wrapper, this, ch, req.handler );
+        s.setRemoteAddress( remoteAddress );
+        s.setSelectionKey( key );
+        
+        try
+        {
+            this.filterChainBuilder.buildFilterChain( s.getFilterChain() );
+            req.filterChainBuilder.buildFilterChain( s.getFilterChain() );
+            ( ( DatagramFilterChain ) s.getFilterChain() ).sessionCreated( s );
+        }
+        catch( Throwable t )
+        {
+            ExceptionMonitor.getInstance().exceptionCaught( t );
+        }
+        
+        return s;
+    }
+    
+    public boolean getBroadcast()
+    {
+        return broadcast;
+    }
+    
+    public void setBroadcast( boolean broadcast )
+    {
+        this.broadcast = broadcast;
+    }
+    
+    public boolean getReuseAddress()
+    {
+        return reuseAddress;
+    }
+    
+    public void setReuseAddress( boolean reuseAddress )
+    {
+        this.reuseAddress = reuseAddress;
+    }
+
+
+    public int getReceiveBufferSize()
+    {
+        return receiveBufferSize;
+    }
+
+    public void setReceiveBufferSize( int receiveBufferSize )
+    {
+        this.receiveBufferSize = receiveBufferSize;
+    }
+
+    public int getSendBufferSize()
+    {
+        return sendBufferSize;
+    }
+
+    public void setSendBufferSize( int sendBufferSize )
+    {
+        this.sendBufferSize = sendBufferSize;
+    }
+
+    public int getTrafficClass()
+    {
+        return trafficClass;
+    }
+
+    public void setTrafficClass( int trafficClass )
+    {
+        this.trafficClass = trafficClass;
+    }
+
+    private synchronized void startupWorker() throws IOException
+    {
+        if( worker == null )
+        {
+            selector = Selector.open();
+            worker = new Worker();
+            worker.start();
+        }
+    }
+
+    public void flushSession( DatagramSessionImpl session )
+    {
+        scheduleFlush( session );
+        Selector selector = this.selector;
+        if( selector != null )
+        {
+            selector.wakeup();
+        }
+    }
+
+    public void closeSession( DatagramSessionImpl session )
+    {
+    }
+
+    private void scheduleFlush( DatagramSessionImpl session )
+    {
+        synchronized( flushingSessions )
+        {
+            flushingSessions.push( session );
+        }
+    }
+
+    private class Worker extends Thread
+    {
+        public Worker()
+        {
+            super( "DatagramAcceptor-" + id );
+        }
+
+        public void run()
+        {
+            for( ;; )
+            {
+                try
+                {
+                    int nKeys = selector.select();
+
+                    registerNew();
+
+                    if( nKeys > 0 )
+                    {
+                        processReadySessions( selector.selectedKeys() );
+                    }
+
+                    flushSessions();
+                    cancelKeys();
+
+                    if( selector.keys().isEmpty() )
+                    {
+                        synchronized( DatagramAcceptorDelegate.this )
+                        {
+                            if( selector.keys().isEmpty() &&
+                                registerQueue.isEmpty() &&
+                                cancelQueue.isEmpty() )
+                            {
+                                worker = null;
+                                try
+                                {
+                                    selector.close();
+                                }
+                                catch( IOException e )
+                                {
+                                    ExceptionMonitor.getInstance().exceptionCaught( e );
+                                }
+                                finally
+                                {
+                                    selector = null;
+                                }
+                                break;
+                            }
+                        }
+                    }
+                }
+                catch( IOException e )
+                {
+                    ExceptionMonitor.getInstance().exceptionCaught( e );
+
+                    try
+                    {
+                        Thread.sleep( 1000 );
+                    }
+                    catch( InterruptedException e1 )
+                    {
+                    }
+                }
+            }
+        }
+    }
+
+    private void processReadySessions( Set keys )
+    {
+        Iterator it = keys.iterator();
+        while( it.hasNext() )
+        {
+            SelectionKey key = ( SelectionKey ) it.next();
+            it.remove();
+
+            DatagramChannel ch = ( DatagramChannel ) key.channel();
+
+            RegistrationRequest req = ( RegistrationRequest ) key.attachment();
+            DatagramSessionImpl session =
+                new DatagramSessionImpl( wrapper, this, ch, req.handler );
+            session.setSelectionKey( key );
+            
+            try
+            {
+                ( ( DatagramFilterChain ) session.getFilterChain() ).sessionCreated( session );
+
+                if( key.isReadable() )
+                {
+                    readSession( session );
+                }
+
+                if( key.isWritable() )
+                {
+                    scheduleFlush( session );
+                }
+            }
+            catch( Throwable t )
+            {
+                ExceptionMonitor.getInstance().exceptionCaught( t );
+            }
+        }
+    }
+
+    private void readSession( DatagramSessionImpl session )
+    {
+
+        ByteBuffer readBuf = ByteBuffer.allocate( 2048 );
+        try
+        {
+            SocketAddress remoteAddress = session.getChannel().receive(
+                    readBuf.buf() );
+            if( remoteAddress != null )
+            {
+                readBuf.flip();
+                session.setRemoteAddress( remoteAddress );
+
+                ByteBuffer newBuf = ByteBuffer.allocate( readBuf.limit() );
+                newBuf.put( readBuf );
+                newBuf.flip();
+
+                session.increaseReadBytes( newBuf.remaining() );
+                ( ( DatagramFilterChain ) session.getFilterChain() ).messageReceived( session, newBuf );
+            }
+        }
+        catch( IOException e )
+        {
+            ( ( DatagramFilterChain ) session.getFilterChain() ).exceptionCaught( session, e );
+        }
+        finally
+        {
+            readBuf.release();
+        }
+    }
+
+    private void flushSessions()
+    {
+        if( flushingSessions.size() == 0 )
+            return;
+
+        for( ;; )
+        {
+            DatagramSessionImpl session;
+
+            synchronized( flushingSessions )
+            {
+                session = ( DatagramSessionImpl ) flushingSessions.pop();
+            }
+
+            if( session == null )
+                break;
+
+            try
+            {
+                flush( session );
+            }
+            catch( IOException e )
+            {
+                ( ( DatagramFilterChain ) session.getFilterChain() ).exceptionCaught( session, e );
+            }
+        }
+    }
+
+    private void flush( DatagramSessionImpl session ) throws IOException
+    {
+        DatagramChannel ch = session.getChannel();
+
+        Queue writeRequestQueue = session.getWriteRequestQueue();
+
+        WriteRequest req;
+        for( ;; )
+        {
+            synchronized( writeRequestQueue )
+            {
+                req = ( WriteRequest ) writeRequestQueue.first();
+            }
+
+            if( req == null )
+                break;
+
+            ByteBuffer buf = ( ByteBuffer ) req.getMessage();
+            if( buf.remaining() == 0 )
+            {
+                // pop and fire event
+                synchronized( writeRequestQueue )
+                {
+                    writeRequestQueue.pop();
+                }
+
+                req.getFuture().setWritten( true );
+                session.increaseWrittenWriteRequests();
+                ( ( DatagramFilterChain ) session.getFilterChain() ).messageSent( session, buf );
+                continue;
+            }
+
+            SelectionKey key = session.getSelectionKey();
+            if( key == null )
+            {
+                scheduleFlush( session );
+                break;
+            }
+            if( !key.isValid() )
+            {
+                continue;
+            }
+
+            int pos = buf.position();
+            int writtenBytes = ch
+                    .send( buf.buf(), session.getRemoteAddress() );
+
+            if( writtenBytes == 0 )
+            {
+                // Kernel buffer is full
+                key.interestOps( key.interestOps() | SelectionKey.OP_WRITE );
+            }
+            else if( writtenBytes > 0 )
+            {
+                key.interestOps( key.interestOps()
+                                 & ( ~SelectionKey.OP_WRITE ) );
+
+                // pop and fire event
+                synchronized( writeRequestQueue )
+                {
+                    writeRequestQueue.pop();
+                }
+
+                session.increaseWrittenBytes( writtenBytes );
+                req.getFuture().setWritten( true );
+                session.increaseWrittenWriteRequests();
+                ( ( DatagramFilterChain ) session.getFilterChain() ).messageSent( session, buf.position( pos ) );
+            }
+        }
+    }
+
+    private void registerNew()
+    {
+        if( registerQueue.isEmpty() )
+            return;
+
+        for( ;; )
+        {
+            RegistrationRequest req;
+            synchronized( registerQueue )
+            {
+                req = ( RegistrationRequest ) registerQueue.pop();
+            }
+
+            if( req == null )
+                break;
+
+            DatagramChannel ch = null;
+            try
+            {
+                ch = DatagramChannel.open();
+                ch.socket().setReuseAddress( reuseAddress );
+                ch.socket().setBroadcast( broadcast );
+                if( receiveBufferSize > 0 )
+                {
+                    ch.socket().setReceiveBufferSize( receiveBufferSize );
+                }
+                if( sendBufferSize > 0 )
+                {
+                    ch.socket().setSendBufferSize( sendBufferSize );
+                }
+                if( trafficClass > 0 )
+                {
+                    ch.socket().setTrafficClass( trafficClass );
+                }
+                ch.configureBlocking( false );
+                ch.socket().bind( req.address );
+                ch.register( selector, SelectionKey.OP_READ, req );
+                channels.put( req.address, ch );
+            }
+            catch( Throwable t )
+            {
+                req.exception = t;
+            }
+            finally
+            {
+                synchronized( req )
+                {
+                    req.done = true;
+                    req.notify();
+                }
+
+                if( ch != null && req.exception != null )
+                {
+                    try
+                    {
+                        ch.disconnect();
+                        ch.close();
+                    }
+                    catch( Throwable e )
+                    {
+                        ExceptionMonitor.getInstance().exceptionCaught( e );
+                    }
+                }
+            }
+        }
+    }
+
+    private void cancelKeys()
+    {
+        if( cancelQueue.isEmpty() )
+            return;
+
+        for( ;; )
+        {
+            CancellationRequest request;
+            synchronized( cancelQueue )
+            {
+                request = ( CancellationRequest ) cancelQueue.pop();
+            }
+            
+            if( request == null )
+            {
+                break;
+            }
+
+            DatagramChannel ch = ( DatagramChannel ) channels.remove( request.address );
+            // close the channel
+            try
+            {
+                if( ch == null )
+                {
+                    request.exception = new IllegalArgumentException(
+                            "Address not bound: " + request.address );
+                }
+                else
+                {
+                    SelectionKey key = ch.keyFor( selector );
+                    key.cancel();
+                    selector.wakeup(); // wake up again to trigger thread death
+                    ch.disconnect();
+                    ch.close();
+                }
+            }
+            catch( Throwable t )
+            {
+                ExceptionMonitor.getInstance().exceptionCaught( t );
+            }
+            finally
+            {
+                synchronized( request )
+                {
+                    request.done = true;
+                    request.notify();
+                }
+            }
+        }
+    }
+    
+    public void updateTrafficMask( DatagramSessionImpl session )
+    {
+        // There's no point in changing the traffic mask for sessions originating
+        // from this acceptor since new sessions are created every time data is
+        // received.
+    }
+
+    private static class RegistrationRequest
+    {
+        private final SocketAddress address;
+        private final IoHandler handler;
+        private final IoFilterChainBuilder filterChainBuilder;
+
+        private Throwable exception; 
+        private boolean done;
+        
+        private RegistrationRequest( SocketAddress address, IoHandler handler, IoFilterChainBuilder filterChainBuilder )
+        {
+            this.address = address;
+            this.handler = handler;
+            this.filterChainBuilder = filterChainBuilder;
+        }
+    }
+
+    private static class CancellationRequest
+    {
+        private final SocketAddress address;
+        private boolean done;
+        private RuntimeException exception;
+        
+        private CancellationRequest( SocketAddress address )
+        {
+            this.address = address;
+        }
+    }
+}



Mime
View raw message