hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r599834 - in /jakarta/httpcomponents/httpcore/trunk/module-nio/src: main/java/org/apache/http/impl/nio/reactor/ main/java/org/apache/http/nio/reactor/ test/java/org/apache/http/impl/nio/reactor/ test/java/org/apache/http/mockup/
Date Fri, 30 Nov 2007 14:40:28 GMT
Author: olegk
Date: Fri Nov 30 06:40:22 2007
New Revision: 599834

URL: http://svn.apache.org/viewvc?rev=599834&view=rev
Log:
Use native Java 1.5 enums

Added:
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/IOReactorStatus.java
  (with props)
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/AbstractMultiworkerIOReactor.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/main/java/org/apache/http/nio/reactor/IOReactor.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpClient.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpServer.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=599834&r1=599833&r2=599834&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 06:40:22 2007
@@ -48,11 +48,12 @@
 
 import org.apache.http.nio.reactor.IOReactor;
 import org.apache.http.nio.reactor.IOReactorException;
+import org.apache.http.nio.reactor.IOReactorStatus;
 import org.apache.http.nio.reactor.IOSession;
 
 public abstract class AbstractIOReactor implements IOReactor {
 
-    private volatile int status;
+    private volatile IOReactorStatus status;
     
     private final Object shutdownMutex;
     private final long selectTimeout;
@@ -76,7 +77,7 @@
             throw new IOReactorException("Failure opening selector", ex);
         }
         this.shutdownMutex = new Object();
-        this.status = INACTIVE;
+        this.status = IOReactorStatus.INACTIVE;
     }
 
     protected abstract void acceptable(SelectionKey key);
@@ -97,7 +98,7 @@
     
     protected abstract void sessionClosed(IOSession session);
     
