You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2008/01/18 00:53:35 UTC
svn commit: r613012 - in
/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor:
AbstractMultiworkerIOReactor.java DefaultConnectingIOReactor.java
DefaultListeningIOReactor.java ListenerEndpointImpl.java
Author: olegk
Date: Thu Jan 17 15:53:21 2008
New Revision: 613012
URL: http://svn.apache.org/viewvc?rev=613012&view=rev
Log:
* Added synchronization on the set of selector keys in AbstractMultiworkerIOReactor and its subclasses
* Declared all instance variables volatile in ListenerEndpointImpl
Modified:
httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java
httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java
httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/ListenerEndpointImpl.java
Modified: httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java?rev=613012&r1=613011&r2=613012&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java (original)
+++ httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java Thu Jan 17 15:53:21 2008
@@ -200,14 +200,16 @@
// Close out all channels
if (this.selector.isOpen()) {
Set<SelectionKey> keys = this.selector.keys();
- for (Iterator<SelectionKey> it = keys.iterator(); it.hasNext(); ) {
- try {
- SelectionKey key = it.next();
- Channel channel = key.channel();
- if (channel != null) {
- channel.close();
+ synchronized (keys) {
+ for (Iterator<SelectionKey> it = keys.iterator(); it.hasNext(); ) {
+ try {
+ SelectionKey key = it.next();
+ Channel channel = key.channel();
+ if (channel != null) {
+ channel.close();
+ }
+ } catch (IOException ignore) {
}
- } catch (IOException ignore) {
}
}
// Stop dispatching I/O events
Modified: httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java?rev=613012&r1=613011&r2=613012&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java (original)
+++ httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java Thu Jan 17 15:53:21 2008
@@ -101,7 +101,7 @@
if ((currentTime - this.lastTimeoutCheck) >= this.selectTimeout) {
this.lastTimeoutCheck = currentTime;
Set<SelectionKey> keys = this.selector.keys();
- if (keys != null) {
+ synchronized (keys) {
processTimeouts(keys);
}
}
Modified: httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java?rev=613012&r1=613011&r2=613012&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java (original)
+++ httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java Thu Jan 17 15:53:21 2008
@@ -180,12 +180,14 @@
List<ListenerEndpoint> list = new ArrayList<ListenerEndpoint>();
if (this.selector.isOpen()) {
Set<SelectionKey> keys = this.selector.keys();
- for (Iterator<SelectionKey> it = keys.iterator(); it.hasNext(); ) {
- SelectionKey key = it.next();
- if (key.isValid()) {
- ListenerEndpoint endpoint = (ListenerEndpoint) key.attachment();
- if (endpoint != null) {
- list.add(endpoint);
+ synchronized (keys) {
+ for (Iterator<SelectionKey> it = keys.iterator(); it.hasNext(); ) {
+ SelectionKey key = it.next();
+ if (key.isValid()) {
+ ListenerEndpoint endpoint = (ListenerEndpoint) key.attachment();
+ if (endpoint != null) {
+ list.add(endpoint);
+ }
}
}
}
@@ -196,13 +198,15 @@
public void pause() throws IOException {
if (this.selector.isOpen()) {
Set<SelectionKey> keys = this.selector.keys();
- for (Iterator<SelectionKey> it = keys.iterator(); it.hasNext(); ) {
- SelectionKey key = it.next();
- if (key.isValid()) {
- ListenerEndpointImpl endpoint = (ListenerEndpointImpl) key.attachment();
- if (endpoint != null) {
- endpoint.close();
- this.pausedEndpoints.add(endpoint.getAddress());
+ synchronized (keys) {
+ for (Iterator<SelectionKey> it = keys.iterator(); it.hasNext(); ) {
+ SelectionKey key = it.next();
+ if (key.isValid()) {
+ ListenerEndpointImpl endpoint = (ListenerEndpointImpl) key.attachment();
+ if (endpoint != null) {
+ endpoint.close();
+ this.pausedEndpoints.add(endpoint.getAddress());
+ }
}
}
}
Modified: httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/ListenerEndpointImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/ListenerEndpointImpl.java?rev=613012&r1=613011&r2=613012&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/ListenerEndpointImpl.java (original)
+++ httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/ListenerEndpointImpl.java Thu Jan 17 15:53:21 2008
@@ -43,8 +43,8 @@
private volatile boolean completed;
private volatile boolean closed;
private volatile SelectionKey key;
- private SocketAddress address;
- private ServerSocketChannel serverChannel = null;
+ private volatile SocketAddress address;
+ private volatile ServerSocketChannel serverChannel = null;
private IOException exception = null;