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 15:32:00 UTC
[1/2] git commit: Updated the Javadoc, adding the missing one
Repository: mina
Updated Branches:
refs/heads/2.0 f1972fc3d -> bdad876b2
Updated the Javadoc, adding the missing one
Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/4adb1cd6
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/4adb1cd6
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/4adb1cd6
Branch: refs/heads/2.0
Commit: 4adb1cd61befe56c740cad215ddd9553ad61ffb3
Parents: f1972fc
Author: Emmanuel Lécharny <el...@symas.com>
Authored: Tue Nov 4 14:38:00 2014 +0100
Committer: Emmanuel Lécharny <el...@symas.com>
Committed: Tue Nov 4 14:38:00 2014 +0100
----------------------------------------------------------------------
.../apache/mina/core/future/CloseFuture.java | 18 +++++++++--
.../apache/mina/core/future/ConnectFuture.java | 2 +-
.../org/apache/mina/core/future/ReadFuture.java | 33 +++++++++++++++-----
.../apache/mina/core/future/WriteFuture.java | 12 ++++---
4 files changed, 51 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina/blob/4adb1cd6/mina-core/src/main/java/org/apache/mina/core/future/CloseFuture.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/core/future/CloseFuture.java b/mina-core/src/main/java/org/apache/mina/core/future/CloseFuture.java
index 0723e61..0235c03 100644
--- a/mina-core/src/main/java/org/apache/mina/core/future/CloseFuture.java
+++ b/mina-core/src/main/java/org/apache/mina/core/future/CloseFuture.java
@@ -26,8 +26,10 @@ package org.apache.mina.core.future;
* <pre>
* IoSession session = ...;
* CloseFuture future = session.close(true);
+ *
* // Wait until the connection is closed
* future.awaitUninterruptibly();
+ *
* // Now connection should be closed.
* assert future.isClosed();
* </pre>
@@ -36,22 +38,34 @@ package org.apache.mina.core.future;
*/
public interface CloseFuture extends IoFuture {
/**
- * Returns <tt>true</tt> if the close request is finished and the session is closed.
+ * @return <tt>true</tt> if the close request is finished and the session is closed.
*/
boolean isClosed();
/**
* Marks this future as closed and notifies all threads waiting for this
- * future. This method is invoked by MINA internally. Please do not call
+ * future. This method is invoked by MINA internally. Please do not call
* this method directly.
*/
void setClosed();
+ /**
+ * {@inheritDoc}
+ */
CloseFuture await() throws InterruptedException;
+ /**
+ * {@inheritDoc}
+ */
CloseFuture awaitUninterruptibly();
+ /**
+ * {@inheritDoc}
+ */
CloseFuture addListener(IoFutureListener<?> listener);
+ /**
+ * {@inheritDoc}
+ */
CloseFuture removeListener(IoFutureListener<?> listener);
}
http://git-wip-us.apache.org/repos/asf/mina/blob/4adb1cd6/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 a1bc093..5eae6a9 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.await(); // Wait until the connection attempt is finished.
+ * future.awaitUninterruptibly(); // Wait until the connection attempt is finished.
* IoSession session = future.getSession();
* session.write(...);
* </pre>
http://git-wip-us.apache.org/repos/asf/mina/blob/4adb1cd6/mina-core/src/main/java/org/apache/mina/core/future/ReadFuture.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/core/future/ReadFuture.java b/mina-core/src/main/java/org/apache/mina/core/future/ReadFuture.java
index b14e06a..1f03523 100644
--- a/mina-core/src/main/java/org/apache/mina/core/future/ReadFuture.java
+++ b/mina-core/src/main/java/org/apache/mina/core/future/ReadFuture.java
@@ -27,12 +27,15 @@ import org.apache.mina.core.session.IoSession;
* <h3>Example</h3>
* <pre>
* IoSession session = ...;
+ *
* // useReadOperation must be enabled to use read operation.
* session.getConfig().setUseReadOperation(true);
*
* ReadFuture future = session.read();
+ *
* // Wait until a message is received.
- * future.await();
+ * future.awaitUninterruptibly();
+ *
* try {
* Object message = future.getMessage();
* } catch (Exception e) {
@@ -45,26 +48,26 @@ import org.apache.mina.core.session.IoSession;
public interface ReadFuture extends IoFuture {
/**
- * Returns the received message. It returns <tt>null</tt> if this
- * future is not ready or the associated {@link IoSession} has been closed.
+ * Get the read message.
*
- * @throws RuntimeException if read or any relevant operation has failed.
+ * @return the received message. It returns <tt>null</tt> if this
+ * future is not ready or the associated {@link IoSession} has been closed.
*/
Object getMessage();
/**
- * Returns <tt>true</tt> if a message was received successfully.
+ * @return <tt>true</tt> if a message was received successfully.
*/
boolean isRead();
/**
- * Returns <tt>true</tt> if the {@link IoSession} associated with this
+ * @return <tt>true</tt> if the {@link IoSession} associated with this
* future has been closed.
*/
boolean isClosed();
/**
- * Returns the cause of the read failure if and only if the read
+ * @return the cause of the read failure if and only if the read
* operation has failed due to an {@link Exception}. Otherwise,
* <tt>null</tt> is returned.
*/
@@ -74,6 +77,8 @@ public interface ReadFuture extends IoFuture {
* Sets the message is written, and notifies all threads waiting for
* this future. This method is invoked by MINA internally. Please do
* not call this method directly.
+ *
+ * @param message The received message to store in this future
*/
void setRead(Object message);
@@ -87,14 +92,28 @@ public interface ReadFuture extends IoFuture {
* Sets the cause of the read failure, and notifies all threads waiting
* for this future. This method is invoked by MINA internally. Please
* do not call this method directly.
+ *
+ * @param cause The exception to store in the Future instance
*/
void setException(Throwable cause);
+ /**
+ * {@inheritDoc}
+ */
ReadFuture await() throws InterruptedException;
+ /**
+ * {@inheritDoc}
+ */
ReadFuture awaitUninterruptibly();
+ /**
+ * {@inheritDoc}
+ */
ReadFuture addListener(IoFutureListener<?> listener);
+ /**
+ * {@inheritDoc}
+ */
ReadFuture removeListener(IoFutureListener<?> listener);
}
http://git-wip-us.apache.org/repos/asf/mina/blob/4adb1cd6/mina-core/src/main/java/org/apache/mina/core/future/WriteFuture.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/core/future/WriteFuture.java b/mina-core/src/main/java/org/apache/mina/core/future/WriteFuture.java
index a8ef241..8991b37 100644
--- a/mina-core/src/main/java/org/apache/mina/core/future/WriteFuture.java
+++ b/mina-core/src/main/java/org/apache/mina/core/future/WriteFuture.java
@@ -26,15 +26,17 @@ package org.apache.mina.core.future;
* <pre>
* IoSession session = ...;
* WriteFuture future = session.write(...);
+ *
* // Wait until the message is completely written out to the O/S buffer.
- * future.join();
+ * future.awaitUninterruptibly();
+ *
* if( future.isWritten() )
* {
* // The message has been written successfully.
* }
* else
* {
- * // The messsage couldn't be written out completely for some reason.
+ * // The message couldn't be written out completely for some reason.
* // (e.g. Connection is closed)
* }
* </pre>
@@ -43,12 +45,12 @@ package org.apache.mina.core.future;
*/
public interface WriteFuture extends IoFuture {
/**
- * Returns <tt>true</tt> if the write operation is finished successfully.
+ * @return <tt>true</tt> if the write operation is finished successfully.
*/
boolean isWritten();
/**
- * Returns the cause of the write failure if and only if the write
+ * @return the cause of the write failure if and only if the write
* operation has failed due to an {@link Exception}. Otherwise,
* <tt>null</tt> is returned.
*/
@@ -65,6 +67,8 @@ public interface WriteFuture extends IoFuture {
* Sets the cause of the write failure, and notifies all threads waiting
* for this future. This method is invoked by MINA internally. Please
* do not call this method directly.
+ *
+ * @param cause The exception to store in the Future instance
*/
void setException(Throwable cause);
[2/2] git commit: o Added the missing Javadoc o Removed the
ExceptionHolder inner class in DefaultReadFuture : it's useless o A few
typoes fix
Posted by el...@apache.org.
o Added the missing Javadoc
o Removed the ExceptionHolder inner class in DefaultReadFuture : it's
useless
o A few typoes fix
Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/bdad876b
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/bdad876b
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/bdad876b
Branch: refs/heads/2.0
Commit: bdad876b214c8a6f68382e29a2b145e69225c72a
Parents: 4adb1cd
Author: Emmanuel Lécharny <el...@symas.com>
Authored: Tue Nov 4 15:31:38 2014 +0100
Committer: Emmanuel Lécharny <el...@symas.com>
Committed: Tue Nov 4 15:31:38 2014 +0100
----------------------------------------------------------------------
.../mina/core/future/DefaultCloseFuture.java | 20 +++++
.../mina/core/future/DefaultReadFuture.java | 81 ++++++++++++++------
.../mina/core/future/DefaultWriteFuture.java | 21 ++++-
.../mina/core/service/AbstractIoService.java | 6 ++
4 files changed, 101 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina/blob/bdad876b/mina-core/src/main/java/org/apache/mina/core/future/DefaultCloseFuture.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/core/future/DefaultCloseFuture.java b/mina-core/src/main/java/org/apache/mina/core/future/DefaultCloseFuture.java
index 3121e99..8378694 100644
--- a/mina-core/src/main/java/org/apache/mina/core/future/DefaultCloseFuture.java
+++ b/mina-core/src/main/java/org/apache/mina/core/future/DefaultCloseFuture.java
@@ -29,11 +29,16 @@ import org.apache.mina.core.session.IoSession;
public class DefaultCloseFuture extends DefaultIoFuture implements CloseFuture {
/**
* Creates a new instance.
+ *
+ * @param session The associated session
*/
public DefaultCloseFuture(IoSession session) {
super(session);
}
+ /**
+ * {@inheritDoc}
+ */
public boolean isClosed() {
if (isDone()) {
return ((Boolean) getValue()).booleanValue();
@@ -42,25 +47,40 @@ public class DefaultCloseFuture extends DefaultIoFuture implements CloseFuture {
}
}
+ /**
+ * {@inheritDoc}
+ */
public void setClosed() {
setValue(Boolean.TRUE);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public CloseFuture await() throws InterruptedException {
return (CloseFuture) super.await();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public CloseFuture awaitUninterruptibly() {
return (CloseFuture) super.awaitUninterruptibly();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public CloseFuture addListener(IoFutureListener<?> listener) {
return (CloseFuture) super.addListener(listener);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public CloseFuture removeListener(IoFutureListener<?> listener) {
return (CloseFuture) super.removeListener(listener);
http://git-wip-us.apache.org/repos/asf/mina/blob/bdad876b/mina-core/src/main/java/org/apache/mina/core/future/DefaultReadFuture.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/core/future/DefaultReadFuture.java b/mina-core/src/main/java/org/apache/mina/core/future/DefaultReadFuture.java
index fb1756f..97199c1 100644
--- a/mina-core/src/main/java/org/apache/mina/core/future/DefaultReadFuture.java
+++ b/mina-core/src/main/java/org/apache/mina/core/future/DefaultReadFuture.java
@@ -30,34 +30,39 @@ import org.apache.mina.core.session.IoSession;
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
public class DefaultReadFuture extends DefaultIoFuture implements ReadFuture {
-
+ /** A static object used when the session is closed */
private static final Object CLOSED = new Object();
/**
* Creates a new instance.
+ *
+ * @param session The associated session
*/
public DefaultReadFuture(IoSession session) {
super(session);
}
+ /**
+ * {@inheritDoc}
+ */
public Object getMessage() {
if (isDone()) {
Object v = getValue();
+
if (v == CLOSED) {
return null;
}
- if (v instanceof ExceptionHolder) {
- v = ((ExceptionHolder) v).exception;
- if (v instanceof RuntimeException) {
- throw (RuntimeException) v;
- }
- if (v instanceof Error) {
- throw (Error) v;
- }
- if (v instanceof IOException || v instanceof Exception) {
- throw new RuntimeIoException((Exception) v);
- }
+ if (v instanceof RuntimeException) {
+ throw (RuntimeException) v;
+ }
+
+ if (v instanceof Error) {
+ throw (Error) v;
+ }
+
+ if (v instanceof IOException || v instanceof Exception) {
+ throw new RuntimeIoException((Exception) v);
}
return v;
@@ -66,75 +71,103 @@ public class DefaultReadFuture extends DefaultIoFuture implements ReadFuture {
return null;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean isRead() {
if (isDone()) {
Object v = getValue();
- return (v != CLOSED && !(v instanceof ExceptionHolder));
+
+ return (v != CLOSED && !(v instanceof Throwable));
}
+
return false;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean isClosed() {
if (isDone()) {
return getValue() == CLOSED;
}
+
return false;
}
+ /**
+ * {@inheritDoc}
+ */
public Throwable getException() {
if (isDone()) {
Object v = getValue();
- if (v instanceof ExceptionHolder) {
- return ((ExceptionHolder) v).exception;
+
+ if (v instanceof Throwable) {
+ return (Throwable)v;
}
}
+
return null;
}
+ /**
+ * {@inheritDoc}
+ */
public void setClosed() {
setValue(CLOSED);
}
+ /**
+ * {@inheritDoc}
+ */
public void setRead(Object message) {
if (message == null) {
throw new IllegalArgumentException("message");
}
+
setValue(message);
}
+ /**
+ * {@inheritDoc}
+ */
public void setException(Throwable exception) {
if (exception == null) {
throw new IllegalArgumentException("exception");
}
- setValue(new ExceptionHolder(exception));
+ setValue(exception);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public ReadFuture await() throws InterruptedException {
return (ReadFuture) super.await();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public ReadFuture awaitUninterruptibly() {
return (ReadFuture) super.awaitUninterruptibly();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public ReadFuture addListener(IoFutureListener<?> listener) {
return (ReadFuture) super.addListener(listener);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public ReadFuture removeListener(IoFutureListener<?> listener) {
return (ReadFuture) super.removeListener(listener);
}
-
- private static class ExceptionHolder {
- private final Throwable exception;
-
- private ExceptionHolder(Throwable exception) {
- this.exception = exception;
- }
- }
}
http://git-wip-us.apache.org/repos/asf/mina/blob/bdad876b/mina-core/src/main/java/org/apache/mina/core/future/DefaultWriteFuture.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/core/future/DefaultWriteFuture.java b/mina-core/src/main/java/org/apache/mina/core/future/DefaultWriteFuture.java
index 2e7b2bb..59377e2 100644
--- a/mina-core/src/main/java/org/apache/mina/core/future/DefaultWriteFuture.java
+++ b/mina-core/src/main/java/org/apache/mina/core/future/DefaultWriteFuture.java
@@ -29,24 +29,35 @@ import org.apache.mina.core.session.IoSession;
public class DefaultWriteFuture extends DefaultIoFuture implements WriteFuture {
/**
* Returns a new {@link DefaultWriteFuture} which is already marked as 'written'.
+ *
+ * @param session The associated session
+ * @return A new future for a written message
*/
public static WriteFuture newWrittenFuture(IoSession session) {
- DefaultWriteFuture unwrittenFuture = new DefaultWriteFuture(session);
- unwrittenFuture.setWritten();
- return unwrittenFuture;
+ DefaultWriteFuture writtenFuture = new DefaultWriteFuture(session);
+ writtenFuture.setWritten();
+
+ return writtenFuture;
}
/**
* Returns a new {@link DefaultWriteFuture} which is already marked as 'not written'.
+ *
+ * @param session The associated session
+ * @param cause The reason why the message has not be written
+ * @return A new future for not written message
*/
public static WriteFuture newNotWrittenFuture(IoSession session, Throwable cause) {
DefaultWriteFuture unwrittenFuture = new DefaultWriteFuture(session);
unwrittenFuture.setException(cause);
+
return unwrittenFuture;
}
/**
* Creates a new instance.
+ *
+ * @param session The associated session
*/
public DefaultWriteFuture(IoSession session) {
super(session);
@@ -58,10 +69,12 @@ public class DefaultWriteFuture extends DefaultIoFuture implements WriteFuture {
public boolean isWritten() {
if (isDone()) {
Object v = getValue();
+
if (v instanceof Boolean) {
return ((Boolean) v).booleanValue();
}
}
+
return false;
}
@@ -71,10 +84,12 @@ public class DefaultWriteFuture extends DefaultIoFuture implements WriteFuture {
public Throwable getException() {
if (isDone()) {
Object v = getValue();
+
if (v instanceof Throwable) {
return (Throwable) v;
}
}
+
return null;
}
http://git-wip-us.apache.org/repos/asf/mina/blob/bdad876b/mina-core/src/main/java/org/apache/mina/core/service/AbstractIoService.java
----------------------------------------------------------------------
diff --git a/mina-core/src/main/java/org/apache/mina/core/service/AbstractIoService.java b/mina-core/src/main/java/org/apache/mina/core/service/AbstractIoService.java
index 6a09763..adb5edf 100644
--- a/mina-core/src/main/java/org/apache/mina/core/service/AbstractIoService.java
+++ b/mina-core/src/main/java/org/apache/mina/core/service/AbstractIoService.java
@@ -487,6 +487,11 @@ public abstract class AbstractIoService implements IoService {
// Do nothing. Extended class might add some specific code
}
+ /**
+ * A specific class used to
+ * @author elecharny
+ *
+ */
protected static class ServiceOperationFuture extends DefaultIoFuture {
public ServiceOperationFuture() {
super(null);
@@ -512,6 +517,7 @@ public abstract class AbstractIoService implements IoService {
if (exception == null) {
throw new IllegalArgumentException("exception");
}
+
setValue(exception);
}
}