directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 9680 - incubator/directory/eve/trunk/eve/frontend/listener/pojo-impl/src/java/org/apache/eve/listener
Date Mon, 22 Mar 2004 10:42:37 GMT
Author: akarasulu
Date: Mon Mar 22 02:42:37 2004
New Revision: 9680

Modified:
   incubator/directory/eve/trunk/eve/frontend/listener/pojo-impl/src/java/org/apache/eve/listener/DefaultListenerManager.java
Log:
need to clean this up more but made it disconnect listeners

Modified: incubator/directory/eve/trunk/eve/frontend/listener/pojo-impl/src/java/org/apache/eve/listener/DefaultListenerManager.java
==============================================================================
--- incubator/directory/eve/trunk/eve/frontend/listener/pojo-impl/src/java/org/apache/eve/listener/DefaultListenerManager.java
(original)
+++ incubator/directory/eve/trunk/eve/frontend/listener/pojo-impl/src/java/org/apache/eve/listener/DefaultListenerManager.java
Mon Mar 22 02:42:37 2004
@@ -1,52 +1,19 @@
 /*
-
- ============================================================================
-                   The Apache Software License, Version 1.1
- ============================================================================
-
- Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
-
- Redistribution and use in source and binary forms, with or without modifica-
- tion, are permitted provided that the following conditions are met:
-
- 1. Redistributions of  source code must  retain the above copyright  notice,
-    this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright notice,
-    this list of conditions and the following disclaimer in the documentation
-    and/or other materials provided with the distribution.
-
- 3. The end-user documentation included with the redistribution, if any, must
-    include  the following  acknowledgment:  "This product includes  software
-    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
-    Alternately, this  acknowledgment may  appear in the software itself,  if
-    and wherever such third-party acknowledgments normally appear.
-
- 4. The names "Eve Directory Server", "Apache Directory Project", "Apache Eve" 
-    and "Apache Software Foundation"  must not be used to endorse or promote
-    products derived  from this  software without  prior written
-    permission. For written permission, please contact apache@apache.org.
-
- 5. Products  derived from this software may not  be called "Apache", nor may
-    "Apache" appear  in their name,  without prior written permission  of the
-    Apache Software Foundation.
-
- THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
- APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
- INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
- DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
- OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
- ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
- (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- This software  consists of voluntary contributions made  by many individuals
- on  behalf of the Apache Software  Foundation. For more  information on the
- Apache Software Foundation, please see <http://www.apache.org/>.
-
-*/
+ *   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.eve.listener ;
 
 
@@ -58,6 +25,7 @@
 import java.io.IOException ;
 import java.net.InetAddress ;
 import java.net.InetSocketAddress ;
+import java.net.Socket;
 
 import java.nio.channels.Selector ;
 import java.nio.channels.SelectionKey ;
@@ -74,6 +42,8 @@
  * A listener manager that uses non-blocking NIO based constructs to detect
  * client connections on server socket listeners.
  * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">
+ * Apache Directory Project</a>
  * @version $Rev$
  */
 public class DefaultListenerManager 
@@ -305,18 +275,14 @@
      */
     public void start() throws InterruptedException
     {
-        synchronized( m_hasStarted )
+        if ( m_hasStarted.booleanValue() )
         {
-            if ( m_hasStarted.booleanValue() )
-            {
-                throw new IllegalStateException( "Already started!" ) ;
-            }
-            
-            m_hasStarted = new Boolean( true ) ;
-            m_thread = new Thread( this ) ;
-            m_thread.start() ;
+            throw new IllegalStateException( "Already started!" ) ;
         }
         
+        m_hasStarted = new Boolean( true ) ;
+        m_thread = new Thread( this ) ;
+        m_thread.start() ;
         m_monitor.started() ;
     }
     
@@ -329,15 +295,37 @@
      */
     public void stop() throws InterruptedException
     {
-        synchronized( m_hasStarted )
+        m_hasStarted = new Boolean( false ) ;
+        m_selector.wakeup() ;
+        
+        while ( m_thread.isAlive() || ! m_clients.isEmpty() )
         {
-            m_hasStarted = new Boolean( false ) ;
-            m_selector.wakeup() ;
-            
-            while ( m_thread.isAlive() )
+            if ( ! m_clients.isEmpty() )
             {
-                Thread.sleep( 100 ) ;
+                synchronized( m_clients )
+                {
+                    Iterator list = m_clients.iterator() ;
+                    while ( list.hasNext() )
+                    {
+                        ClientKey key = ( ClientKey ) list.next() ;
+                        
+                        try
+                        {
+                            Socket socket = key.getSocket() ;
+                            socket.close() ;
+                            list.remove() ;
+                        }
+                        catch( IOException e )
+                        {
+                            // monitor.doSomthing( e ) ;
+                            e.printStackTrace() ;
+                        }
+                    }
+                }
             }
+            
+            Thread.sleep( 100 ) ;
+            m_selector.wakeup() ;
         }
         
         m_monitor.stopped() ;

Mime
View raw message