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 2007/10/03 17:50:38 UTC
svn commit: r581638 - in
/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor:
AbstractIOReactor.java AbstractMultiworkerIOReactor.java
Author: olegk
Date: Wed Oct 3 08:50:37 2007
New Revision: 581638
URL: http://svn.apache.org/viewvc?rev=581638&view=rev
Log:
Improved graceful shutdown of I/O reactors
Modified:
jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java
jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java?rev=581638&r1=581637&r2=581638&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java Wed Oct 3 08:50:37 2007
@@ -121,26 +121,43 @@
}
if (this.status == SHUT_DOWN) {
+ // Hard shut down. Exit select loop immediately
break;
}
+ if (this.status == SHUTTING_DOWN) {
+ // Graceful shutdown in process
+ // Try to close things out nicely
+ closeSessions();
+ closeNewChannels();
+ }
+
+ // Process selected I/O events
if (readyCount > 0) {
processEvents(this.selector.selectedKeys());
}
+ // Validate active channels
validate(this.selector.keys());
+ // Process closed sessions
processClosedSessions();
+ // If active process new channels
if (this.status == ACTIVE) {
processNewChannels();
}
- if (this.status != ACTIVE && this.sessions.isEmpty()) {
+ // Exit select loop if graceful shutdown has been completed
+ if (this.status > ACTIVE && this.sessions.isEmpty()) {
break;
}
}
+
+ // Close remaining active channels and the selector itself
+ closeActiveChannels();
+
} catch (ClosedSelectorException ex) {
} finally {
synchronized (this.shutdownMutex) {
@@ -251,8 +268,7 @@
}
}
- protected void closeChannels() throws IOReactorException {
- // Close out all new channels
+ protected void closeNewChannels() throws IOReactorException {
ChannelEntry entry;
while ((entry = this.newChannels.pop()) != null) {
SessionRequestImpl sessionRequest = entry.getSessionRequest();
@@ -265,7 +281,9 @@
} catch (IOException ignore) {
}
}
- // Close out all active channels
+ }
+
+ protected void closeActiveChannels() throws IOReactorException {
Set keys = this.selector.keys();
for (Iterator it = keys.iterator(); it.hasNext(); ) {
try {
@@ -277,11 +295,9 @@
} catch (IOException ignore) {
}
}
- // Stop dispatching I/O events
try {
this.selector.close();
- } catch (IOException ex) {
- throw new IOReactorException("Failure closing selector", ex);
+ } catch (IOException ignore) {
}
}
@@ -291,7 +307,6 @@
return;
}
this.status = SHUTTING_DOWN;
- closeSessions();
this.selector.wakeup();
}
@@ -301,7 +316,8 @@
return;
}
this.status = SHUT_DOWN;
- closeChannels();
+ closeNewChannels();
+ closeActiveChannels();
}
public void awaitShutdown(long timeout) throws InterruptedException {
Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java?rev=581638&r1=581637&r2=581638&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java Wed Oct 3 08:50:37 2007
@@ -285,16 +285,6 @@
this.exception = ex;
} catch (RuntimeException ex) {
this.exception = ex;
- } finally {
- try {
- if (this.dispatcher.getStatus() != SHUT_DOWN) {
- this.dispatcher.closeChannels();
- }
- } catch (IOReactorException ex2) {
- if (this.exception == null) {
- this.exception = ex2;
- }
- }
}
}