Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

HTTPCORE-155: Compatibility mode with IBM JRE and other JREs with nai…

…ve (broken) implementation of SelectionKey.

* Eliminated tight coupling between IOSessionImpl and AbstractIOReactor
* Minor code cleanups

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/branches/ibm_compat_branch@758012 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
commit 8e660859c558b2bce98180db6dbdd7aedffe57b0 1 parent aaa188a
@ok2c ok2c authored
View
19 httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java
@@ -373,13 +373,26 @@ private void processNewChannels() throws IOReactorException {
"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 @@ public void shutdown() throws IOReactorException {
* @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");
View
47 httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java
@@ -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 SocketAddress getRemoteAddress() {
}
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 @@ public void setEventMask(int ops) {
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 @@ public void setEvent(int op) {
if (this.status == CLOSED) {
return;
}
- if (this.interestOpsQueueing) {
+ if (this.interestOpsCallback != null) {
// update the current event mask
this.currentEventMask |= op;
@@ -146,7 +147,7 @@ public void setEvent(int op) {
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 @@ public void clearEvent(int op) {
if (this.status == CLOSED) {
return;
}
- if (this.interestOpsQueueing) {
+ if (this.interestOpsCallback != null) {
// update the current event mask
this.currentEventMask &= ~op;
@@ -168,7 +169,7 @@ public void clearEvent(int op) {
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 @@ public void close() {
// 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 @@ public String toString() {
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());
View
4 httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/InterestOpEntry.java
@@ -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;
View
44 httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/InterestOpsCallback.java
@@ -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);
+
+}

0 comments on commit 8e66085

Please sign in to comment.
Something went wrong with that request. Please try again.