You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by el...@apache.org on 2014/11/04 14:22:30 UTC

[1/4] git commit: Added some missing JavaDoc

Repository: mina
Updated Branches:
  refs/heads/2.0 6f571c1ea -> f1972fc3d


Added some missing JavaDoc

Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/aff52b8f
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/aff52b8f
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/aff52b8f

Branch: refs/heads/2.0
Commit: aff52b8fef99d3775c03421c3f721e1a3a3a66f9
Parents: 6f571c1
Author: Emmanuel Lécharny <el...@symas.com>
Authored: Tue Nov 4 11:37:28 2014 +0100
Committer: Emmanuel Lécharny <el...@symas.com>
Committed: Tue Nov 4 11:37:28 2014 +0100

----------------------------------------------------------------------
 .../src/main/java/org/apache/mina/core/future/IoFuture.java | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina/blob/aff52b8f/mina-core/src/main/java/org/apache/mina/core/future/IoFuture.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/core/future/IoFuture.java b/mina-core/src/main/java/org/apache/mina/core/future/IoFuture.java
index 519f85a..db740b0 100644
--- a/mina-core/src/main/java/org/apache/mina/core/future/IoFuture.java
+++ b/mina-core/src/main/java/org/apache/mina/core/future/IoFuture.java
@@ -32,7 +32,7 @@ import org.apache.mina.core.session.IoSession;
  */
 public interface IoFuture {
     /**
-     * Returns the {@link IoSession} which is associated with this future.
+     * @return the {@link IoSession} which is associated with this future.
      */
     IoSession getSession();
 
@@ -40,6 +40,9 @@ public interface IoFuture {
      * Wait for the asynchronous operation to complete.
      * The attached listeners will be notified when the operation is 
      * completed.
+     * 
+     * @return The instance of IoFuture that we are waiting for
+     * @exception InterruptedException If the thread is interrupted while waiting
      */
     IoFuture await() throws InterruptedException;
 
@@ -49,7 +52,7 @@ public interface IoFuture {
      * @param timeout The maximum delay to wait before getting out
      * @param unit the type of unit for the delay (seconds, minutes...)
      * @return <tt>true</tt> if the operation is completed. 
-     * @exception InterruptedException If the thread is interruped while waiting
+     * @exception InterruptedException If the thread is interrupted while waiting
      */
     boolean await(long timeout, TimeUnit unit) throws InterruptedException;
 
@@ -58,7 +61,7 @@ public interface IoFuture {
      *
      * @param timeout The maximum milliseconds to wait before getting out
      * @return <tt>true</tt> if the operation is completed.
-     * @exception InterruptedException If the thread is interruped while waiting
+     * @exception InterruptedException If the thread is interrupted while waiting
      */
     boolean await(long timeoutMillis) throws InterruptedException;
 


[3/4] git commit: Updated the Javadoc, adding the missing ones

Posted by el...@apache.org.
Updated the Javadoc, adding the missing ones

Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/32945a91
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/32945a91
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/32945a91

Branch: refs/heads/2.0
Commit: 32945a919d9e110296c638c6405db7928ed9f739
Parents: 92183f8
Author: Emmanuel Lécharny <el...@symas.com>
Authored: Tue Nov 4 11:50:12 2014 +0100
Committer: Emmanuel Lécharny <el...@symas.com>
Committed: Tue Nov 4 11:50:12 2014 +0100

----------------------------------------------------------------------
 .../apache/mina/core/future/ConnectFuture.java  |  3 +-
 .../mina/core/future/DefaultConnectFuture.java  | 63 ++++++++++++++++----
 2 files changed, 54 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina/blob/32945a91/mina-core/src/main/java/org/apache/mina/core/future/ConnectFuture.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/core/future/ConnectFuture.java b/mina-core/src/main/java/org/apache/mina/core/future/ConnectFuture.java
index 0e18626..2db17c3 100644
--- a/mina-core/src/main/java/org/apache/mina/core/future/ConnectFuture.java
+++ b/mina-core/src/main/java/org/apache/mina/core/future/ConnectFuture.java
@@ -39,7 +39,8 @@ public interface ConnectFuture extends IoFuture {
     /**
      * Returns {@link IoSession} which is the result of connect operation.
      *
-     * @return {@code true} if the connect operation is not finished yet
+     * @return The {link IoSession} instance that has been associated with the connection,
+     * if the connection was successful, {@code null} otherwise
      */
     IoSession getSession();
 

http://git-wip-us.apache.org/repos/asf/mina/blob/32945a91/mina-core/src/main/java/org/apache/mina/core/future/DefaultConnectFuture.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/core/future/DefaultConnectFuture.java b/mina-core/src/main/java/org/apache/mina/core/future/DefaultConnectFuture.java
index 7b486e4..4d283fd 100644
--- a/mina-core/src/main/java/org/apache/mina/core/future/DefaultConnectFuture.java
+++ b/mina-core/src/main/java/org/apache/mina/core/future/DefaultConnectFuture.java
@@ -28,43 +28,55 @@ import org.apache.mina.core.session.IoSession;
  * @author <a href="http://mina.apache.org">Apache MINA Project</a>
  */
 public class DefaultConnectFuture extends DefaultIoFuture implements ConnectFuture {
-
+    /** A static object stored into the ConnectFuture when teh connection has been cancelled */
     private static final Object CANCELED = new Object();
 
     /**
-     * Returns a new {@link ConnectFuture} which is already marked as 'failed to connect'.
+     * Creates a new instance.
+     */
+    public DefaultConnectFuture() {
+        super(null);
+    }
+
+    /**
+     * Creates a new instance of a Connection Failure, with the associated cause.
+     * 
+     * @param exception The exception that caused the failure
+     * @return a new {@link ConnectFuture} which is already marked as 'failed to connect'.
      */
     public static ConnectFuture newFailedFuture(Throwable exception) {
         DefaultConnectFuture failedFuture = new DefaultConnectFuture();
         failedFuture.setException(exception);
+        
         return failedFuture;
     }
 
     /**
-     * Creates a new instance.
+     * {@inheritDoc}
      */
-    public DefaultConnectFuture() {
-        super(null);
-    }
-
     @Override
     public IoSession getSession() {
         Object v = getValue();
-        if (v instanceof RuntimeException) {
+        
+        if (v instanceof IoSession) {
+            return (IoSession) v;
+        } else if (v instanceof RuntimeException) {
             throw (RuntimeException) v;
         } else if (v instanceof Error) {
             throw (Error) v;
         } else if (v instanceof Throwable) {
             throw (RuntimeIoException) new RuntimeIoException("Failed to get the session.").initCause((Throwable) v);
-        } else if (v instanceof IoSession) {
-            return (IoSession) v;
-        } else {
+        } else  {
             return null;
         }
     }
 
+    /**
+     * {@inheritDoc}
+     */
     public Throwable getException() {
         Object v = getValue();
+        
         if (v instanceof Throwable) {
             return (Throwable) v;
         } else {
@@ -72,47 +84,76 @@ public class DefaultConnectFuture extends DefaultIoFuture implements ConnectFutu
         }
     }
 
+    /**
+     * {@inheritDoc}
+     */
     public boolean isConnected() {
         return getValue() instanceof IoSession;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     public boolean isCanceled() {
         return getValue() == CANCELED;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     public void setSession(IoSession session) {
         if (session == null) {
             throw new IllegalArgumentException("session");
         }
+        
         setValue(session);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     public void setException(Throwable exception) {
         if (exception == null) {
             throw new IllegalArgumentException("exception");
         }
+        
         setValue(exception);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     public void cancel() {
         setValue(CANCELED);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public ConnectFuture await() throws InterruptedException {
         return (ConnectFuture) super.await();
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public ConnectFuture awaitUninterruptibly() {
         return (ConnectFuture) super.awaitUninterruptibly();
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public ConnectFuture addListener(IoFutureListener<?> listener) {
         return (ConnectFuture) super.addListener(listener);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public ConnectFuture removeListener(IoFutureListener<?> listener) {
         return (ConnectFuture) super.removeListener(listener);


[2/4] git commit: Added the missing Javadoc

Posted by el...@apache.org.
Added the missing Javadoc

Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/92183f83
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/92183f83
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/92183f83

Branch: refs/heads/2.0
Commit: 92183f83855e0e11ddb8009fd0226bb85883a820
Parents: aff52b8
Author: Emmanuel Lécharny <el...@symas.com>
Authored: Tue Nov 4 11:38:30 2014 +0100
Committer: Emmanuel Lécharny <el...@symas.com>
Committed: Tue Nov 4 11:38:30 2014 +0100

----------------------------------------------------------------------
 .../apache/mina/core/future/ConnectFuture.java  | 28 +++++++++++++++-----
 1 file changed, 22 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina/blob/92183f83/mina-core/src/main/java/org/apache/mina/core/future/ConnectFuture.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/core/future/ConnectFuture.java b/mina-core/src/main/java/org/apache/mina/core/future/ConnectFuture.java
index ad3cd48..0e18626 100644
--- a/mina-core/src/main/java/org/apache/mina/core/future/ConnectFuture.java
+++ b/mina-core/src/main/java/org/apache/mina/core/future/ConnectFuture.java
@@ -28,7 +28,7 @@ import org.apache.mina.core.session.IoSession;
  * <pre>
  * IoConnector connector = ...;
  * ConnectFuture future = connector.connect(...);
- * future.join(); // Wait until the connection attempt is finished.
+ * future.await(); // Wait until the connection attempt is finished.
  * IoSession session = future.getSession();
  * session.write(...);
  * </pre>
@@ -39,8 +39,7 @@ public interface ConnectFuture extends IoFuture {
     /**
      * Returns {@link IoSession} which is the result of connect operation.
      *
-     * @return <tt>null</tt> if the connect operation is not finished yet
-     * @throws RuntimeException if connection attempt failed by an exception
+     * @return {@code true} if the connect operation is not finished yet
      */
     IoSession getSession();
 
@@ -48,17 +47,18 @@ public interface ConnectFuture extends IoFuture {
      * Returns the cause of the connection failure.
      *
      * @return <tt>null</tt> if the connect operation is not finished yet,
-     *         or if the connection attempt is successful.
+     *         or if the connection attempt is successful, otherwise returns
+     *         teh cause of the exception
      */
     Throwable getException();
 
     /**
-     * Returns <tt>true</tt> if the connect operation is finished successfully.
+     * @return {@code true} if the connect operation is finished successfully.
      */
     boolean isConnected();
 
     /**
-     * Returns {@code true} if the connect operation has been canceled by
+     * @return {@code true} if the connect operation has been canceled by
      * {@link #cancel()} method.
      */
     boolean isCanceled();
@@ -67,6 +67,8 @@ public interface ConnectFuture extends IoFuture {
      * Sets the newly connected session and notifies all threads waiting for
      * this future.  This method is invoked by MINA internally.  Please do not
      * call this method directly.
+     * 
+     * @param session The created session to store in the ConnectFuture insteance
      */
     void setSession(IoSession session);
 
@@ -74,6 +76,8 @@ public interface ConnectFuture extends IoFuture {
      * Sets the exception caught due to connection failure and notifies all
      * threads waiting for this future.  This method is invoked by MINA
      * internally.  Please do not call this method directly.
+     * 
+     * @param exception The exception to store in the ConnectFuture instance
      */
     void setException(Throwable exception);
 
@@ -83,11 +87,23 @@ public interface ConnectFuture extends IoFuture {
      */
     void cancel();
 
+    /**
+     * {@inheritDoc}
+     */
     ConnectFuture await() throws InterruptedException;
 
+    /**
+     * {@inheritDoc}
+     */
     ConnectFuture awaitUninterruptibly();
 
+    /**
+     * {@inheritDoc}
+     */
     ConnectFuture addListener(IoFutureListener<?> listener);
 
+    /**
+     * {@inheritDoc}
+     */
     ConnectFuture removeListener(IoFutureListener<?> listener);
 }


[4/4] git commit: A fix for DIRMINA-994. The ConnectFuture.cancel() method now return a flag telling if the cancellation was already done or not. We don't add a cancelled future into the cancel queue anymore.

Posted by el...@apache.org.
A fix for DIRMINA-994. The ConnectFuture.cancel() method now return a
flag telling if the cancellation was already done or not. We don't add a
cancelled future into the cancel queue anymore.

Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/f1972fc3
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/f1972fc3
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/f1972fc3

Branch: refs/heads/2.0
Commit: f1972fc3de8c4074ff7b60f8c557d3c53013e30b
Parents: 32945a9
Author: Emmanuel Lécharny <el...@symas.com>
Authored: Tue Nov 4 14:22:15 2014 +0100
Committer: Emmanuel Lécharny <el...@symas.com>
Committed: Tue Nov 4 14:22:15 2014 +0100

----------------------------------------------------------------------
 .../apache/mina/core/future/ConnectFuture.java  |  5 ++++-
 .../mina/core/future/DefaultConnectFuture.java  |  4 ++--
 .../mina/core/future/DefaultIoFuture.java       |  8 +++++--
 .../polling/AbstractPollingIoConnector.java     | 22 +++++++++++++++-----
 4 files changed, 29 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina/blob/f1972fc3/mina-core/src/main/java/org/apache/mina/core/future/ConnectFuture.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/core/future/ConnectFuture.java b/mina-core/src/main/java/org/apache/mina/core/future/ConnectFuture.java
index 2db17c3..a1bc093 100644
--- a/mina-core/src/main/java/org/apache/mina/core/future/ConnectFuture.java
+++ b/mina-core/src/main/java/org/apache/mina/core/future/ConnectFuture.java
@@ -85,8 +85,11 @@ public interface ConnectFuture extends IoFuture {
     /**
      * Cancels the connection attempt and notifies all threads waiting for
      * this future.
+     * 
+     * @return {@code true} if the future has been cancelled by this call, {@code false}
+     * if the future was already cancelled.
      */
-    void cancel();
+    boolean cancel();
 
     /**
      * {@inheritDoc}

http://git-wip-us.apache.org/repos/asf/mina/blob/f1972fc3/mina-core/src/main/java/org/apache/mina/core/future/DefaultConnectFuture.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/core/future/DefaultConnectFuture.java b/mina-core/src/main/java/org/apache/mina/core/future/DefaultConnectFuture.java
index 4d283fd..1860f0c 100644
--- a/mina-core/src/main/java/org/apache/mina/core/future/DefaultConnectFuture.java
+++ b/mina-core/src/main/java/org/apache/mina/core/future/DefaultConnectFuture.java
@@ -123,8 +123,8 @@ public class DefaultConnectFuture extends DefaultIoFuture implements ConnectFutu
     /**
      * {@inheritDoc}
      */
-    public void cancel() {
-        setValue(CANCELED);
+    public boolean cancel() {
+        return setValue(CANCELED);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/mina/blob/f1972fc3/mina-core/src/main/java/org/apache/mina/core/future/DefaultIoFuture.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/core/future/DefaultIoFuture.java b/mina-core/src/main/java/org/apache/mina/core/future/DefaultIoFuture.java
index c664aab..fa59906 100644
--- a/mina-core/src/main/java/org/apache/mina/core/future/DefaultIoFuture.java
+++ b/mina-core/src/main/java/org/apache/mina/core/future/DefaultIoFuture.java
@@ -293,12 +293,14 @@ public class DefaultIoFuture implements IoFuture {
      * Sets the result of the asynchronous operation, and mark it as finished.
      * 
      * @param newValue The result to store into the Future
+     * @return {@code true} if the value has been set, {@code false} if
+     * the future already has a value (thus is in ready state)
      */
-    public void setValue(Object newValue) {
+    public boolean setValue(Object newValue) {
         synchronized (lock) {
             // Allowed only once.
             if (ready) {
-                return;
+                return false;
             }
 
             result = newValue;
@@ -312,6 +314,8 @@ public class DefaultIoFuture implements IoFuture {
 
         // Last, not least, inform the listeners
         notifyListeners();
+        
+        return true;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/mina/blob/f1972fc3/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoConnector.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoConnector.java b/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoConnector.java
index 147ad1e..167e8a5 100644
--- a/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoConnector.java
+++ b/mina-core/src/main/java/org/apache/mina/core/polling/AbstractPollingIoConnector.java
@@ -569,20 +569,25 @@ public abstract class AbstractPollingIoConnector<T extends AbstractIoSession, H>
     }
 
     public final class ConnectionRequest extends DefaultConnectFuture {
+        /** The handle associated with this connection request */
         private final H handle;
 
+        /** The time up to this connection request will be valid */
         private final long deadline;
 
+        /** The callback to call when the session is initialized */
         private final IoSessionInitializer<? extends ConnectFuture> sessionInitializer;
 
         public ConnectionRequest(H handle, IoSessionInitializer<? extends ConnectFuture> callback) {
             this.handle = handle;
             long timeout = getConnectTimeoutMillis();
+            
             if (timeout <= 0L) {
                 this.deadline = Long.MAX_VALUE;
             } else {
                 this.deadline = System.currentTimeMillis() + timeout;
             }
+            
             this.sessionInitializer = callback;
         }
 
@@ -599,13 +604,20 @@ public abstract class AbstractPollingIoConnector<T extends AbstractIoSession, H>
         }
 
         @Override
-        public void cancel() {
+        public boolean cancel() {
             if (!isDone()) {
-                super.cancel();
-                cancelQueue.add(this);
-                startupWorker();
-                wakeup();
+                boolean justCancelled = super.cancel();
+                
+                // We haven't cancelled the request before, so add the future
+                // in the cancel queue.
+                if (justCancelled) {
+                    cancelQueue.add(this);
+                    startupWorker();
+                    wakeup();
+                }
             }
+            
+            return true;
         }
     }
 }