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/02 12:54:37 UTC
svn commit: r581187 - in
/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor:
AbstractIOReactor.java BaseIOReactor.java
Author: olegk
Date: Tue Oct 2 03:54:36 2007
New Revision: 581187
URL: http://svn.apache.org/viewvc?rev=581187&view=rev
Log:
Improved handling of runtime exceptions in base I/O reactor
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/BaseIOReactor.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=581187&r1=581186&r2=581187&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 Tue Oct 2 03:54:36 2007
@@ -42,7 +42,6 @@
import java.util.Iterator;
import java.util.Set;
-import org.apache.http.nio.reactor.IOEventDispatch;
import org.apache.http.nio.reactor.IOReactor;
import org.apache.http.nio.reactor.IOReactorException;
import org.apache.http.nio.reactor.IOSession;
@@ -58,8 +57,6 @@
private final SessionQueue closedSessions;
private final ChannelQueue newChannels;
- protected IOEventDispatch eventDispatch = null;
-
public AbstractIOReactor(long selectTimeout) throws IOReactorException {
super();
if (selectTimeout <= 0) {
@@ -90,9 +87,11 @@
protected abstract void validate(Set keys);
- protected abstract void keyCreated(final SelectionKey key, final IOSession session);
+ protected abstract void keyCreated(SelectionKey key, IOSession session);
+
+ protected abstract IOSession keyCancelled(SelectionKey key);
- protected abstract IOSession keyCancelled(final SelectionKey key);
+ protected abstract void sessionClosed(IOSession session);
public int getStatus() {
return this.status;
@@ -106,13 +105,7 @@
this.selector.wakeup();
}
- public void execute(final IOEventDispatch eventDispatch)
- throws InterruptedIOException, IOReactorException {
- if (eventDispatch == null) {
- throw new IllegalArgumentException("Event dispatcher may not be null");
- }
- this.eventDispatch = eventDispatch;
-
+ protected void execute() throws InterruptedIOException, IOReactorException {
this.status = ACTIVE;
try {
@@ -225,10 +218,9 @@
session.setAttribute(IOSession.ATTACHMENT_KEY, entry.getAttachment());
session.setSocketTimeout(timeout);
this.sessions.add(session);
- keyCreated(key, session);
try {
- this.eventDispatch.connected(session);
+ keyCreated(key, session);
SessionRequestImpl sessionRequest = entry.getSessionRequest();
if (sessionRequest != null) {
@@ -245,7 +237,7 @@
IOSession session;
while ((session = this.closedSessions.pop()) != null) {
if (this.sessions.remove(session)) {
- this.eventDispatch.disconnected(session);
+ sessionClosed(session);
}
}
}
Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/BaseIOReactor.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/BaseIOReactor.java?rev=581187&r1=581186&r2=581187&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/BaseIOReactor.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/BaseIOReactor.java Tue Oct 2 03:54:36 2007
@@ -31,12 +31,14 @@
package org.apache.http.impl.nio.reactor;
+import java.io.InterruptedIOException;
import java.nio.channels.CancelledKeyException;
import java.nio.channels.SelectionKey;
import java.util.Iterator;
import java.util.Set;
import org.apache.http.nio.reactor.EventMask;
+import org.apache.http.nio.reactor.IOEventDispatch;
import org.apache.http.nio.reactor.IOReactorException;
import org.apache.http.nio.reactor.IOReactorExceptionHandler;
import org.apache.http.nio.reactor.IOSession;
@@ -48,7 +50,8 @@
private long lastTimeoutCheck;
- private IOReactorExceptionHandler exceptionHandler;
+ private IOReactorExceptionHandler exceptionHandler = null;
+ private IOEventDispatch eventDispatch = null;
public BaseIOReactor(long selectTimeout) throws IOReactorException {
super(selectTimeout);
@@ -57,17 +60,22 @@
this.lastTimeoutCheck = System.currentTimeMillis();
}
+ public void execute(
+ final IOEventDispatch eventDispatch) throws InterruptedIOException, IOReactorException {
+ if (eventDispatch == null) {
+ throw new IllegalArgumentException("Event dispatcher may not be null");
+ }
+ this.eventDispatch = eventDispatch;
+ execute();
+ }
+
public void setExceptionHandler(IOReactorExceptionHandler exceptionHandler) {
this.exceptionHandler = exceptionHandler;
}
- protected void processEvent(final SelectionKey key) {
- try {
- super.processEvent(key);
- } catch (RuntimeException ex) {
- if (this.exceptionHandler == null || !this.exceptionHandler.handle(ex)) {
- throw ex;
- }
+ protected void handleRuntimeException(final RuntimeException ex) {
+ if (this.exceptionHandler == null || !this.exceptionHandler.handle(ex)) {
+ throw ex;
}
}
@@ -82,7 +90,11 @@
IOSession session = handle.getSession();
handle.resetLastRead();
- this.eventDispatch.inputReady(session);
+ try {
+ this.eventDispatch.inputReady(session);
+ } catch (RuntimeException ex) {
+ handleRuntimeException(ex);
+ }
if (session.hasBufferedInput()) {
this.bufferingSessions.add(session);
}
@@ -93,7 +105,11 @@
IOSession session = handle.getSession();
handle.resetLastWrite();
- this.eventDispatch.outputReady(session);
+ try {
+ this.eventDispatch.outputReady(session);
+ } catch (RuntimeException ex) {
+ handleRuntimeException(ex);
+ }
}
protected void validate(final Set keys) {
@@ -117,7 +133,11 @@
try {
int ops = session.getEventMask();
if ((ops & EventMask.READ) > 0) {
- this.eventDispatch.inputReady(session);
+ try {
+ this.eventDispatch.inputReady(session);
+ } catch (RuntimeException ex) {
+ handleRuntimeException(ex);
+ }
if (!session.hasBufferedInput()) {
it.remove();
}
@@ -137,7 +157,11 @@
int timeout = session.getSocketTimeout();
if (timeout > 0) {
if (handle.getLastReadTime() + timeout < now) {
- this.eventDispatch.timeout(session);
+ try {
+ this.eventDispatch.timeout(session);
+ } catch (RuntimeException ex) {
+ handleRuntimeException(ex);
+ }
}
}
}
@@ -146,6 +170,11 @@
protected void keyCreated(final SelectionKey key, final IOSession session) {
SessionHandle handle = new SessionHandle(session);
key.attach(handle);
+ try {
+ this.eventDispatch.connected(session);
+ } catch (RuntimeException ex) {
+ handleRuntimeException(ex);
+ }
}
protected IOSession keyCancelled(final SelectionKey key) {
@@ -155,6 +184,14 @@
return handle.getSession();
} else {
return null;
+ }
+ }
+
+ protected void sessionClosed(final IOSession session) {
+ try {
+ this.eventDispatch.disconnected(session);
+ } catch (RuntimeException ex) {
+ handleRuntimeException(ex);
}
}