You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2016/02/03 11:23:33 UTC
svn commit: r1728292 - in /tomcat/trunk/java/org/apache/tomcat/util/net:
AprEndpoint.java Nio2Endpoint.java NioEndpoint.java SocketWrapperBase.java
Author: remm
Date: Wed Feb 3 10:23:33 2016
New Revision: 1728292
URL: http://svn.apache.org/viewvc?rev=1728292&view=rev
Log:
- Pull default "unsupported" async methods implementation up, since it looks unlikely it ever makes sense to use them with APR or NIO.
- Add some new helpers. It is possible that I'll add some sync oriented helpers, but unsure yet.
Modified:
tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java
tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java?rev=1728292&r1=1728291&r2=1728292&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Wed Feb 3 10:23:33 2016
@@ -20,7 +20,6 @@ import java.io.EOFException;
import java.io.IOException;
import java.net.SocketTimeoutException;
import java.nio.ByteBuffer;
-import java.nio.channels.CompletionHandler;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
@@ -30,7 +29,6 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.RejectedExecutionException;
-import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
@@ -2635,12 +2633,6 @@ public class AprEndpoint extends Abstrac
@Override
- public boolean isReadPending() {
- return false;
- }
-
-
- @Override
public void registerReadInterest() {
// Make sure an already closed socket is not added to the poller
synchronized (closedLock) {
@@ -2793,30 +2785,5 @@ public class AprEndpoint extends Abstrac
SSLSocket.setVerify(socket, SSL.SSL_CVERIFY_REQUIRE, -1);
SSLSocket.renegotiate(socket);
}
-
-
- @Override
- public boolean isWritePending() {
- return false;
- }
-
-
- @Override
- public <A> CompletionState read(ByteBuffer[] dsts, int offset,
- int length, boolean block, long timeout, TimeUnit unit,
- A attachment, CompletionCheck check,
- CompletionHandler<Long, ? super A> handler) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException();
- }
-
- @Override
- public <A> CompletionState write(ByteBuffer[] srcs, int offset,
- int length, boolean block, long timeout, TimeUnit unit,
- A attachment, CompletionCheck check,
- CompletionHandler<Long, ? super A> handler) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException();
- }
}
}
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java?rev=1728292&r1=1728291&r2=1728292&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java Wed Feb 3 10:23:33 2016
@@ -1107,6 +1107,9 @@ public class Nio2Endpoint extends Abstra
} else {
throw new ReadPendingException();
}
+ if (block && state.state == CompletionState.PENDING && readPending.tryAcquire(timeout, unit)) {
+ readPending.release();
+ }
} catch (InterruptedException e) {
handler.failed(e, attachment);
}
@@ -1337,6 +1340,32 @@ public class Nio2Endpoint extends Abstra
}
}
+
+ @Override
+ public boolean awaitReadComplete(long timeout, TimeUnit unit) {
+ try {
+ if (readPending.tryAcquire(timeout, unit)) {
+ readPending.release();
+ }
+ } catch (InterruptedException e) {
+ return false;
+ }
+ return true;
+ }
+
+
+ @Override
+ public boolean awaitWriteComplete(long timeout, TimeUnit unit) {
+ try {
+ if (writePending.tryAcquire(timeout, unit)) {
+ writePending.release();
+ }
+ } catch (InterruptedException e) {
+ return false;
+ }
+ return true;
+ }
+
/*
* This should only be called from a thread that currently holds a lock
* on the socket. This prevents a race condition between a pending read
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=1728292&r1=1728291&r2=1728292&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Wed Feb 3 10:23:33 2016
@@ -27,7 +27,6 @@ import java.net.Socket;
import java.net.SocketTimeoutException;
import java.nio.ByteBuffer;
import java.nio.channels.CancelledKeyException;
-import java.nio.channels.CompletionHandler;
import java.nio.channels.FileChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
@@ -1315,12 +1314,6 @@ public class NioEndpoint extends Abstrac
@Override
- public boolean isReadPending() {
- return false;
- }
-
-
- @Override
public void registerReadInterest() {
getPoller().add(getSocket(), SelectionKey.OP_READ);
}
@@ -1430,29 +1423,6 @@ public class NioEndpoint extends Abstrac
}
}
}
-
- @Override
- public boolean isWritePending() {
- return false;
- }
-
- @Override
- public <A> CompletionState read(ByteBuffer[] dsts, int offset,
- int length, boolean block, long timeout, TimeUnit unit,
- A attachment, CompletionCheck check,
- CompletionHandler<Long, ? super A> handler) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException();
- }
-
- @Override
- public <A> CompletionState write(ByteBuffer[] srcs, int offset,
- int length, boolean block, long timeout, TimeUnit unit,
- A attachment, CompletionCheck check,
- CompletionHandler<Long, ? super A> handler) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException();
- }
}
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java?rev=1728292&r1=1728291&r2=1728292&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java Wed Feb 3 10:23:33 2016
@@ -208,8 +208,6 @@ public abstract class SocketWrapperBase<
return blockingStatusWriteLock;
}
public SocketBufferHandler getSocketBufferHandler() { return socketBufferHandler; }
- public abstract boolean isReadPending();
- public abstract boolean isWritePending();
public boolean hasDataToWrite() {
return !socketBufferHandler.isWriteBufferEmpty() || bufferedWrites.size() > 0;
@@ -660,6 +658,52 @@ public abstract class SocketWrapperBase<
}
/**
+ * Allows checking if an asynchronous read operation is currently pending.
+ * @return <code>true</code> if the endpoint supports asynchronous IO and
+ * a read operation is being processed asynchronously
+ */
+ public boolean isReadPending() {
+ return false;
+ }
+
+ /**
+ * Allows checking if an asynchronous write operation is currently pending.
+ * @return <code>true</code> if the endpoint supports asynchronous IO and
+ * a write operation is being processed asynchronously
+ */
+ public boolean isWritePending() {
+ return false;
+ }
+
+ /**
+ * If an asynchronous read operation is pending, this method will block
+ * until the operation completes, or the specified amount of time
+ * has passed.
+ * @param timeout The maximum amount of time to wait
+ * @param unit The unit for the timeout
+ * @return <code>true</code> if the read operation is complete,
+ * <code>false</code> if the operation is still pending and
+ * the specified timeout has passed
+ */
+ public boolean awaitReadComplete(long timeout, TimeUnit unit) {
+ return true;
+ }
+
+ /**
+ * If an asynchronous write operation is pending, this method will block
+ * until the operation completes, or the specified amount of time
+ * has passed.
+ * @param timeout The maximum amount of time to wait
+ * @param unit The unit for the timeout
+ * @return <code>true</code> if the read operation is complete,
+ * <code>false</code> if the operation is still pending and
+ * the specified timeout has passed
+ */
+ public boolean awaitWriteComplete(long timeout, TimeUnit unit) {
+ return true;
+ }
+
+ /**
* Scatter read. The completion handler will be called once some
* data has been read or an error occurred. If a CompletionCheck
* object has been provided, the completion handler will only be
@@ -683,7 +727,7 @@ public abstract class SocketWrapperBase<
* @param <A> The attachment type
* @return the completion state (done, done inline, or still pending)
*/
- public <A> CompletionState read(boolean block, long timeout, TimeUnit unit, A attachment,
+ public final <A> CompletionState read(boolean block, long timeout, TimeUnit unit, A attachment,
CompletionCheck check, CompletionHandler<Long, ? super A> handler,
ByteBuffer... dsts) {
if (dsts == null) {
@@ -718,9 +762,11 @@ public abstract class SocketWrapperBase<
* @param <A> The attachment type
* @return the completion state (done, done inline, or still pending)
*/
- public abstract <A> CompletionState read(ByteBuffer[] dsts, int offset, int length,
+ public <A> CompletionState read(ByteBuffer[] dsts, int offset, int length,
boolean block, long timeout, TimeUnit unit, A attachment,
- CompletionCheck check, CompletionHandler<Long, ? super A> handler);
+ CompletionCheck check, CompletionHandler<Long, ? super A> handler) {
+ throw new UnsupportedOperationException();
+ }
/**
* Gather write. The completion handler will be called once some
@@ -747,7 +793,7 @@ public abstract class SocketWrapperBase<
* @param <A> The attachment type
* @return the completion state (done, done inline, or still pending)
*/
- public <A> CompletionState write(boolean block, long timeout, TimeUnit unit, A attachment,
+ public final <A> CompletionState write(boolean block, long timeout, TimeUnit unit, A attachment,
CompletionCheck check, CompletionHandler<Long, ? super A> handler,
ByteBuffer... srcs) {
if (srcs == null) {
@@ -783,9 +829,11 @@ public abstract class SocketWrapperBase<
* @param <A> The attachment type
* @return the completion state (done, done inline, or still pending)
*/
- public abstract <A> CompletionState write(ByteBuffer[] srcs, int offset, int length,
+ public <A> CompletionState write(ByteBuffer[] srcs, int offset, int length,
boolean block, long timeout, TimeUnit unit, A attachment,
- CompletionCheck check, CompletionHandler<Long, ? super A> handler);
+ CompletionCheck check, CompletionHandler<Long, ? super A> handler) {
+ throw new UnsupportedOperationException();
+ }
// --------------------------------------------------------- Utility methods
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org