directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r440259 - in /directory/trunks/mina: core/src/main/java/org/apache/mina/common/ core/src/main/java/org/apache/mina/common/support/ core/src/main/java/org/apache/mina/transport/socket/nio/ core/src/main/java/org/apache/mina/transport/vmpipe/...
Date Tue, 05 Sep 2006 05:01:47 GMT
Author: trustin
Date: Mon Sep  4 22:01:47 2006
New Revision: 440259

URL: http://svn.apache.org/viewvc?view=rev&rev=440259
Log:
Fixed issue: DIRMINA-239 (Allow multiple Callbacks per IoFuture)
* Replaced IoFuture.Callback with IoFutureListener
* Replaced IoFuture.get/setCallback() with add/removeListener()
* Fixed all compilation errors caused by the changes above


Added:
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFutureListener.java
  (with props)
Modified:
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFilter.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFuture.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultIoFuture.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAcceptor.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/filter/StreamWriteFilterTest.java
    directory/trunks/mina/examples/src/main/java/org/apache/mina/examples/proxy/ClientToProxyIoHandler.java
    directory/trunks/mina/filter-ssl/src/main/java/org/apache/mina/filter/SSLFilter.java

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFilter.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFilter.java?view=diff&rev=440259&r1=440258&r2=440259
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFilter.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFilter.java Mon Sep
 4 22:01:47 2006
@@ -289,14 +289,14 @@
                 return true;
             }
 
-            public Callback getCallback()
+            public void addListener( IoFutureListener listener )
             {
-                return null;
+                throw new IllegalStateException( "You can't add a listener to a dummy future."
);
             }
 
-            public void setCallback( Callback callback )
+            public void removeListener( IoFutureListener listener )
             {
-                throw new IllegalStateException( "You can't set a callback for a dummy future."
);
+                throw new IllegalStateException( "You can't add a listener to a dummy future."
);
             }
         };
         

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFuture.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFuture.java?view=diff&rev=440259&r1=440258&r2=440259
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFuture.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFuture.java Mon Sep
 4 22:01:47 2006
@@ -22,41 +22,13 @@
 
 /**
  * Represents the result of an ashynchronous I/O operation.
- *  
+ * 
  * @author The Apache Directory Project (mina-dev@directory.apache.org)
  * @version $Rev$, $Date$
  */
 public interface IoFuture
 {
     /**
-     * Something interested in being notified when the result
-     * of an {@link IoFuture} becomes available.
-     */
-    public interface Callback
-    {
-        /**
-         * A {@link Callback} that closes the {@link IoSession} which is
-         * associated with the specified {@link IoFuture}.
-         */
-        static Callback CLOSE = new Callback()
-        {
-            public void operationComplete( IoFuture future )
-            {
-                future.getSession().close();
-            }
-        };
-        
-        /**
-         * Invoked when the operation associated with the {@link IoFuture}
-         * has been completed.
-         * 
-         * @param future  The source {@link IoFuture} which called this
-         *                callback.
-         */
-        void operationComplete( IoFuture future );
-    }
-
-    /**
      * Returns the {@link IoSession} which is associated with this future.
      */
     IoSession getSession();
@@ -84,14 +56,14 @@
     boolean isReady();
 
     /**
-     * Returns a {@link Callback} which is associated with this future.
+     * Adds an event <tt>listener</tt> which is notified when
+     * the state of this future changes.
      */
-    Callback getCallback();
+    void addListener( IoFutureListener listener );
     
     /**
-     * Sets a {@link Callback} to be notified when a result
-     * becomes available.  If tth result has already become obtained,
-     * the specified callback is notified immediately
+     * Removes an existing event <tt>listener</tt> which is notified when
+     * the state of this future changes.
      */
-    void setCallback( Callback callback );
+    void removeListener( IoFutureListener listener );
 }

Added: directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFutureListener.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFutureListener.java?view=auto&rev=440259
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFutureListener.java
(added)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFutureListener.java
Mon Sep  4 22:01:47 2006
@@ -0,0 +1,53 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.EventListener;
+
+/**
+ * Something interested in being notified when the result
+ * of an {@link IoFuture} becomes available.
+ * 
+ * @author The Apache Directory Project (mina-dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public interface IoFutureListener extends EventListener
+{
+    /**
+     * An {@link IoFutureListener} that closes the {@link IoSession} which is
+     * associated with the specified {@link IoFuture}.
+     */
+    static IoFutureListener CLOSE = new IoFutureListener()
+    {
+        public void operationComplete( IoFuture future )
+        {
+            future.getSession().close();
+        }
+    };
+    
+    /**
+     * Invoked when the operation associated with the {@link IoFuture}
+     * has been completed.
+     * 
+     * @param future  The source {@link IoFuture} which called this
+     *                callback.
+     */
+    void operationComplete( IoFuture future );
+}
\ No newline at end of file

