cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6882] Making NioReaderEntity completion closer to the CompletionStage pattern
Date Tue, 08 Aug 2017 14:44:22 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 938183d7b -> 344feb533


[CXF-6882] Making NioReaderEntity completion closer to the CompletionStage pattern


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/344feb53
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/344feb53
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/344feb53

Branch: refs/heads/master
Commit: 344feb53305bdf28a807c9fc2d515bda70e5f640
Parents: 938183d
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Tue Aug 8 15:44:05 2017 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Tue Aug 8 15:44:05 2017 +0100

----------------------------------------------------------------------
 .../apache/cxf/jaxrs/nio/NioErrorHandler.java   | 30 --------------------
 .../cxf/jaxrs/nio/NioReadCompletionHandler.java |  2 +-
 .../org/apache/cxf/jaxrs/nio/NioReadEntity.java | 10 ++-----
 .../cxf/jaxrs/nio/NioReadListenerImpl.java      |  4 +--
 .../apache/cxf/jaxrs/nio/NioWriteEntity.java    |  6 ++--
 .../cxf/jaxrs/nio/NioWriteErrorHandler.java     | 30 ++++++++++++++++++++
 .../cxf/systest/jaxrs/nio/NioBookStore.java     | 21 +++++---------
 7 files changed, 45 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/344feb53/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioErrorHandler.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioErrorHandler.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioErrorHandler.java
deleted file mode 100644
index e7a538f..0000000
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioErrorHandler.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * 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.
- */
-package org.apache.cxf.jaxrs.nio;
-
-@FunctionalInterface
-public interface NioErrorHandler {
-    /**
-     * Method called when an exception or error occurred.
-     *
-     * @param throwable the error or exception encountered.
-     */
-    void error(Throwable throwable) throws Throwable;
-}
-

http://git-wip-us.apache.org/repos/asf/cxf/blob/344feb53/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadCompletionHandler.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadCompletionHandler.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadCompletionHandler.java
index c889a0d..2901166 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadCompletionHandler.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadCompletionHandler.java
@@ -20,6 +20,6 @@ package org.apache.cxf.jaxrs.nio;
 
 @FunctionalInterface
 public interface NioReadCompletionHandler {
-    void complete(NioInputStream in);
+    void complete(NioInputStream in, Throwable t);
 }
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/344feb53/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadEntity.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadEntity.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadEntity.java
index a7b17fe..413b744 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadEntity.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadEntity.java
@@ -29,12 +29,10 @@ import org.apache.cxf.transport.http.AbstractHTTPDestination;
 public class NioReadEntity {
     private final NioReadHandler reader;
     private final NioReadCompletionHandler completion;
-    private final NioErrorHandler error;
-
-    public NioReadEntity(NioReadHandler reader, NioReadCompletionHandler completion, NioErrorHandler
error) {
+    
+    public NioReadEntity(NioReadHandler reader, NioReadCompletionHandler completion) {
         this.reader = reader;
         this.completion = completion;
-        this.error = error;
         
         try {
             final Message m = JAXRSUtils.getCurrentMessage();
@@ -56,8 +54,4 @@ public class NioReadEntity {
     public NioReadCompletionHandler getCompletion() {
         return completion;
     }
-
-    public NioErrorHandler getError() {
-        return error;
-    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/344feb53/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadListenerImpl.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadListenerImpl.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadListenerImpl.java
index c39ab36..cece8b9 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadListenerImpl.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadListenerImpl.java
@@ -40,7 +40,7 @@ public final class NioReadListenerImpl implements ReadListener {
     @Override
     public void onError(Throwable t) {
         try {
-            entity.getError().error(t);
+            entity.getCompletion().complete(null, t);
         } catch (final Throwable ex) {
             LOG.warning("NIO NioReadListener error: " + ExceptionUtils.getStackTrace(ex));
         }
@@ -55,6 +55,6 @@ public final class NioReadListenerImpl implements ReadListener {
 
     @Override
     public void onAllDataRead() throws IOException {
-        entity.getCompletion().complete(in);
+        entity.getCompletion().complete(in, null);
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cxf/blob/344feb53/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioWriteEntity.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioWriteEntity.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioWriteEntity.java
index 32874e3..af39eaa 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioWriteEntity.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioWriteEntity.java
@@ -20,9 +20,9 @@ package org.apache.cxf.jaxrs.nio;
 
 public final class NioWriteEntity {
     private final NioWriteHandler writer;
-    private final NioErrorHandler error;
+    private final NioWriteErrorHandler error;
 
-    public NioWriteEntity(final NioWriteHandler writer, final NioErrorHandler error) {
+    public NioWriteEntity(final NioWriteHandler writer, final NioWriteErrorHandler error)
{
         this.writer = writer;
         this.error = error;
     }
@@ -31,7 +31,7 @@ public final class NioWriteEntity {
         return writer;
     }
 
-    public NioErrorHandler getError() {
+    public NioWriteErrorHandler getError() {
         return error;
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/344feb53/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioWriteErrorHandler.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioWriteErrorHandler.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioWriteErrorHandler.java
new file mode 100644
index 0000000..91feb2c
--- /dev/null
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioWriteErrorHandler.java
@@ -0,0 +1,30 @@
+/**
+ * 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.
+ */
+package org.apache.cxf.jaxrs.nio;
+
+@FunctionalInterface
+public interface NioWriteErrorHandler {
+    /**
+     * Method called when an exception or error occurred.
+     *
+     * @param throwable the error or exception encountered.
+     */
+    void error(Throwable throwable) throws Throwable;
+}
+

http://git-wip-us.apache.org/repos/asf/cxf/blob/344feb53/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/nio/NioBookStore.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/nio/NioBookStore.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/nio/NioBookStore.java
index 1498653..7545a28 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/nio/NioBookStore.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/nio/NioBookStore.java
@@ -99,6 +99,7 @@ public class NioBookStore {
         final LongAdder adder = new LongAdder();
 
         new NioReadEntity(
+        // read handler                  
         in -> {
             try {
                 final int n = in.read(buffer);
@@ -107,24 +108,16 @@ public class NioBookStore {
                     out.write(buffer, 0, n);
                 }
             } catch (IOException e) {
-                throw new WebApplicationException(e);
+                response.resume(new WebApplicationException(e));
             }
         },
-        in -> {
-            try {
-                if (!in.isFinished()) {
-                    throw new IllegalStateException("Reader did not finish yet");
-                }
-
-                out.close();
+        // completion handler
+        (in, throwable) -> {
+            if (throwable != null) {
+                response.resume(throwable);
+            } else {
                 response.resume("Book Store uploaded: " + adder.longValue() + " bytes");
-            } catch (IOException e) {
-                throw new WebApplicationException(e);
             }
-        },
-        throwable -> {              // error handler
-            System.out.println("Problem found: " + throwable.getMessage());
-            throw throwable;
         });
     }
 }


Mime
View raw message