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/08/05 14:06:29 UTC
svn commit: r562854 - in /jakarta/httpcomponents/httpcore/trunk: ./
module-nio/src/main/java/org/apache/http/impl/nio/reactor/
module-nio/src/test/java/org/apache/http/impl/nio/reactor/
Author: olegk
Date: Sun Aug 5 05:06:28 2007
New Revision: 562854
URL: http://svn.apache.org/viewvc?view=rev&rev=562854
Log:
HTTPCORE-108: Close all channels registered with the I/O reactor during shutdown. Fixes the problem with DefaultListeningIOReactor not releasing socket ports until JVM is restarted
Added:
jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultListeningIOReactor.java (with props)
Modified:
jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
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/DefaultConnectingIOReactor.java
jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java
jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/reactor/TestAllImplReactor.java
Modified: jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt?view=diff&rev=562854&r1=562853&r2=562854
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original)
+++ jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Sun Aug 5 05:06:28 2007
@@ -1,5 +1,10 @@
Changes since release 4.0 Alpha 5
+* [HTTPCORE-108] Close all channels registered with the I/O reactor during
+ shutdown. Fixed the problem with DefaultListeningIOReactor not releasing
+ socket ports until JVM is restarted.
+ Oleg Kalnichevski <olegk at apache.org>
+
* [HTTPCORE-106] Pluggable HTTP message parsers and message writers
Oleg Kalnichevski <olegk at apache.org>
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?view=diff&rev=562854&r1=562853&r2=562854
==============================================================================
--- 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 Sun Aug 5 05:06:28 2007
@@ -34,6 +34,7 @@
import java.io.IOException;
import java.io.InterruptedIOException;
import java.nio.channels.CancelledKeyException;
+import java.nio.channels.Channel;
import java.nio.channels.ClosedSelectorException;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
@@ -248,6 +249,18 @@
return;
}
this.closed = true;
+ // Close out all channels
+ Set keys = this.selector.keys();
+ for (Iterator it = keys.iterator(); it.hasNext(); ) {
+ try {
+ SelectionKey key = (SelectionKey) it.next();
+ Channel channel = key.channel();
+ if (channel != null) {
+ channel.close();
+ }
+ } catch (IOException ignore) {
+ }
+ }
// Stop dispatching I/O events
try {
this.selector.close();
Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java?view=diff&rev=562854&r1=562853&r2=562854
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java Sun Aug 5 05:06:28 2007
@@ -38,6 +38,7 @@
import java.net.SocketAddress;
import java.net.UnknownHostException;
import java.nio.channels.CancelledKeyException;
+import java.nio.channels.Channel;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;
@@ -202,6 +203,9 @@
final Object attachment,
final SessionRequestCallback callback) {
+ if (this.closed) {
+ throw new IllegalStateException("I/O reactor has been shut down");
+ }
SessionRequestImpl sessionRequest = new SessionRequestImpl(
remoteAddress, localAddress, attachment, callback);
sessionRequest.setConnectTimeout(HttpConnectionParams.getConnectionTimeout(this.params));
@@ -280,6 +284,18 @@
return;
}
this.closed = true;
+ // Close out all channels
+ Set keys = this.selector.keys();
+ for (Iterator it = keys.iterator(); it.hasNext(); ) {
+ try {
+ SelectionKey key = (SelectionKey) it.next();
+ Channel channel = key.channel();
+ if (channel != null) {
+ channel.close();
+ }
+ } catch (IOException ignore) {
+ }
+ }
// Stop dispatching I/O events
this.selector.close();
// Stop the workers
Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java?view=diff&rev=562854&r1=562853&r2=562854
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java Sun Aug 5 05:06:28 2007
@@ -36,6 +36,7 @@
import java.net.Socket;
import java.net.SocketAddress;
import java.nio.channels.CancelledKeyException;
+import java.nio.channels.Channel;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
@@ -168,6 +169,9 @@
public SocketAddress listen(
final SocketAddress address) throws IOException {
+ if (this.closed) {
+ throw new IllegalStateException("I/O reactor has been shut down");
+ }
ServerSocketChannel serverChannel = ServerSocketChannel.open();
serverChannel.configureBlocking(false);
serverChannel.socket().bind(address);
@@ -181,8 +185,22 @@
return;
}
this.closed = true;
+
+ // Close out all channels
+ Set keys = this.selector.keys();
+ for (Iterator it = keys.iterator(); it.hasNext(); ) {
+ try {
+ SelectionKey key = (SelectionKey) it.next();
+ Channel channel = key.channel();
+ if (channel != null) {
+ channel.close();
+ }
+ } catch (IOException ignore) {
+ }
+ }
// Stop dispatching I/O events
this.selector.close();
+
// Stop the workers
stopWorkers(500);
}
Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/reactor/TestAllImplReactor.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/reactor/TestAllImplReactor.java?view=diff&rev=562854&r1=562853&r2=562854
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/reactor/TestAllImplReactor.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/reactor/TestAllImplReactor.java Sun Aug 5 05:06:28 2007
@@ -41,6 +41,7 @@
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(TestSessionInOutBuffers.suite());
+ suite.addTest(TestDefaultListeningIOReactor.suite());
return suite;
}
Added: jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultListeningIOReactor.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultListeningIOReactor.java?view=auto&rev=562854
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultListeningIOReactor.java (added)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultListeningIOReactor.java Sun Aug 5 05:06:28 2007
@@ -0,0 +1,80 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.nio.reactor;
+
+import java.net.InetSocketAddress;
+
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpParams;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Simple tests for {@link DefaultListeningIOReactor}.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Id$
+ */
+public class TestDefaultListeningIOReactor extends TestCase {
+
+ // ------------------------------------------------------------ Constructor
+ public TestDefaultListeningIOReactor(String testName) {
+ super(testName);
+ }
+
+ // ------------------------------------------------------------------- Main
+ public static void main(String args[]) {
+ String[] testCaseName = { TestDefaultListeningIOReactor.class.getName() };
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+ // ------------------------------------------------------- TestCase Methods
+
+ public static Test suite() {
+ return new TestSuite(TestDefaultListeningIOReactor.class);
+ }
+
+ public void testRestart() throws Exception {
+ HttpParams params = new BasicHttpParams();
+
+ DefaultListeningIOReactor ioReactor = new DefaultListeningIOReactor(1, params);
+ ioReactor.listen(new InetSocketAddress(9999));
+ ioReactor.shutdown();
+
+ ioReactor = new DefaultListeningIOReactor(1, params);
+ ioReactor.listen(new InetSocketAddress(9999));
+ ioReactor.shutdown();
+ }
+
+}
Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultListeningIOReactor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultListeningIOReactor.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultListeningIOReactor.java
------------------------------------------------------------------------------
svn:mime-type = text/plain