Propchange: directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFutureListener.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultIoFuture.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultIoFuture.java?view=diff&rev=440259&r1=440258&r2=440259
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultIoFuture.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/DefaultIoFuture.java
Mon Sep  4 22:01:47 2006
@@ -19,7 +19,12 @@
  */
 package org.apache.mina.common.support;
 
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
 import org.apache.mina.common.IoFuture;
+import org.apache.mina.common.IoFutureListener;
 import org.apache.mina.common.IoSession;
 
 /**
@@ -32,8 +37,8 @@
 {
     private final IoSession session;
     private final Object lock;
+    private final List listeners = new ArrayList();
     private Object result;
-    private Callback callback;
     private boolean ready;
 
     /**
@@ -153,10 +158,7 @@
             ready = true;
             lock.notifyAll();
     
-            if( callback != null )
-            {
-                invokeCallback();
-            }
+            notifyListeners();
         }
     }
 
@@ -171,33 +173,43 @@
         }
     }
     
-    public Callback getCallback()
+    public void addListener( IoFutureListener listener )
     {
+        if( listener == null )
+        {
+            throw new NullPointerException( "listener" );
+        }
+
         synchronized( lock )
         {
-            return callback;
+            listeners.add( listener );
+            if( ready )
+            {
+                listener.operationComplete( this );
+            }
         }
     }
     
-    public void setCallback( Callback callback ) 
+    public void removeListener( IoFutureListener listener )
     {
-        if( callback == null )
+        if( listener == null )
         {
-            throw new NullPointerException( "callback" );
+            throw new NullPointerException( "listener" );
         }
 
         synchronized( lock )
         {
-            this.callback = callback;
-            if( ready )
-            {
-                invokeCallback();
-            }
+            listeners.remove( listener );
         }
     }
 
-    private void invokeCallback()
+    private void notifyListeners()
     {
-        callback.operationComplete( this );
+        synchronized( lock )
+        {
+            for( Iterator i = listeners.iterator(); i.hasNext(); ) {
+                ( ( IoFutureListener ) i.next() ).operationComplete( this );
+            }
+        }
     }
 }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAcceptor.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAcceptor.java?view=diff&rev=440259&r1=440258&r2=440259
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAcceptor.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAcceptor.java
Mon Sep  4 22:01:47 2006
@@ -19,17 +19,6 @@
  */
 package org.apache.mina.transport.socket.nio;
 
-import org.apache.mina.common.ExceptionMonitor;
-import org.apache.mina.common.IoAcceptor;
-import org.apache.mina.common.IoAcceptorConfig;
-import org.apache.mina.common.IoFuture;
-import org.apache.mina.common.IoHandler;
-import org.apache.mina.common.IoServiceConfig;
-import org.apache.mina.common.IoSession;
-import org.apache.mina.common.support.BaseIoAcceptor;
-import org.apache.mina.util.IdentityHashSet;
-import org.apache.mina.util.Queue;
-
 import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.net.SocketAddress;
