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 2009/03/24 21:47:02 UTC
svn commit: r758012 - in
/httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor:
AbstractIOReactor.java IOSessionImpl.java InterestOpEntry.java
InterestOpsCallback.java
Author: olegk
Date: Tue Mar 24 20:46:59 2009
New Revision: 758012
URL: http://svn.apache.org/viewvc?rev=758012&view=rev
Log:
HTTPCORE-155: Compatibility mode with IBM JRE and other JREs with naive (broken) implementation of SelectionKey.
* Eliminated tight coupling between IOSessionImpl and AbstractIOReactor
* Minor code cleanups
Added:
httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/InterestOpsCallback.java (with props)
Modified:
httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java
httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java
httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/InterestOpEntry.java
Modified: httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java?rev=758012&r1=758011&r2=758012&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java (original)
+++ httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java Tue Mar 24 20:46:59 2009
@@ -373,13 +373,26 @@
"with the selector", ex);
}
- IOSession session = new IOSessionImpl(key, new SessionClosedCallback() {
+ SessionClosedCallback sessionClosedCallback = new SessionClosedCallback() {
public void sessionClosed(IOSession session) {
queueClosedSession(session);
}
- }, this);
+ };
+
+ InterestOpsCallback interestOpsCallback = null;
+ if (this.interestOpsQueueing) {
+ interestOpsCallback = new InterestOpsCallback() {
+
+ public void addInterestOps(InterestOpEntry entry) {
+ queueInterestOps(entry);
+ }
+
+ };
+ }
+
+ IOSession session = new IOSessionImpl(key, interestOpsCallback, sessionClosedCallback);
int timeout = 0;
try {
@@ -572,7 +585,7 @@
* @return <code>true</code> if the operation could be performed successfully,
* <code>false</code> otherwise.
*/
- protected boolean addInterestOpsQueueElement(final InterestOpEntry entry) {
+ protected boolean queueInterestOps(final InterestOpEntry entry) {
// validity checks
if (!this.interestOpsQueueing) {
throw new IllegalStateException("Interest ops queueing not enabled");
Modified: httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java?rev=758012&r1=758011&r2=758012&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java (original)
+++ httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java Tue Mar 24 20:46:59 2009
@@ -58,37 +58,38 @@
private final SelectionKey key;
private final ByteChannel channel;
- private final SessionClosedCallback callback;
private final Map<String, Object> attributes;
- private final AbstractIOReactor abstractIOReactor;
- private final boolean interestOpsQueueing;
+ private final InterestOpsCallback interestOpsCallback;
+ private final SessionClosedCallback sessionClosedCallback;
private SessionBufferStatus bufferStatus;
private int socketTimeout;
private volatile int currentEventMask;
- public IOSessionImpl(final SelectionKey key, final SessionClosedCallback callback, final AbstractIOReactor abstractIOReactor) {
+ public IOSessionImpl(
+ final SelectionKey key,
+ final InterestOpsCallback interestOpsCallback,
+ final SessionClosedCallback sessionClosedCallback) {
super();
if (key == null) {
throw new IllegalArgumentException("Selection key may not be null");
}
-
- // validity check
- if (abstractIOReactor == null) {
- throw new IllegalArgumentException("IO reactor may not be null");
- }
-
this.key = key;
this.channel = (ByteChannel) this.key.channel();
- this.callback = callback;
+ this.interestOpsCallback = interestOpsCallback;
+ this.sessionClosedCallback = sessionClosedCallback;
this.attributes = Collections.synchronizedMap(new HashMap<String, Object>());
- this.abstractIOReactor = abstractIOReactor;
- this.interestOpsQueueing = abstractIOReactor.getInterestOpsQueueing();
this.currentEventMask = 0;
this.socketTimeout = 0;
this.status = ACTIVE;
}
+ public IOSessionImpl(
+ final SelectionKey key,
+ final SessionClosedCallback sessionClosedCallback) {
+ this(key, null, sessionClosedCallback);
+ }
+
public ByteChannel channel() {
return this.channel;
}
@@ -112,14 +113,14 @@
}
public int getEventMask() {
- return this.interestOpsQueueing ? this.currentEventMask : this.key.interestOps();
+ return this.interestOpsCallback != null ? this.currentEventMask : this.key.interestOps();
}
public void setEventMask(int ops) {
if (this.status == CLOSED) {
return;
}
- if (this.interestOpsQueueing) {
+ if (this.interestOpsCallback != null) {
// update the current event mask
this.currentEventMask = ops;
@@ -127,7 +128,7 @@
InterestOpEntry entry = new InterestOpEntry(this.key, this.currentEventMask);
// add this operation to the interestOps() queue
- this.abstractIOReactor.addInterestOpsQueueElement(entry);
+ this.interestOpsCallback.addInterestOps(entry);
} else {
this.key.interestOps(ops);
}
@@ -138,7 +139,7 @@
if (this.status == CLOSED) {
return;
}
- if (this.interestOpsQueueing) {
+ if (this.interestOpsCallback != null) {
// update the current event mask
this.currentEventMask |= op;
@@ -146,7 +147,7 @@
InterestOpEntry entry = new InterestOpEntry(this.key, this.currentEventMask);
// add this operation to the interestOps() queue
- this.abstractIOReactor.addInterestOpsQueueElement(entry);
+ this.interestOpsCallback.addInterestOps(entry);
} else {
synchronized (this.key) {
int ops = this.key.interestOps();
@@ -160,7 +161,7 @@
if (this.status == CLOSED) {
return;
}
- if (this.interestOpsQueueing) {
+ if (this.interestOpsCallback != null) {
// update the current event mask
this.currentEventMask &= ~op;
@@ -168,7 +169,7 @@
InterestOpEntry entry = new InterestOpEntry(this.key, this.currentEventMask);
// add this operation to the interestOps() queue
- this.abstractIOReactor.addInterestOpsQueueElement(entry);
+ this.interestOpsCallback.addInterestOps(entry);
} else {
synchronized (this.key) {
int ops = this.key.interestOps();
@@ -198,8 +199,8 @@
// Munching exceptions is not nice
// but in this case it is justified
}
- if (this.callback != null) {
- this.callback.sessionClosed(this);
+ if (this.sessionClosedCallback != null) {
+ this.sessionClosedCallback.sessionClosed(this);
}
if (this.key.selector().isOpen()) {
this.key.selector().wakeup();
@@ -267,7 +268,7 @@
buffer.append("[");
if (this.key.isValid()) {
buffer.append("interested ops: ");
- formatOps(buffer, this.interestOpsQueueing ?
+ formatOps(buffer, this.interestOpsCallback != null ?
this.currentEventMask : this.key.interestOps());
buffer.append("; ready ops: ");
formatOps(buffer, this.key.readyOps());
Modified: httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/InterestOpEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/InterestOpEntry.java?rev=758012&r1=758011&r2=758012&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/InterestOpEntry.java (original)
+++ httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/InterestOpEntry.java Tue Mar 24 20:46:59 2009
@@ -34,10 +34,10 @@
import java.nio.channels.SelectionKey;
/**
- * Helper class, representing an element on an {@link java.nio.channels.SelectionKey#interestOps(int)
+ * Helper class, representing an entry on an {@link java.nio.channels.SelectionKey#interestOps(int)
* interestOps(int)} queue.
*/
-class InterestOpEntry {
+public class InterestOpEntry {
private final SelectionKey key;
private final int eventMask;
Added: httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/InterestOpsCallback.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/InterestOpsCallback.java?rev=758012&view=auto
==============================================================================
--- httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/InterestOpsCallback.java (added)
+++ httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/InterestOpsCallback.java Tue Mar 24 20:46:59 2009
@@ -0,0 +1,44 @@
+/*
+ * $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;
+
+/**
+ * Callback interface used internally by I/O session implementations to delegate execution
+ * of a {@link java.nio.channels.SelectionKey#interestOps(int)} operation to the I/O reactor.
+ *
+ * @since 4.1
+ */
+public interface InterestOpsCallback {
+
+ void addInterestOps(InterestOpEntry entry);
+
+}
Propchange: httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/InterestOpsCallback.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/InterestOpsCallback.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/InterestOpsCallback.java
------------------------------------------------------------------------------
svn:mime-type = text/plain