-    public int getStatus() {
+    public IOReactorStatus getStatus() {
         return this.status;
     }
 
@@ -110,7 +111,7 @@
     }
     
     protected void execute() throws InterruptedIOException, IOReactorException {
-        this.status = ACTIVE;
+        this.status = IOReactorStatus.ACTIVE;
 
         try {
             for (;;) {
@@ -124,12 +125,12 @@
                     throw new IOReactorException("Unexpected selector failure", ex);
                 }
                 
-                if (this.status == SHUT_DOWN) {
+                if (this.status == IOReactorStatus.SHUT_DOWN) {
                     // Hard shut down. Exit select loop immediately
                     break;
                 }
 
-                if (this.status == SHUTTING_DOWN) {
+                if (this.status == IOReactorStatus.SHUTTING_DOWN) {
                     // Graceful shutdown in process
                     // Try to close things out nicely
                     closeSessions();
@@ -148,12 +149,13 @@
                 processClosedSessions();
 
                 // If active process new channels
-                if (this.status == ACTIVE) {
+                if (this.status == IOReactorStatus.ACTIVE) {
                     processNewChannels();
                 }
                 
                 // Exit select loop if graceful shutdown has been completed
-                if (this.status > ACTIVE && this.sessions.isEmpty()) {
+                if (this.status.compareTo(IOReactorStatus.ACTIVE) > 0 
+                        && this.sessions.isEmpty()) {
                     break;
                 }
                 
@@ -165,7 +167,7 @@
         } catch (ClosedSelectorException ex) {
         } finally {
             synchronized (this.shutdownMutex) {
-                this.status = SHUT_DOWN;
+                this.status = IOReactorStatus.SHUT_DOWN;
                 this.shutdownMutex.notifyAll();
             }
         }
@@ -306,20 +308,20 @@
     }
     
     public void gracefulShutdown() {
-        if (this.status != ACTIVE) {
+        if (this.status != IOReactorStatus.ACTIVE) {
             // Already shutting down
             return;
         }
-        this.status = SHUTTING_DOWN;
+        this.status = IOReactorStatus.SHUTTING_DOWN;
         this.selector.wakeup();
     }
         
     public void hardShutdown() throws IOReactorException {
-        if (this.status == SHUT_DOWN) {
+        if (this.status == IOReactorStatus.SHUT_DOWN) {
             // Already shut down
             return;
         }
-        this.status = SHUT_DOWN;
+        this.status = IOReactorStatus.SHUT_DOWN;
         closeNewChannels();
         closeActiveChannels();
     }
@@ -328,7 +330,7 @@
         synchronized (this.shutdownMutex) {
             long deadline = System.currentTimeMillis() + timeout;
             long remaining = timeout;
-            while (this.status != SHUT_DOWN) {
+            while (this.status != IOReactorStatus.SHUT_DOWN) {
                 this.shutdownMutex.wait(remaining);
                 if (timeout > 0) {
                     remaining = deadline - System.currentTimeMillis();
@@ -341,14 +343,14 @@
     }
         
     public void shutdown(long gracePeriod) throws IOReactorException {
-        if (this.status != INACTIVE) {
+        if (this.status != IOReactorStatus.INACTIVE) {
             gracefulShutdown();
             try {
                 awaitShutdown(gracePeriod);
             } catch (InterruptedException ignore) {
             }
         }
-        if (this.status != SHUT_DOWN) {
+        if (this.status != IOReactorStatus.SHUT_DOWN) {
             hardShutdown();
         }
     }

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java?rev=599834&r1=599833&r2=599834&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
Fri Nov 30 06:40:22 2007
@@ -49,12 +49,13 @@
 import org.apache.http.nio.reactor.IOReactor;
 import org.apache.http.nio.reactor.IOReactorException;
 import org.apache.http.nio.reactor.IOReactorExceptionHandler;
+import org.apache.http.nio.reactor.IOReactorStatus;
 import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
 
 public abstract class AbstractMultiworkerIOReactor implements IOReactor {
 
-    protected volatile int status;
+    protected volatile IOReactorStatus status;
     
     protected final HttpParams params;
     protected final Selector selector;
@@ -100,10 +101,10 @@
         }
         this.workers = new Worker[workerCount];
         this.threads = new Thread[workerCount];
-        this.status = INACTIVE;
+        this.status = IOReactorStatus.INACTIVE;
     }
 
-    public int getStatus() {
+    public IOReactorStatus getStatus() {
         return this.status;
     }
 
@@ -123,7 +124,7 @@
             throw new IllegalArgumentException("Event dispatcher may not be null");
         }
 
-        this.status = ACTIVE;
+        this.status = IOReactorStatus.ACTIVE;
         
         // Start I/O dispatchers
         for (int i = 0; i < this.workerCount; i++) {
@@ -132,7 +133,7 @@
             this.threads[i] = this.threadFactory.newThread(this.workers[i]);
         }
         for (int i = 0; i < this.workerCount; i++) {
-            if (this.status != ACTIVE) {
+            if (this.status != IOReactorStatus.ACTIVE) {
                 return;
             }
             this.threads[i].start();
@@ -151,7 +152,7 @@
                     throw new IOReactorException("Unexpected selector failure", ex);
                 }
                 
-                if (this.status > ACTIVE) {
+                if (this.status.compareTo(IOReactorStatus.ACTIVE) > 0) {
                     break;
                 }
                 processEvents(readyCount);
@@ -187,10 +188,10 @@
     }
 
     public void shutdown(long gracePeriod) throws IOException {
-        if (this.status > ACTIVE) {
+        if (this.status.compareTo(IOReactorStatus.ACTIVE) > 0) {
             return;
         }
-        this.status = SHUTTING_DOWN;        
+        this.status = IOReactorStatus.SHUTTING_DOWN;        
         this.selector.wakeup();
         
         // Close out all channels
@@ -219,10 +220,10 @@
             // in time
             for (int i = 0; i < this.workerCount; i++) {
                 BaseIOReactor dispatcher = this.dispatchers[i];
-                if (dispatcher.getStatus() != INACTIVE) {
+                if (dispatcher.getStatus() != IOReactorStatus.INACTIVE) {
                     dispatcher.awaitShutdown(gracePeriod);
                 }
-                if (dispatcher.getStatus() != SHUT_DOWN) {
+                if (dispatcher.getStatus() != IOReactorStatus.SHUT_DOWN) {
                     dispatcher.hardShutdown();
                 }
             }
@@ -236,7 +237,7 @@
         } catch (InterruptedException ex) {
             throw new InterruptedIOException(ex.getMessage());
         } finally {
-            this.status = SHUT_DOWN;        
+            this.status = IOReactorStatus.SHUT_DOWN;        
         }
     }
 

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=599834&r1=599833&r2=599834&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 06:40:22 2007
@@ -45,6 +45,7 @@
 
 import org.apache.http.nio.reactor.ConnectingIOReactor;
 import org.apache.http.nio.reactor.IOReactorException;
+import org.apache.http.nio.reactor.IOReactorStatus;
 import org.apache.http.nio.reactor.SessionRequest;
 import org.apache.http.nio.reactor.SessionRequestCallback;
 import org.apache.http.params.HttpConnectionParams;
@@ -162,7 +163,7 @@
             final Object attachment,
             final SessionRequestCallback callback) {
 
-        if (this.status > ACTIVE) {
+        if (this.status.compareTo(IOReactorStatus.ACTIVE) > 0) {
             throw new IllegalStateException("I/O reactor has been shut down");
         }
         SessionRequestImpl sessionRequest = new SessionRequestImpl(

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=599834&r1=599833&r2=599834&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 06:40:22 2007
@@ -43,6 +43,7 @@
 import java.util.concurrent.ConcurrentLinkedQueue;
 
 import org.apache.http.nio.reactor.IOReactorException;
+import org.apache.http.nio.reactor.IOReactorStatus;
 import org.apache.http.nio.reactor.ListenerEndpoint;
 import org.apache.http.nio.reactor.ListeningIOReactor;
 import org.apache.http.params.HttpParams;
@@ -117,7 +118,7 @@
     }
 
     public ListenerEndpoint listen(final SocketAddress address) {
-        if (this.status > ACTIVE) {
+        if (this.status.compareTo(IOReactorStatus.ACTIVE) > 0) {
             throw new IllegalStateException("I/O reactor has been shut down");
         }
         ListenerEndpointImpl request = new ListenerEndpointImpl(address);

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/IOReactor.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/IOReactor.java?rev=599834&r1=599833&r2=599834&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/IOReactor.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/IOReactor.java
Fri Nov 30 06:40:22 2007
@@ -35,12 +35,7 @@
 
 public interface IOReactor {
 
-    public static final int INACTIVE         = 0;
-    public static final int ACTIVE           = 1;
-    public static final int SHUTTING_DOWN    = 2;
-    public static final int SHUT_DOWN        = 3;
-     
-    int getStatus();
+    IOReactorStatus getStatus();
     
     void execute(IOEventDispatch eventDispatch) 
         throws IOException;

Added: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/IOReactorStatus.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/IOReactorStatus.java?rev=599834&view=auto
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/IOReactorStatus.java
(added)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/IOReactorStatus.java
Fri Nov 30 06:40:22 2007
@@ -0,0 +1,41 @@
+/*
+ * $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.nio.reactor;
+
+public enum IOReactorStatus {
+
+    INACTIVE,
+    ACTIVE,
+    SHUTTING_DOWN,
+    SHUT_DOWN;
+    
+}

Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/IOReactorStatus.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/IOReactorStatus.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/IOReactorStatus.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java?rev=599834&r1=599833&r2=599834&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java
Fri Nov 30 06:40:22 2007
@@ -48,8 +48,8 @@
 import org.apache.http.nio.NHttpServiceHandler;
 import org.apache.http.nio.protocol.EventListener;
 import org.apache.http.nio.protocol.HttpRequestExecutionHandler;
-import org.apache.http.nio.reactor.IOReactor;
 import org.apache.http.nio.reactor.IOReactorExceptionHandler;
+import org.apache.http.nio.reactor.IOReactorStatus;
 import org.apache.http.nio.reactor.ListenerEndpoint;
 import org.apache.http.params.BasicHttpParams;
 import org.apache.http.params.HttpParams;
@@ -256,7 +256,7 @@
         assertNotNull(ex);
         assertTrue(ex instanceof IllegalStateException);
         // I/O reactor shut down itself
-        assertEquals(IOReactor.SHUT_DOWN, this.server.getStatus());
+        assertEquals(IOReactorStatus.SHUT_DOWN, this.server.getStatus());
         
         this.client.shutdown();
         this.server.shutdown();
@@ -345,7 +345,7 @@
         assertNotNull(ex);
         assertTrue(ex instanceof IllegalStateException);
         // I/O reactor shut down itself
-        assertEquals(IOReactor.SHUT_DOWN, this.server.getStatus());
+        assertEquals(IOReactorStatus.SHUT_DOWN, this.server.getStatus());
         
         this.client.shutdown();
         this.server.shutdown();
@@ -430,7 +430,7 @@
         
         this.server.join(1000);
         
-        assertEquals(IOReactor.ACTIVE, this.server.getStatus());
+        assertEquals(IOReactorStatus.ACTIVE, this.server.getStatus());
         assertNull(this.server.getException());
         
         this.client.shutdown();

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpClient.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpClient.java?rev=599834&r1=599833&r2=599834&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpClient.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpClient.java
Fri Nov 30 06:40:22 2007
@@ -39,6 +39,7 @@
 import org.apache.http.nio.NHttpClientHandler;
 import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.IOReactorExceptionHandler;
+import org.apache.http.nio.reactor.IOReactorStatus;
 import org.apache.http.params.HttpParams;
 
 public class TestHttpClient {
@@ -79,7 +80,7 @@
         this.thread.start();
     }
 
-    public int getStatus() {
+    public IOReactorStatus getStatus() {
         return this.ioReactor.getStatus();
     }
     

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpServer.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpServer.java?rev=599834&r1=599833&r2=599834&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpServer.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/mockup/TestHttpServer.java
Fri Nov 30 06:40:22 2007
@@ -39,6 +39,7 @@
 import org.apache.http.nio.NHttpServiceHandler;
 import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.IOReactorExceptionHandler;
+import org.apache.http.nio.reactor.IOReactorStatus;
 import org.apache.http.nio.reactor.ListenerEndpoint;
 import org.apache.http.params.HttpParams;
 
@@ -91,7 +92,7 @@
         this.thread.start();
     }
     
-    public int getStatus() {
+    public IOReactorStatus getStatus() {
         return this.ioReactor.getStatus();
     }
     



Mime
View raw message