hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r836372 - in /httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http: impl/nio/client/HttpExchangeImpl.java nio/concurrent/BasicFuture.java nio/concurrent/FutureCallback.java
Date Sun, 15 Nov 2009 15:29:40 GMT
Author: olegk
Date: Sun Nov 15 15:29:39 2009
New Revision: 836372

URL: http://svn.apache.org/viewvc?rev=836372&view=rev
Log:
Simplifed FutureCallback interface

Modified:
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/HttpExchangeImpl.java
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/nio/concurrent/BasicFuture.java
    httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/nio/concurrent/FutureCallback.java

Modified: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/HttpExchangeImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/HttpExchangeImpl.java?rev=836372&r1=836371&r2=836372&view=diff
==============================================================================
--- httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/HttpExchangeImpl.java
(original)
+++ httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/impl/nio/client/HttpExchangeImpl.java
Sun Nov 15 15:29:39 2009
@@ -86,40 +86,33 @@
         this.responseFuture.cancel(true);
     }
 
-    private synchronized void sessionRequestCompleted() {
-        try {
-            this.managedSession = this.sessionFuture.get();
-            if (this.managedSession == null || this.sessionFuture.isCancelled()) {
-                this.responseFuture.cancel(true);
-            } else {
-                IOSession iosession = this.managedSession.getSession();
-                iosession.setAttribute(InternalRequestExecutionHandler.HTTP_EXCHANGE, this);
-                iosession.setEvent(SelectionKey.OP_WRITE);
-            }
-        } catch (InterruptedException ex) {
-            this.responseFuture.cancel(true);
-        } catch (ExecutionException ex) {
-            Throwable cause = ex.getCause(); 
-            if (cause != null && cause instanceof Exception) {
-                this.responseFuture.failed((Exception) cause);
-            } else {
-                this.responseFuture.failed(ex);
-            }
-        }
+    private synchronized void requestCompleted(final ManagedIOSession session) {
+        this.managedSession = session;
+        IOSession iosession = session.getSession();
+        iosession.setAttribute(InternalRequestExecutionHandler.HTTP_EXCHANGE, this);
+        iosession.setEvent(SelectionKey.OP_WRITE);
+    }
+    
+    private synchronized void requestFailed(final Exception ex) {
+        this.responseFuture.failed(ex);
+    }
+    
+    private synchronized void requestCancelled() {
+        this.responseFuture.cancel(true);
     }
     
     class InternalFutureCallback implements FutureCallback<ManagedIOSession> {
 
-        public void completed(final Future<ManagedIOSession> future) {
-            sessionRequestCompleted();
+        public void completed(final ManagedIOSession session) {
+            requestCompleted(session);
         }
 
-        public void failed(final Future<ManagedIOSession> future) {
-            sessionRequestCompleted();
+        public void failed(final Exception ex) {
+            requestFailed(ex);
         }
         
-        public void cancelled(final Future<ManagedIOSession> future) {
-            sessionRequestCompleted();            
+        public void cancelled() {
+            requestCancelled();            
         }
 
     }

Modified: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/nio/concurrent/BasicFuture.java
URL: http://svn.apache.org/viewvc/httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/nio/concurrent/BasicFuture.java?rev=836372&r1=836371&r2=836372&view=diff
==============================================================================
--- httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/nio/concurrent/BasicFuture.java
(original)
+++ httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/nio/concurrent/BasicFuture.java
Sun Nov 15 15:29:39 2009
@@ -97,10 +97,10 @@
         }
         this.completed = true;
         this.result = result;
-        notifyAll();
         if (this.callback != null) {
-            this.callback.completed(this);
+            this.callback.completed(result);
         }
+        notifyAll();
         return true;
     }
 
@@ -110,10 +110,10 @@
         }
         this.completed = true;
         this.ex = exception;
-        notifyAll();
         if (this.callback != null) {
-            this.callback.failed(this);
+            this.callback.failed(exception);
         }
+        notifyAll();
         return true;
     }
 
@@ -123,10 +123,10 @@
         }
         this.completed = true;
         this.cancelled = true;
-        notifyAll();
         if (this.callback != null) {
-            this.callback.cancelled(this);
+            this.callback.cancelled();
         }
+        notifyAll();
         return true;
     }
 

Modified: httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/nio/concurrent/FutureCallback.java
URL: http://svn.apache.org/viewvc/httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/nio/concurrent/FutureCallback.java?rev=836372&r1=836371&r2=836372&view=diff
==============================================================================
--- httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/nio/concurrent/FutureCallback.java
(original)
+++ httpcomponents/asynchttpclient/trunk/src/main/java/org/apache/http/nio/concurrent/FutureCallback.java
Sun Nov 15 15:29:39 2009
@@ -26,14 +26,12 @@
  */
 package org.apache.http.nio.concurrent;
 
-import java.util.concurrent.Future;
-
 public interface FutureCallback<T> {
 
-    void completed(Future<T> future);
+    void completed(T result);
 
-    void failed(Future<T> future);
+    void failed(Exception ex);
 
-    void cancelled(Future<T> future);
+    void cancelled();
 
 }



Mime
View raw message