hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r599819 - /jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/
Date Fri, 30 Nov 2007 13:45:47 GMT
Author: olegk
Date: Fri Nov 30 05:45:42 2007
New Revision: 599819

URL: http://svn.apache.org/viewvc?rev=599819&view=rev
Log:
Use native Java 1.5 collection primitives

Removed:
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/ChannelQueue.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/ListenerEndpointQueue.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionQueue.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionRequestQueue.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionSet.java
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
    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

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=599819&r1=599818&r2=599819&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
Fri Nov 30 05:45:42 2007
@@ -39,8 +39,12 @@
 import java.nio.channels.SelectionKey;
 import java.nio.channels.Selector;
 import java.nio.channels.SocketChannel;
+import java.util.Collections;
+import java.util.HashSet;
 import java.util.Iterator;
+import java.util.Queue;
 import java.util.Set;
+import java.util.concurrent.ConcurrentLinkedQueue;
 
 import org.apache.http.nio.reactor.IOReactor;
 import org.apache.http.nio.reactor.IOReactorException;
@@ -53,9 +57,9 @@
     private final Object shutdownMutex;
     private final long selectTimeout;
     private final Selector selector;
-    private final SessionSet sessions;
-    private final SessionQueue closedSessions;
-    private final ChannelQueue newChannels;
+    private final Set<IOSession> sessions;
+    private final Queue<IOSession> closedSessions;
+    private final Queue<ChannelEntry> newChannels;
     
     public AbstractIOReactor(long selectTimeout) throws IOReactorException {
         super();
@@ -63,9 +67,9 @@
             throw new IllegalArgumentException("Select timeout may not be negative or zero");
         }
         this.selectTimeout = selectTimeout;
-        this.sessions = new SessionSet();
-        this.closedSessions = new SessionQueue();
-        this.newChannels = new ChannelQueue();
+        this.sessions = Collections.synchronizedSet(new HashSet<IOSession>());
+        this.closedSessions = new ConcurrentLinkedQueue<IOSession>();
+        this.newChannels = new ConcurrentLinkedQueue<ChannelEntry>();
         try {
             this.selector = Selector.open();
         } catch (IOException ex) {
@@ -101,7 +105,7 @@
         if (channelEntry == null) {
             throw new IllegalArgumentException("Channel entry may not be null");
         }
-        this.newChannels.push(channelEntry);
+        this.newChannels.add(channelEntry);
         this.selector.wakeup();
     }
     
@@ -194,7 +198,7 @@
         } catch (CancelledKeyException ex) {
             IOSession session = keyCancelled(key);
             if (session != null) {
-                this.closedSessions.push(session);
+                this.closedSessions.add(session);
             }
             key.attach(null);
         }
@@ -202,7 +206,7 @@
 
     private void processNewChannels() throws IOReactorException {
         ChannelEntry entry;
-        while ((entry = this.newChannels.pop()) != null) {
+        while ((entry = this.newChannels.poll()) != null) {
             
             SocketChannel channel;
             SelectionKey key;
@@ -218,7 +222,7 @@
             IOSession session = new IOSessionImpl(key, new SessionClosedCallback() {
 
                 public void sessionClosed(IOSession session) {
-                    closedSessions.push(session);
+                    closedSessions.add(session);
                 }
                 
             });
@@ -244,7 +248,7 @@
                     sessionRequest.completed(session);
                 }
             } catch (CancelledKeyException ex) {
-                this.closedSessions.push(session);
+                this.closedSessions.add(session);
                 key.attach(null);
             }
         }