@@ -48,6 +37,18 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.mina.common.ExceptionMonitor;
+import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.common.IoAcceptorConfig;
+import org.apache.mina.common.IoFuture;
+import org.apache.mina.common.IoFutureListener;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoServiceConfig;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.support.BaseIoAcceptor;
+import org.apache.mina.util.IdentityHashSet;
+import org.apache.mina.util.Queue;
+
 /**
  * {@link IoAcceptor} for socket transport (TCP/IP).
  *
@@ -287,7 +288,7 @@
                     // removed from managedSessions by the SocketIoProcessor.
                     continue;
                 }
-                tempSessions[i].close().setCallback( new IoFuture.Callback()
+                tempSessions[i].close().addListener( new IoFutureListener()
                 {
                     public void operationComplete( IoFuture future )
                     {

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java?view=diff&rev=440259&r1=440258&r2=440259
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java
Mon Sep  4 22:01:47 2006
@@ -33,6 +33,7 @@
 
 import org.apache.mina.common.IoAcceptorConfig;
 import org.apache.mina.common.IoFuture;
+import org.apache.mina.common.IoFutureListener;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoServiceConfig;
 import org.apache.mina.common.IoSession;
@@ -155,7 +156,7 @@
                     // removed from managedSessions by the VmPipeFilterChain.
                     continue;
                 }
-                tempSessions[ i ].close().setCallback( new IoFuture.Callback()
+                tempSessions[ i ].close().addListener( new IoFutureListener()
                 {
                     public void operationComplete( IoFuture future )
                     {

Modified: directory/trunks/mina/core/src/test/java/org/apache/mina/filter/StreamWriteFilterTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/test/java/org/apache/mina/filter/StreamWriteFilterTest.java?view=diff&rev=440259&r1=440258&r2=440259
==============================================================================
--- directory/trunks/mina/core/src/test/java/org/apache/mina/filter/StreamWriteFilterTest.java
(original)
+++ directory/trunks/mina/core/src/test/java/org/apache/mina/filter/StreamWriteFilterTest.java
Mon Sep  4 22:01:47 2006
@@ -33,6 +33,7 @@
 import org.apache.mina.common.IdleStatus;
 import org.apache.mina.common.IoAcceptor;
 import org.apache.mina.common.IoConnector;
+import org.apache.mina.common.IoFutureListener;
 import org.apache.mina.common.IoHandlerAdapter;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.WriteFuture;
@@ -620,14 +621,12 @@
             return true;
         }
 
-        public Callback getCallback()
+        public void addListener( IoFutureListener listener )
         {
-            return null;
         }
 
-        public void setCallback( Callback callback )
+        public void removeListener( IoFutureListener listener )
         {
-            throw new IllegalStateException( "You can't set a callback for a dummy future."
);
         }
     }
 }

Modified: directory/trunks/mina/examples/src/main/java/org/apache/mina/examples/proxy/ClientToProxyIoHandler.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/examples/src/main/java/org/apache/mina/examples/proxy/ClientToProxyIoHandler.java?view=diff&rev=440259&r1=440258&r2=440259
==============================================================================
--- directory/trunks/mina/examples/src/main/java/org/apache/mina/examples/proxy/ClientToProxyIoHandler.java
(original)
+++ directory/trunks/mina/examples/src/main/java/org/apache/mina/examples/proxy/ClientToProxyIoHandler.java
Mon Sep  4 22:01:47 2006
@@ -24,6 +24,7 @@
 import org.apache.mina.common.ConnectFuture;
 import org.apache.mina.common.IoConnector;
 import org.apache.mina.common.IoFuture;
+import org.apache.mina.common.IoFutureListener;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.RuntimeIOException;
 import org.apache.mina.common.TrafficMask;
@@ -51,8 +52,8 @@
 
     public void sessionOpened( final IoSession session ) throws Exception 
     {
-        connector.connect( address, connectorHandler ).setCallback( 
-                new IoFuture.Callback()
+        connector.connect( address, connectorHandler ).addListener( 
+                new IoFutureListener()
         {
             public void operationComplete( IoFuture f )
             {

Modified: directory/trunks/mina/filter-ssl/src/main/java/org/apache/mina/filter/SSLFilter.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/filter-ssl/src/main/java/org/apache/mina/filter/SSLFilter.java?view=diff&rev=440259&r1=440258&r2=440259
==============================================================================
--- directory/trunks/mina/filter-ssl/src/main/java/org/apache/mina/filter/SSLFilter.java (original)
+++ directory/trunks/mina/filter-ssl/src/main/java/org/apache/mina/filter/SSLFilter.java Mon
Sep  4 22:01:47 2006
@@ -30,6 +30,7 @@
 import org.apache.mina.common.IoFilterAdapter;
 import org.apache.mina.common.IoFilterChain;
 import org.apache.mina.common.IoFuture;
+import org.apache.mina.common.IoFutureListener;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.WriteFuture;
@@ -549,7 +550,7 @@
                 }
                 else
                 {
-                    future.setCallback( new IoFuture.Callback()
+                    future.addListener( new IoFutureListener()
                     {
                         public void operationComplete( IoFuture future )
                         {



Mime
View raw message