@@ -252,7 +256,7 @@
 
     private void processClosedSessions() {
         IOSession session;
-        while ((session = this.closedSessions.pop()) != null) {
+        while ((session = this.closedSessions.poll()) != null) {
             if (this.sessions.remove(session)) {
                 sessionClosed(session);
             }
@@ -270,7 +274,7 @@
     
     protected void closeNewChannels() throws IOReactorException {
         ChannelEntry entry;
-        while ((entry = this.newChannels.pop()) != null) {
+        while ((entry = this.newChannels.poll()) != null) {
             SessionRequestImpl sessionRequest = entry.getSessionRequest();
             if (sessionRequest != null) {
                 sessionRequest.cancel();

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=599819&r1=599818&r2=599819&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
Fri Nov 30 05:45:42 2007
@@ -34,6 +34,7 @@
 import java.io.InterruptedIOException;
 import java.nio.channels.CancelledKeyException;
 import java.nio.channels.SelectionKey;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
 
@@ -46,7 +47,7 @@
 public class BaseIOReactor extends AbstractIOReactor {
 
     private final long timeoutCheckInterval;
-    private SessionSet bufferingSessions;
+    private final Set<IOSession> bufferingSessions;
     
     private long lastTimeoutCheck;
     
@@ -55,7 +56,7 @@
     
     public BaseIOReactor(long selectTimeout) throws IOReactorException {
         super(selectTimeout);
-        this.bufferingSessions = new SessionSet();
+        this.bufferingSessions = new HashSet<IOSession>();
         this.timeoutCheckInterval = selectTimeout;
         this.lastTimeoutCheck = System.currentTimeMillis();
     }

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?rev=599819&r1=599818&r2=599819&view=diff
==============================================================================
--- 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
Fri Nov 30 05:45:42 2007
@@ -39,7 +39,9 @@
 import java.nio.channels.SelectionKey;
 import java.nio.channels.SocketChannel;
 import java.util.Iterator;
+import java.util.Queue;
 import java.util.Set;
+import java.util.concurrent.ConcurrentLinkedQueue;
 
 import org.apache.http.nio.reactor.ConnectingIOReactor;
 import org.apache.http.nio.reactor.IOReactorException;
@@ -52,7 +54,7 @@
 public class DefaultConnectingIOReactor extends AbstractMultiworkerIOReactor 
         implements ConnectingIOReactor {
 
-    private final SessionRequestQueue requestQueue;
+    private final Queue<SessionRequestImpl> requestQueue;
     
     private long lastTimeoutCheck;
     
@@ -61,7 +63,7 @@
             final ThreadFactory threadFactory,
             final HttpParams params) throws IOReactorException {
         super(workerCount, threadFactory, params);
-        this.requestQueue = new SessionRequestQueue();
+        this.requestQueue = new ConcurrentLinkedQueue<SessionRequestImpl>();
         this.lastTimeoutCheck = System.currentTimeMillis();
     }
 
@@ -167,7 +169,7 @@
                 remoteAddress, localAddress, attachment, callback);
         sessionRequest.setConnectTimeout(HttpConnectionParams.getConnectionTimeout(this.params));
         
-        this.requestQueue.push(sessionRequest);
+        this.requestQueue.add(sessionRequest);
         this.selector.wakeup();
         
         return sessionRequest;
@@ -187,7 +189,7 @@
     
     private void processSessionRequests() throws IOReactorException {
         SessionRequestImpl request;
-        while ((request = this.requestQueue.pop()) != null) {
+        while ((request = this.requestQueue.poll()) != null) {
             if (request.isCompleted()) {
                 continue;
             }

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?rev=599819&r1=599818&r2=599819&view=diff
==============================================================================
--- 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
Fri Nov 30 05:45:42 2007
@@ -38,7 +38,9 @@
 import java.nio.channels.ServerSocketChannel;
 import java.nio.channels.SocketChannel;
 import java.util.Iterator;
+import java.util.Queue;
 import java.util.Set;
+import java.util.concurrent.ConcurrentLinkedQueue;
 
 import org.apache.http.nio.reactor.IOReactorException;
 import org.apache.http.nio.reactor.ListenerEndpoint;
@@ -49,14 +51,14 @@
 public class DefaultListeningIOReactor extends AbstractMultiworkerIOReactor 
         implements ListeningIOReactor {
 
-    private final ListenerEndpointQueue requestQueue;
+    private final Queue<ListenerEndpointImpl> requestQueue;
     
     public DefaultListeningIOReactor(
             int workerCount, 
             final ThreadFactory threadFactory,
             final HttpParams params) throws IOReactorException {
         super(workerCount, threadFactory, params);
-        this.requestQueue = new ListenerEndpointQueue();
+        this.requestQueue = new ConcurrentLinkedQueue<ListenerEndpointImpl>();
     }
 
     public DefaultListeningIOReactor(
@@ -119,14 +121,14 @@
             throw new IllegalStateException("I/O reactor has been shut down");
         }
         ListenerEndpointImpl request = new ListenerEndpointImpl(address);
-        this.requestQueue.push(request);
+        this.requestQueue.add(request);
         this.selector.wakeup();
         return request;
     }
 
     private void processSessionRequests() throws IOReactorException {
         ListenerEndpointImpl request;
-        while ((request = this.requestQueue.pop()) != null) {
+        while ((request = this.requestQueue.poll()) != null) {
             SocketAddress address = request.getAddress();
             ServerSocketChannel serverChannel;
             try {



Mime
View raw message