[prev in list] [next in list] [prev in thread] [next in thread]
List: httpcomponents-commits
Subject: svn commit: r1761318 [4/8] - in /httpcomponents/httpcore/trunk: httpcore5-h2/src/main/java/org/apach
From: olegk () apache ! org
Date: 2016-09-18 11:29:33
Message-ID: 20160918112935.0FE093A18B6 () svn01-us-west ! apache ! org
[Download RAW message or body]
Copied: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncExchangeHandler.java \
(from r1761317, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/ \
java/org/apache/hc/core5/http2/nio/AsyncExchangeHandler.java?p2=httpcomponents/httpcor \
e/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncExchangeHandler. \
java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java&r1=1761317&r2=1761318&rev=1761318&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java \
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncExchangeHandler.java \
Sun Sep 18 11:29:30 2016 @@ -24,17 +24,22 @@
* <http://www.apache.org/>.
*
*/
-package org.apache.hc.core5.http2.frame;
+package org.apache.hc.core5.http2.nio;
-public final class FrameConsts {
+import java.io.IOException;
- private FrameConsts() {
- // Do not allow utility class to be instantiated.
- }
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpRequest;
- public final static int HEAD_LEN = 9;
- public final static int MAX_PADDING = 255;
- public final static int MIN_FRAME_SIZE = 2 ^ 14;
- public final static int MAX_FRAME_SIZE = 2 ^ 24 - 1;
+/**
+ * Abstract asynchronous message exchange handler that acts as a request consumer \
and a response producer. + *
+ * @since 5.0
+ */
+public interface AsyncExchangeHandler extends AsyncDataConsumer, AsyncDataProducer {
+
+ void handleRequest(HttpRequest request, boolean enclosedBody, ResponseChannel \
responseChannel) throws HttpException, IOException; +
+ void failed(Exception cause);
-};
+}
Copied: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncPushConsumer.java \
(from r1761317, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/ \
java/org/apache/hc/core5/http2/nio/AsyncPushConsumer.java?p2=httpcomponents/httpcore/t \
runk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncPushConsumer.java&p \
1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java&r1=1761317&r2=1761318&rev=1761318&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java \
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncPushConsumer.java \
Sun Sep 18 11:29:30 2016 @@ -24,17 +24,23 @@
* <http://www.apache.org/>.
*
*/
-package org.apache.hc.core5.http2.frame;
+package org.apache.hc.core5.http2.nio;
-public final class FrameConsts {
+import java.io.IOException;
- private FrameConsts() {
- // Do not allow utility class to be instantiated.
- }
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.HttpResponse;
- public final static int HEAD_LEN = 9;
- public final static int MAX_PADDING = 255;
- public final static int MIN_FRAME_SIZE = 2 ^ 14;
- public final static int MAX_FRAME_SIZE = 2 ^ 24 - 1;
+/**
+ * Abstract asynchronous push response consumer.
+ *
+ * @since 5.0
+ */
+public interface AsyncPushConsumer extends AsyncDataConsumer {
+
+ void consumePromise(HttpRequest promise, HttpResponse response) throws \
HttpException, IOException; +
+ void failed(Exception cause);
-};
+}
Copied: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncPushProducer.java \
(from r1761317, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/ \
java/org/apache/hc/core5/http2/nio/AsyncPushProducer.java?p2=httpcomponents/httpcore/t \
runk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncPushProducer.java&p \
1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java&r1=1761317&r2=1761318&rev=1761318&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java \
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncPushProducer.java \
Sun Sep 18 11:29:30 2016 @@ -24,17 +24,21 @@
* <http://www.apache.org/>.
*
*/
-package org.apache.hc.core5.http2.frame;
+package org.apache.hc.core5.http2.nio;
-public final class FrameConsts {
+import java.io.IOException;
- private FrameConsts() {
- // Do not allow utility class to be instantiated.
- }
+import org.apache.hc.core5.http.HttpException;
- public final static int HEAD_LEN = 9;
- public final static int MAX_PADDING = 255;
- public final static int MIN_FRAME_SIZE = 2 ^ 14;
- public final static int MAX_FRAME_SIZE = 2 ^ 24 - 1;
+/**
+ * Abstract asynchronous push response producer.
+ *
+ * @since 5.0
+ */
+public interface AsyncPushProducer extends AsyncDataProducer {
+
+ void produceResponse(ResponseChannel channel) throws HttpException, IOException;
+
+ void failed(Exception cause);
-};
+}
Copied: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncRequestConsumer.java \
(from r1761317, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/ \
java/org/apache/hc/core5/http2/nio/AsyncRequestConsumer.java?p2=httpcomponents/httpcor \
e/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncRequestConsumer. \
java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java&r1=1761317&r2=1761318&rev=1761318&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java \
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncRequestConsumer.java \
Sun Sep 18 11:29:30 2016 @@ -24,17 +24,21 @@
* <http://www.apache.org/>.
*
*/
-package org.apache.hc.core5.http2.frame;
+package org.apache.hc.core5.http2.nio;
-public final class FrameConsts {
+import java.io.IOException;
- private FrameConsts() {
- // Do not allow utility class to be instantiated.
- }
+import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpRequest;
- public final static int HEAD_LEN = 9;
- public final static int MAX_PADDING = 255;
- public final static int MIN_FRAME_SIZE = 2 ^ 14;
- public final static int MAX_FRAME_SIZE = 2 ^ 24 - 1;
+/**
+ * Abstract asynchronous request consumer.
+ *
+ * @since 5.0
+ */
+public interface AsyncRequestConsumer<T> extends AsyncDataConsumer {
+
+ void consumeRequest(HttpRequest request, boolean endStream, FutureCallback<T> \
resultCallback) throws HttpException, IOException;
-};
+}
Copied: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncRequestProducer.java \
(from r1761317, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/ \
java/org/apache/hc/core5/http2/nio/AsyncRequestProducer.java?p2=httpcomponents/httpcor \
e/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncRequestProducer. \
java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java&r1=1761317&r2=1761318&rev=1761318&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java \
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncRequestProducer.java \
Sun Sep 18 11:29:30 2016 @@ -24,17 +24,25 @@
* <http://www.apache.org/>.
*
*/
-package org.apache.hc.core5.http2.frame;
+package org.apache.hc.core5.http2.nio;
-public final class FrameConsts {
+import java.io.IOException;
- private FrameConsts() {
- // Do not allow utility class to be instantiated.
- }
+import org.apache.hc.core5.http.HttpRequest;
- public final static int HEAD_LEN = 9;
- public final static int MAX_PADDING = 255;
- public final static int MIN_FRAME_SIZE = 2 ^ 14;
- public final static int MAX_FRAME_SIZE = 2 ^ 24 - 1;
+/**
+ * Abstract asynchronous request producer.
+ *
+ * @since 5.0
+ */
+public interface AsyncRequestProducer extends AsyncDataProducer {
+
+ HttpRequest produceRequest();
+
+ boolean isEnclosingEntity();
+
+ void dataStart(final DataStreamChannel channel) throws IOException;
+
+ void failed(Exception cause);
-};
+}
Copied: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncResponseConsumer.java \
(from r1761317, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/ \
java/org/apache/hc/core5/http2/nio/AsyncResponseConsumer.java?p2=httpcomponents/httpco \
re/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncResponseConsume \
r.java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java&r1=1761317&r2=1761318&rev=1761318&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java \
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncResponseConsumer.java \
Sun Sep 18 11:29:30 2016 @@ -24,17 +24,21 @@
* <http://www.apache.org/>.
*
*/
-package org.apache.hc.core5.http2.frame;
+package org.apache.hc.core5.http2.nio;
-public final class FrameConsts {
+import java.io.IOException;
- private FrameConsts() {
- // Do not allow utility class to be instantiated.
- }
+import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpResponse;
- public final static int HEAD_LEN = 9;
- public final static int MAX_PADDING = 255;
- public final static int MIN_FRAME_SIZE = 2 ^ 14;
- public final static int MAX_FRAME_SIZE = 2 ^ 24 - 1;
+/**
+ * Abstract asynchronous response consumer.
+ *
+ * @since 5.0
+ */
+public interface AsyncResponseConsumer<T> extends AsyncDataConsumer {
+
+ void consumeResponse(HttpResponse response, FutureCallback<T> resultCallback) \
throws HttpException, IOException;
-};
+}
Copied: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncResponseProducer.java \
(from r1761317, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/ \
java/org/apache/hc/core5/http2/nio/AsyncResponseProducer.java?p2=httpcomponents/httpco \
re/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncResponseProduce \
r.java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java&r1=1761317&r2=1761318&rev=1761318&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java \
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncResponseProducer.java \
Sun Sep 18 11:29:30 2016 @@ -24,17 +24,25 @@
* <http://www.apache.org/>.
*
*/
-package org.apache.hc.core5.http2.frame;
+package org.apache.hc.core5.http2.nio;
-public final class FrameConsts {
+import java.io.IOException;
- private FrameConsts() {
- // Do not allow utility class to be instantiated.
- }
+import org.apache.hc.core5.http.HttpResponse;
- public final static int HEAD_LEN = 9;
- public final static int MAX_PADDING = 255;
- public final static int MIN_FRAME_SIZE = 2 ^ 14;
- public final static int MAX_FRAME_SIZE = 2 ^ 24 - 1;
+/**
+ * Abstract asynchronous response producer.
+ *
+ * @since 5.0
+ */
+public interface AsyncResponseProducer extends AsyncDataProducer {
+
+ HttpResponse produceResponse();
+
+ boolean isEnclosingEntity();
+
+ void dataStart(final DataStreamChannel channel) throws IOException;
+
+ void failed(Exception cause);
-};
+}
Copied: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncResponseTrigger.java \
(from r1761317, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/ \
java/org/apache/hc/core5/http2/nio/AsyncResponseTrigger.java?p2=httpcomponents/httpcor \
e/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncResponseTrigger. \
java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java&r1=1761317&r2=1761318&rev=1761318&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java \
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/AsyncResponseTrigger.java \
Sun Sep 18 11:29:30 2016 @@ -24,17 +24,26 @@
* <http://www.apache.org/>.
*
*/
-package org.apache.hc.core5.http2.frame;
-public final class FrameConsts {
+package org.apache.hc.core5.http2.nio;
- private FrameConsts() {
- // Do not allow utility class to be instantiated.
- }
+import java.io.IOException;
- public final static int HEAD_LEN = 9;
- public final static int MAX_PADDING = 255;
- public final static int MIN_FRAME_SIZE = 2 ^ 14;
- public final static int MAX_FRAME_SIZE = 2 ^ 24 - 1;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpRequest;
-};
+/**
+ * Abstract asynchronous response / response promise trigger.
+ *
+ * @since 5.0
+ */
+@Contract(threading = ThreadingBehavior.SAFE)
+public interface AsyncResponseTrigger {
+
+ void submitResponse(AsyncResponseProducer responseProducer) throws \
HttpException, IOException; +
+ void pushPromise(HttpRequest promise, AsyncPushProducer responseProducer) throws \
HttpException, IOException; +
+}
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicPushProducer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicPushProducer.java?rev=1761318&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicPushProducer.java \
(added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicPushProducer.java \
Sun Sep 18 11:29:30 2016 @@ -0,0 +1,102 @@
+/*
+ * ====================================================================
+ * 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.hc.core5.http2.nio;
+
+import java.io.IOException;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpHeaders;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.HttpStatus;
+import org.apache.hc.core5.http.message.BasicHttpResponse;
+import org.apache.hc.core5.util.Args;
+
+/**
+ * @since 5.0
+ */
+public class BasicPushProducer implements AsyncPushProducer {
+
+ private final HttpResponse response;
+ private final AsyncEntityProducer dataProducer;
+ private final AtomicBoolean dataStarted;
+
+ public BasicPushProducer(final HttpResponse response, final AsyncEntityProducer \
dataProducer) { + this.response = Args.notNull(response, "Response");
+ this.dataProducer = Args.notNull(dataProducer, "Entity producer");
+ this.dataStarted = new AtomicBoolean(false);
+ }
+
+ public BasicPushProducer(final int code, final AsyncEntityProducer dataProducer) \
{ + this(new BasicHttpResponse(code), dataProducer);
+ }
+
+ public BasicPushProducer(final AsyncEntityProducer dataProducer) {
+ this(HttpStatus.SC_OK, dataProducer);
+ }
+
+ @Override
+ public void produceResponse(final ResponseChannel channel) throws HttpException, \
IOException { + if (!response.containsHeader(HttpHeaders.CONTENT_TYPE)) {
+ if (dataProducer != null) {
+ final String contentType = dataProducer.getContentType();
+ if (contentType != null) {
+ response.addHeader(HttpHeaders.CONTENT_TYPE, contentType);
+ }
+ }
+ }
+ channel.sendResponse(response, dataProducer != null);
+ }
+
+ @Override
+ public int available() {
+ return dataProducer != null ? dataProducer.available() : 0;
+ }
+
+ @Override
+ public void produce(final DataStreamChannel channel) throws IOException {
+ if (dataProducer != null) {
+ if (dataStarted.compareAndSet(false, true)) {
+ dataProducer.streamStart(channel);
+ }
+ dataProducer.produce(channel);
+ }
+ }
+
+ @Override
+ public void failed(final Exception cause) {
+ releaseResources();
+ }
+
+ @Override
+ public void releaseResources() {
+ if (dataProducer != null) {
+ dataProducer.releaseResources();
+ }
+ }
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicPushProducer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicPushProducer.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicPushProducer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicRequestConsumer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/ \
java/org/apache/hc/core5/http2/nio/BasicRequestConsumer.java?rev=1761318&view=auto \
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicRequestConsumer.java \
(added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicRequestConsumer.java \
Sun Sep 18 11:29:30 2016 @@ -0,0 +1,104 @@
+/*
+ * ====================================================================
+ * 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.hc.core5.http2.nio;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.List;
+
+import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpHeaders;
+import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.Message;
+import org.apache.hc.core5.util.Args;
+
+/**
+ * @since 5.0
+ */
+public class BasicRequestConsumer<T> implements \
AsyncRequestConsumer<Message<HttpRequest, T>> { +
+ private final AsyncEntityConsumer<T> dataConsumer;
+
+ public BasicRequestConsumer(final AsyncEntityConsumer<T> dataConsumer) {
+ this.dataConsumer = dataConsumer;
+ }
+
+ @Override
+ public void consumeRequest(
+ final HttpRequest request,
+ final boolean enclosedBody,
+ final FutureCallback<Message<HttpRequest, T>> resultCallback) throws \
HttpException, IOException { + Args.notNull(request, "Request");
+ Args.notNull(resultCallback, "Result callback");
+ if (enclosedBody) {
+ final Header header = request.getFirstHeader(HttpHeaders.CONTENT_TYPE);
+ dataConsumer.streamStart(header != null ? header.getValue() : null, new \
FutureCallback<T>() { +
+ @Override
+ public void completed(final T result) {
+ resultCallback.completed(new Message<>(request, result));
+ }
+
+ @Override
+ public void failed(final Exception ex) {
+ resultCallback.failed(ex);
+ }
+
+ @Override
+ public void cancelled() {
+ resultCallback.cancelled();
+ }
+
+ });
+ } else {
+ resultCallback.completed(new Message<>(request, (T) null));
+ }
+ }
+
+ @Override
+ public void updateCapacity(final CapacityChannel capacityChannel) throws \
IOException { + dataConsumer.updateCapacity(capacityChannel);
+ }
+
+ @Override
+ public void consume(final ByteBuffer src) throws IOException {
+ dataConsumer.consume(src);
+ }
+
+ @Override
+ public void streamEnd(final List<Header> trailers) throws HttpException, \
IOException { + dataConsumer.streamEnd(trailers);
+ }
+
+ @Override
+ public void releaseResources() {
+ dataConsumer.releaseResources();
+ }
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicRequestConsumer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicRequestConsumer.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicRequestConsumer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicRequestProducer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/ \
java/org/apache/hc/core5/http2/nio/BasicRequestProducer.java?rev=1761318&view=auto \
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicRequestProducer.java \
(added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicRequestProducer.java \
Sun Sep 18 11:29:30 2016 @@ -0,0 +1,102 @@
+/*
+ * ====================================================================
+ * 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.hc.core5.http2.nio;
+
+import java.io.IOException;
+import java.net.URI;
+
+import org.apache.hc.core5.http.HttpHeaders;
+import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.message.BasicHttpRequest;
+
+public class BasicRequestProducer implements AsyncRequestProducer {
+
+ private final HttpRequest request;
+ private final AsyncEntityProducer dataProducer;
+
+ public BasicRequestProducer(final HttpRequest request, final AsyncEntityProducer \
dataProducer) { + this.request = request;
+ this.dataProducer = dataProducer;
+ }
+
+ public BasicRequestProducer(final String method, final URI requestUri, final \
AsyncEntityProducer dataProducer) { + this(new BasicHttpRequest(method, \
requestUri), dataProducer); + }
+
+ public BasicRequestProducer(final String method, final URI requestUri) {
+ this(method, requestUri, null);
+ }
+
+ @Override
+ public HttpRequest produceRequest() {
+ if (!request.containsHeader(HttpHeaders.CONTENT_TYPE)) {
+ if (dataProducer != null) {
+ final String contentType = dataProducer.getContentType();
+ if (contentType != null) {
+ request.addHeader(HttpHeaders.CONTENT_TYPE, contentType);
+ }
+ }
+ }
+ return request;
+ }
+
+ @Override
+ public boolean isEnclosingEntity() {
+ return dataProducer != null;
+ }
+
+ @Override
+ public void dataStart(final DataStreamChannel channel) throws IOException {
+ if (dataProducer != null) {
+ dataProducer.streamStart(channel);
+ }
+ }
+
+ @Override
+ public int available() {
+ return dataProducer != null ? dataProducer.available() : 0;
+ }
+
+ @Override
+ public void produce(final DataStreamChannel channel) throws IOException {
+ if (dataProducer != null) {
+ dataProducer.produce(channel);
+ }
+ }
+
+ @Override
+ public void failed(final Exception cause) {
+ releaseResources();
+ }
+
+ @Override
+ public void releaseResources() {
+ if (dataProducer != null) {
+ dataProducer.releaseResources();
+ }
+ }
+}
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicRequestProducer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicRequestProducer.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicRequestProducer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicResponseConsumer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/ \
java/org/apache/hc/core5/http2/nio/BasicResponseConsumer.java?rev=1761318&view=auto \
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicResponseConsumer.java \
(added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicResponseConsumer.java \
Sun Sep 18 11:29:30 2016 @@ -0,0 +1,99 @@
+/*
+ * ====================================================================
+ * 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.hc.core5.http2.nio;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.List;
+
+import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpHeaders;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.Message;
+import org.apache.hc.core5.util.Args;
+
+/**
+ * @since 5.0
+ */
+public class BasicResponseConsumer<T> implements \
AsyncResponseConsumer<Message<HttpResponse, T>> { +
+ private final AsyncEntityConsumer<T> dataConsumer;
+
+ public BasicResponseConsumer(final AsyncEntityConsumer<T> dataConsumer) {
+ this.dataConsumer = dataConsumer;
+ }
+
+ @Override
+ public void consumeResponse(
+ final HttpResponse response,
+ final FutureCallback<Message<HttpResponse, T>> resultCallback) throws \
HttpException, IOException { + Args.notNull(response, "Response");
+ Args.notNull(resultCallback, "Result callback");
+ final Header header = response.getFirstHeader(HttpHeaders.CONTENT_TYPE);
+ dataConsumer.streamStart(header != null ? header.getValue() : null, new \
FutureCallback<T>() { +
+ @Override
+ public void completed(final T result) {
+ resultCallback.completed(new Message<>(response, result));
+ }
+
+ @Override
+ public void failed(final Exception ex) {
+ resultCallback.failed(ex);
+ }
+
+ @Override
+ public void cancelled() {
+ resultCallback.cancelled();
+ }
+
+ });
+ }
+
+ @Override
+ public void updateCapacity(final CapacityChannel capacityChannel) throws \
IOException { + dataConsumer.updateCapacity(capacityChannel);
+ }
+
+ @Override
+ public void consume(final ByteBuffer src) throws IOException {
+ dataConsumer.consume(src);
+ }
+
+ @Override
+ public void streamEnd(final List<Header> trailers) throws HttpException, \
IOException { + dataConsumer.streamEnd(trailers);
+ }
+
+ @Override
+ public void releaseResources() {
+ dataConsumer.releaseResources();
+ }
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicResponseConsumer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicResponseConsumer.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicResponseConsumer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicResponseProducer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/ \
java/org/apache/hc/core5/http2/nio/BasicResponseProducer.java?rev=1761318&view=auto \
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicResponseProducer.java \
(added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicResponseProducer.java \
Sun Sep 18 11:29:30 2016 @@ -0,0 +1,107 @@
+/*
+ * ====================================================================
+ * 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.hc.core5.http2.nio;
+
+import java.io.IOException;
+
+import org.apache.hc.core5.http.HttpHeaders;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.HttpStatus;
+import org.apache.hc.core5.http.message.BasicHttpResponse;
+import org.apache.hc.core5.util.Args;
+
+/**
+ * @since 5.0
+ */
+public class BasicResponseProducer implements AsyncResponseProducer {
+
+ private final HttpResponse response;
+ private final AsyncEntityProducer dataProducer;
+
+ public BasicResponseProducer(final HttpResponse response, final \
AsyncEntityProducer dataProducer) { + this.response = Args.notNull(response, \
"Response"); + this.dataProducer = dataProducer;
+ }
+
+ public BasicResponseProducer(final int code, final AsyncEntityProducer \
dataProducer) { + this(new BasicHttpResponse(code), dataProducer);
+ }
+
+ public BasicResponseProducer(final AsyncEntityProducer dataProducer) {
+ this(HttpStatus.SC_OK, dataProducer);
+ }
+
+ @Override
+ public HttpResponse produceResponse() {
+ if (!response.containsHeader(HttpHeaders.CONTENT_TYPE)) {
+ if (dataProducer != null) {
+ final String contentType = dataProducer.getContentType();
+ if (contentType != null) {
+ response.addHeader(HttpHeaders.CONTENT_TYPE, contentType);
+ }
+ }
+ }
+ return response;
+ }
+
+ @Override
+ public boolean isEnclosingEntity() {
+ return dataProducer != null;
+ }
+
+ @Override
+ public void dataStart(final DataStreamChannel channel) throws IOException {
+ if (dataProducer != null) {
+ dataProducer.streamStart(channel);
+ }
+ }
+
+ @Override
+ public int available() {
+ return dataProducer != null ? dataProducer.available() : 0;
+ }
+
+ @Override
+ public void produce(final DataStreamChannel channel) throws IOException {
+ if (dataProducer != null) {
+ dataProducer.produce(channel);
+ }
+ }
+
+ @Override
+ public void failed(final Exception cause) {
+ releaseResources();
+ }
+
+ @Override
+ public void releaseResources() {
+ if (dataProducer != null) {
+ dataProducer.releaseResources();
+ }
+ }
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicResponseProducer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicResponseProducer.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicResponseProducer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/CapacityChannel.java \
(from r1761317, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/ \
java/org/apache/hc/core5/http2/nio/CapacityChannel.java?p2=httpcomponents/httpcore/tru \
nk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/CapacityChannel.java&p1=ht \
tpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java&r1=1761317&r2=1761318&rev=1761318&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java \
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/CapacityChannel.java \
Sun Sep 18 11:29:30 2016 @@ -24,17 +24,23 @@
* <http://www.apache.org/>.
*
*/
-package org.apache.hc.core5.http2.frame;
+package org.apache.hc.core5.http2.nio;
-public final class FrameConsts {
+import java.io.IOException;
- private FrameConsts() {
- // Do not allow utility class to be instantiated.
- }
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
- public final static int HEAD_LEN = 9;
- public final static int MAX_PADDING = 255;
- public final static int MIN_FRAME_SIZE = 2 ^ 14;
- public final static int MAX_FRAME_SIZE = 2 ^ 24 - 1;
+/**
+ * Abstract capacity update channel.
+ * <p>
+ * Implementations are expected to be thread-safe.
+ *
+ * @since 5.0
+ */
+@Contract(threading = ThreadingBehavior.SAFE)
+public interface CapacityChannel {
+
+ void update(int increment) throws IOException;
-};
+}
Copied: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/DataStreamChannel.java \
(from r1761317, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/ \
java/org/apache/hc/core5/http2/nio/DataStreamChannel.java?p2=httpcomponents/httpcore/t \
runk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/DataStreamChannel.java&p \
1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java&r1=1761317&r2=1761318&rev=1761318&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java \
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/DataStreamChannel.java \
Sun Sep 18 11:29:30 2016 @@ -24,17 +24,29 @@
* <http://www.apache.org/>.
*
*/
-package org.apache.hc.core5.http2.frame;
-public final class FrameConsts {
+package org.apache.hc.core5.http2.nio;
- private FrameConsts() {
- // Do not allow utility class to be instantiated.
- }
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.List;
- public final static int HEAD_LEN = 9;
- public final static int MAX_PADDING = 255;
- public final static int MIN_FRAME_SIZE = 2 ^ 14;
- public final static int MAX_FRAME_SIZE = 2 ^ 24 - 1;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.Header;
-};
+/**
+ * Abstract data stream channel
+ * <p>
+ * Implementations are expected to be thread-safe.
+ *
+ * @since 5.0
+ */
+@Contract(threading = ThreadingBehavior.SAFE)
+public interface DataStreamChannel extends StreamChannel<ByteBuffer> {
+
+ void requestOutput();
+
+ void endStream(List<Header> trailers) throws IOException;
+
+}
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/FixedResponseExchangeHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/ \
java/org/apache/hc/core5/http2/nio/FixedResponseExchangeHandler.java?rev=1761318&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/FixedResponseExchangeHandler.java \
(added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/FixedResponseExchangeHandler.java \
Sun Sep 18 11:29:30 2016 @@ -0,0 +1,68 @@
+/*
+ * ====================================================================
+ * 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.hc.core5.http2.nio;
+
+import java.io.IOException;
+
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.Message;
+import org.apache.hc.core5.http.entity.ContentType;
+import org.apache.hc.core5.http.message.BasicHttpResponse;
+import org.apache.hc.core5.http2.nio.entity.NoopEntityConsumer;
+import org.apache.hc.core5.http2.nio.entity.StringAsyncEntityProducer;
+import org.apache.hc.core5.util.Args;
+
+/**
+ * @since 5.0
+ */
+public final class FixedResponseExchangeHandler extends \
AbstractAsyncExchangeHandler<Void>{ +
+ private final AsyncResponseProducer responseProducer;
+
+ public FixedResponseExchangeHandler(final AsyncResponseProducer \
responseProducer) { + super(new NoopEntityConsumer());
+ this.responseProducer = Args.notNull(responseProducer, "Response producer");
+ }
+
+ public FixedResponseExchangeHandler(final HttpResponse response, final String \
message) { + this(new BasicResponseProducer(response, new \
StringAsyncEntityProducer(message, ContentType.TEXT_PLAIN))); + }
+
+ public FixedResponseExchangeHandler(final int status, final String message) {
+ this(new BasicHttpResponse(status), message);
+ }
+
+ @Override
+ protected void handle(
+ final Message<HttpRequest, Void> request,
+ final AsyncResponseTrigger responseTrigger) throws IOException, \
HttpException { + responseTrigger.submitResponse(responseProducer);
+ }
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/FixedResponseExchangeHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/FixedResponseExchangeHandler.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/FixedResponseExchangeHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/HandlerFactory.java \
(from r1761317, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/ \
java/org/apache/hc/core5/http2/nio/HandlerFactory.java?p2=httpcomponents/httpcore/trun \
k/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/HandlerFactory.java&p1=http \
components/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java&r1=1761317&r2=1761318&rev=1761318&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java \
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/HandlerFactory.java \
Sun Sep 18 11:29:30 2016 @@ -24,17 +24,23 @@
* <http://www.apache.org/>.
*
*/
-package org.apache.hc.core5.http2.frame;
+package org.apache.hc.core5.http2.nio;
-public final class FrameConsts {
+import java.io.IOException;
- private FrameConsts() {
- // Do not allow utility class to be instantiated.
- }
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.protocol.HttpContext;
- public final static int HEAD_LEN = 9;
- public final static int MAX_PADDING = 255;
- public final static int MIN_FRAME_SIZE = 2 ^ 14;
- public final static int MAX_FRAME_SIZE = 2 ^ 24 - 1;
+/**
+ * Abstract handler factory.
+ *
+ * @param <T> resource holder
+ *
+ * @since 5.0
+ */
+public interface HandlerFactory<T extends ResourceHolder> {
+
+ T create(HttpRequest request, HttpContext context) throws HttpException, \
IOException;
-};
+}
Copied: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/ResourceHolder.java \
(from r1761317, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/ \
java/org/apache/hc/core5/http2/nio/ResourceHolder.java?p2=httpcomponents/httpcore/trun \
k/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/ResourceHolder.java&p1=http \
components/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java&r1=1761317&r2=1761318&rev=1761318&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java \
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/ResourceHolder.java \
Sun Sep 18 11:29:30 2016 @@ -24,17 +24,18 @@
* <http://www.apache.org/>.
*
*/
-package org.apache.hc.core5.http2.frame;
+package org.apache.hc.core5.http2.nio;
-public final class FrameConsts {
-
- private FrameConsts() {
- // Do not allow utility class to be instantiated.
- }
+/**
+ * Abstract resource holder.
+ * <p>
+ * Implementations are expected to ensure that {@link #releaseResources()} methods \
is idempotent and is + * safe to invoke multiple times..
+ *
+ * @since 5.0
+ */
+public interface ResourceHolder {
- public final static int HEAD_LEN = 9;
- public final static int MAX_PADDING = 255;
- public final static int MIN_FRAME_SIZE = 2 ^ 14;
- public final static int MAX_FRAME_SIZE = 2 ^ 24 - 1;
+ void releaseResources();
-};
+}
Copied: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/ResponseChannel.java \
(from r1761317, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/ \
java/org/apache/hc/core5/http2/nio/ResponseChannel.java?p2=httpcomponents/httpcore/tru \
nk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/ResponseChannel.java&p1=ht \
tpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java&r1=1761317&r2=1761318&rev=1761318&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java \
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/ResponseChannel.java \
Sun Sep 18 11:29:30 2016 @@ -24,17 +24,29 @@
* <http://www.apache.org/>.
*
*/
-package org.apache.hc.core5.http2.frame;
-public final class FrameConsts {
+package org.apache.hc.core5.http2.nio;
- private FrameConsts() {
- // Do not allow utility class to be instantiated.
- }
+import java.io.IOException;
- public final static int HEAD_LEN = 9;
- public final static int MAX_PADDING = 255;
- public final static int MIN_FRAME_SIZE = 2 ^ 14;
- public final static int MAX_FRAME_SIZE = 2 ^ 24 - 1;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.HttpResponse;
-};
+/**
+ * Abstract response / response promise channel.
+ * <p>
+ * Implementations are expected to be thread-safe.
+ *
+ * @since 5.0
+ */
+@Contract(threading = ThreadingBehavior.SAFE)
+public interface ResponseChannel {
+
+ void sendResponse(HttpResponse response, boolean endStream) throws \
HttpException, IOException; +
+ void pushPromise(HttpRequest promise, AsyncPushProducer pushProducer) throws \
HttpException, IOException; +
+}
Copied: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/StreamChannel.java \
(from r1761317, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/ \
java/org/apache/hc/core5/http2/nio/StreamChannel.java?p2=httpcomponents/httpcore/trunk \
/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/StreamChannel.java&p1=httpco \
mponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java&r1=1761317&r2=1761318&rev=1761318&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java \
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/StreamChannel.java \
Sun Sep 18 11:29:30 2016 @@ -24,17 +24,20 @@
* <http://www.apache.org/>.
*
*/
-package org.apache.hc.core5.http2.frame;
-public final class FrameConsts {
+package org.apache.hc.core5.http2.nio;
- private FrameConsts() {
- // Do not allow utility class to be instantiated.
- }
+import java.io.IOException;
+import java.nio.Buffer;
- public final static int HEAD_LEN = 9;
- public final static int MAX_PADDING = 255;
- public final static int MIN_FRAME_SIZE = 2 ^ 14;
- public final static int MAX_FRAME_SIZE = 2 ^ 24 - 1;
+/**
+ * Abstract stream channel.
+ *
+ * @since 5.0
+ */
+public interface StreamChannel<T extends Buffer> {
+
+ int write(T src) throws IOException;
-};
+ void endStream() throws IOException;
+}
Copied: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/Supplier.java \
(from r1761317, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/ \
java/org/apache/hc/core5/http2/nio/Supplier.java?p2=httpcomponents/httpcore/trunk/http \
core5-h2/src/main/java/org/apache/hc/core5/http2/nio/Supplier.java&p1=httpcomponents/h \
ttpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java&r1=1761317&r2=1761318&rev=1761318&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java \
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/Supplier.java \
Sun Sep 18 11:29:30 2016 @@ -24,17 +24,16 @@
* <http://www.apache.org/>.
*
*/
-package org.apache.hc.core5.http2.frame;
-public final class FrameConsts {
+package org.apache.hc.core5.http2.nio;
- private FrameConsts() {
- // Do not allow utility class to be instantiated.
- }
+/**
+ * Abstract object supplier.
+ *
+ * @since 5.0
+ */
+public interface Supplier<T> {
- public final static int HEAD_LEN = 9;
- public final static int MAX_PADDING = 255;
- public final static int MIN_FRAME_SIZE = 2 ^ 14;
- public final static int MAX_FRAME_SIZE = 2 ^ 24 - 1;
+ T get();
-};
+}
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/command/ClientCommandEndpoint.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/ \
java/org/apache/hc/core5/http2/nio/command/ClientCommandEndpoint.java?rev=1761318&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/command/ClientCommandEndpoint.java \
(added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/command/ClientCommandEndpoint.java \
Sun Sep 18 11:29:30 2016 @@ -0,0 +1,90 @@
+/*
+ * ====================================================================
+ * 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.hc.core5.http2.nio.command;
+
+import java.nio.channels.SelectionKey;
+import java.util.concurrent.Future;
+
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.concurrent.BasicFuture;
+import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http2.nio.AsyncRequestProducer;
+import org.apache.hc.core5.http2.nio.AsyncResponseConsumer;
+import org.apache.hc.core5.reactor.Command;
+import org.apache.hc.core5.reactor.IOSession;
+
+/**
+ * Endpoint that can be used to initiate client side operations by submitting a \
{@link Command} object. + *
+ * @since 5.0
+ */
+@Contract(threading = ThreadingBehavior.SAFE_CONDITIONAL)
+public final class ClientCommandEndpoint {
+
+ private final IOSession ioSession;
+
+ public ClientCommandEndpoint(final IOSession ioSession) {
+ super();
+ this.ioSession = ioSession;
+ }
+
+ public <T> Future<T> execute(
+ final AsyncRequestProducer requestProducer,
+ final AsyncResponseConsumer<T> responseConsumer,
+ final FutureCallback<T> callback) {
+ final BasicFuture<T> future = new BasicFuture<>(callback);
+ final Command executionCommand = new ExecutionCommand<>(requestProducer, \
responseConsumer, new FutureCallback<T>() { +
+ @Override
+ public void completed(final T result) {
+ future.completed(result);
+ }
+
+ @Override
+ public void failed(final Exception ex) {
+ future.failed(ex);
+ }
+
+ @Override
+ public void cancelled() {
+ future.cancel();
+ }
+
+ });
+ ioSession.getCommandQueue().add(executionCommand);
+ ioSession.setEvent(SelectionKey.OP_WRITE);
+ return future;
+ }
+
+ public void requestGracefulShutdown() {
+ ioSession.getCommandQueue().addFirst(ShutdownCommand.GRACEFUL);
+ ioSession.setEvent(SelectionKey.OP_WRITE);
+ }
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/command/ClientCommandEndpoint.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/command/ClientCommandEndpoint.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/command/ClientCommandEndpoint.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/command/ExecutionCommand.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/ \
java/org/apache/hc/core5/http2/nio/command/ExecutionCommand.java?rev=1761318&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/command/ExecutionCommand.java \
(added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/command/ExecutionCommand.java \
Sun Sep 18 11:29:30 2016 @@ -0,0 +1,88 @@
+/*
+ * ====================================================================
+ * 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.hc.core5.http2.nio.command;
+
+import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http2.nio.AsyncRequestProducer;
+import org.apache.hc.core5.http2.nio.AsyncResponseConsumer;
+import org.apache.hc.core5.reactor.Command;
+
+/**
+ * Request execution command.
+ *
+ * @param <T> message processing result type.
+ *
+ * @since 5.0
+ */
+public final class ExecutionCommand<T> implements Command {
+
+ private final AsyncRequestProducer requestProducer;
+ private final AsyncResponseConsumer<T> responseConsumer;
+ private final FutureCallback<T> callback;
+
+ public ExecutionCommand(
+ final AsyncRequestProducer requestProducer,
+ final AsyncResponseConsumer<T> responseConsumer,
+ final FutureCallback<T> callback) {
+ this.requestProducer = requestProducer;
+ this.responseConsumer = responseConsumer;
+ this.callback = callback;
+ }
+
+ public AsyncRequestProducer getRequestProducer() {
+ return requestProducer;
+ }
+
+ public AsyncResponseConsumer<T> getResponseConsumer() {
+ return responseConsumer;
+ }
+
+ public FutureCallback<T> getCallback() {
+ return callback;
+ }
+
+ @Override
+ public boolean cancel() {
+ try {
+ requestProducer.releaseResources();
+ responseConsumer.releaseResources();
+ } finally {
+ if (callback != null) {
+ callback.cancelled();
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "Request: " + requestProducer;
+ }
+
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/command/ExecutionCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/command/ExecutionCommand.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/command/ExecutionCommand.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/command/ShutdownCommand.java \
(from r1761317, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/ \
java/org/apache/hc/core5/http2/nio/command/ShutdownCommand.java?p2=httpcomponents/http \
core/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/command/ShutdownCo \
mmand.java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java&r1=1761317&r2=1761318&rev=1761318&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java \
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/command/ShutdownCommand.java \
Sun Sep 18 11:29:30 2016 @@ -24,17 +24,39 @@
* <http://www.apache.org/>.
*
*/
-package org.apache.hc.core5.http2.frame;
-public final class FrameConsts {
+package org.apache.hc.core5.http2.nio.command;
- private FrameConsts() {
- // Do not allow utility class to be instantiated.
+import org.apache.hc.core5.reactor.Command;
+
+/**
+ * Shutdown command.
+ *
+ * @since 5.0
+ */
+public final class ShutdownCommand implements Command {
+
+ public static final ShutdownCommand GRACEFUL = new \
ShutdownCommand(ShutdownType.GRACEFUL); + public static final ShutdownCommand \
IMMEDIATE = new ShutdownCommand(ShutdownType.IMMEDIATE); +
+ private final ShutdownType type;
+
+ public ShutdownCommand(final ShutdownType type) {
+ this.type = type;
}
- public final static int HEAD_LEN = 9;
- public final static int MAX_PADDING = 255;
- public final static int MIN_FRAME_SIZE = 2 ^ 14;
- public final static int MAX_FRAME_SIZE = 2 ^ 24 - 1;
+ public ShutdownType getType() {
+ return type;
+ }
+
+ @Override
+ public boolean cancel() {
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "Shutdown: " + type;
+ }
-};
+}
Copied: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/command/ShutdownType.java \
(from r1761317, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/ \
java/org/apache/hc/core5/http2/nio/command/ShutdownType.java?p2=httpcomponents/httpcor \
e/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/command/ShutdownType. \
java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java&r1=1761317&r2=1761318&rev=1761318&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java \
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/command/ShutdownType.java \
Sun Sep 18 11:29:30 2016 @@ -24,17 +24,16 @@
* <http://www.apache.org/>.
*
*/
-package org.apache.hc.core5.http2.frame;
-public final class FrameConsts {
+package org.apache.hc.core5.http2.nio.command;
- private FrameConsts() {
- // Do not allow utility class to be instantiated.
- }
+/**
+ * Shutdown type.
+ *
+ * @since 5.0
+ */
+public enum ShutdownType {
- public final static int HEAD_LEN = 9;
- public final static int MAX_PADDING = 255;
- public final static int MIN_FRAME_SIZE = 2 ^ 14;
- public final static int MAX_FRAME_SIZE = 2 ^ 24 - 1;
+ IMMEDIATE, GRACEFUL
-};
+}
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractBinAsyncEntityConsumer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/ \
java/org/apache/hc/core5/http2/nio/entity/AbstractBinAsyncEntityConsumer.java?rev=1761318&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractBinAsyncEntityConsumer.java \
(added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractBinAsyncEntityConsumer.java \
Sun Sep 18 11:29:30 2016 @@ -0,0 +1,72 @@
+/*
+ * ====================================================================
+ * 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.hc.core5.http2.nio.entity;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.nio.charset.UnsupportedCharsetException;
+import java.util.List;
+
+import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.entity.ContentType;
+import org.apache.hc.core5.http2.nio.AsyncEntityConsumer;
+import org.apache.hc.core5.util.Args;
+
+public abstract class AbstractBinAsyncEntityConsumer<T> implements \
AsyncEntityConsumer<T> { +
+ protected abstract void dataStart(ContentType contentType, FutureCallback<T> \
resultCallback) throws HttpException, IOException; +
+ protected abstract void consumeData(ByteBuffer src) throws IOException;
+
+ protected abstract void dataEnd() throws IOException;
+
+ @Override
+ public final void streamStart(
+ final String contentType,
+ final FutureCallback<T> resultCallback) throws IOException, \
HttpException { + Args.notNull(resultCallback, "Result callback");
+ try {
+ dataStart(contentType != null ? ContentType.parse(contentType) : null, \
resultCallback); + } catch (UnsupportedCharsetException ex) {
+ throw new UnsupportedEncodingException(ex.getMessage());
+ }
+ }
+
+ @Override
+ public final void consume(final ByteBuffer src) throws IOException {
+ consumeData(src);
+ }
+
+ @Override
+ public final void streamEnd(final List<Header> trailers) throws IOException {
+ dataEnd();
+ }
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractBinAsyncEntityConsumer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractBinAsyncEntityConsumer.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractBinAsyncEntityConsumer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractBinAsyncEntityProducer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/ \
java/org/apache/hc/core5/http2/nio/entity/AbstractBinAsyncEntityProducer.java?rev=1761318&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractBinAsyncEntityProducer.java \
(added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractBinAsyncEntityProducer.java \
Sun Sep 18 11:29:30 2016 @@ -0,0 +1,112 @@
+/*
+ * ====================================================================
+ * 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.hc.core5.http2.nio.entity;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import org.apache.hc.core5.http.entity.ContentType;
+import org.apache.hc.core5.http2.nio.AsyncEntityProducer;
+import org.apache.hc.core5.http2.nio.DataStreamChannel;
+import org.apache.hc.core5.http2.nio.StreamChannel;
+import org.apache.hc.core5.util.Args;
+
+/**
+ * @since 5.0
+ */
+public abstract class AbstractBinAsyncEntityProducer implements AsyncEntityProducer \
{ +
+ private final ContentType contentType;
+ private final ByteBuffer bytebuf;
+
+ private volatile boolean endStream;
+
+ public AbstractBinAsyncEntityProducer(final int bufferSize, final ContentType \
contentType) { + Args.positive(bufferSize, "Buffer size");
+ this.bytebuf = ByteBuffer.allocate(bufferSize);
+ this.contentType = contentType;
+ }
+
+ protected abstract void dataStart() throws IOException;
+
+ protected abstract void produceData(StreamChannel<ByteBuffer> channel) throws \
IOException; +
+ @Override
+ public final String getContentType() {
+ return contentType != null ? contentType.toString() : null;
+ }
+
+ @Override
+ public final void streamStart(final DataStreamChannel channel) throws \
IOException { + dataStart();
+ }
+
+ @Override
+ public final void produce(final DataStreamChannel channel) throws IOException {
+ produceData(new StreamChannel<ByteBuffer>() {
+
+ @Override
+ public int write(final ByteBuffer src) throws IOException {
+ Args.notNull(src, "ByteBuffer");
+ final int chunk = src.remaining();
+ if (chunk == 0) {
+ return 0;
+ }
+ if (bytebuf.remaining() >= chunk) {
+ bytebuf.put(src);
+ return chunk;
+ }
+ if (bytebuf.position() > 0) {
+ bytebuf.flip();
+ final int bytesWritten = channel.write(bytebuf);
+ bytebuf.compact();
+ return bytesWritten;
+ }
+ if (bytebuf.position() == 0) {
+ return channel.write(src);
+ }
+ return 0;
+ }
+
+ @Override
+ public void endStream() throws IOException {
+ endStream = true;
+ }
+
+ });
+
+ if (bytebuf.remaining() > 1024 || endStream) {
+ bytebuf.flip();
+ channel.write(bytebuf);
+ bytebuf.compact();
+ }
+ if (bytebuf.position() == 0 && endStream) {
+ channel.endStream();
+ }
+ }
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractBinAsyncEntityProducer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractBinAsyncEntityProducer.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractBinAsyncEntityProducer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractCharAsyncEntityConsumer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/ \
java/org/apache/hc/core5/http2/nio/entity/AbstractCharAsyncEntityConsumer.java?rev=1761318&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractCharAsyncEntityConsumer.java \
(added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractCharAsyncEntityConsumer.java \
Sun Sep 18 11:29:30 2016 @@ -0,0 +1,124 @@
+/*
+ * ====================================================================
+ * 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.hc.core5.http2.nio.entity;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CoderResult;
+import java.nio.charset.StandardCharsets;
+import java.nio.charset.UnsupportedCharsetException;
+import java.util.List;
+
+import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.entity.ContentType;
+import org.apache.hc.core5.http2.nio.AsyncEntityConsumer;
+import org.apache.hc.core5.util.Args;
+
+/**
+ * @since 5.0
+ */
+public abstract class AbstractCharAsyncEntityConsumer<T> implements \
AsyncEntityConsumer<T> { +
+ private static final ByteBuffer EMPTY = ByteBuffer.wrap(new byte[0]);
+
+ private volatile ContentType contentType;
+ private volatile CharsetDecoder charsetDecoder;
+ private volatile CharBuffer charbuf;
+
+ protected abstract void dataStart(ContentType contentType, FutureCallback<T> \
resultCallback) throws HttpException, IOException; +
+ protected abstract void consumeData(CharBuffer src) throws IOException;
+
+ protected abstract void dataEnd() throws IOException;
+
+ @Override
+ public final void streamStart(
+ final String contentType,
+ final FutureCallback<T> resultCallback) throws IOException, \
HttpException { + Args.notNull(resultCallback, "Result callback");
+ try {
+ this.contentType = contentType != null ? ContentType.parse(contentType) \
: null; + dataStart(this.contentType, resultCallback);
+ } catch (UnsupportedCharsetException ex) {
+ throw new UnsupportedEncodingException(ex.getMessage());
+ }
+ }
+
+ private void checkResult(final CoderResult result) throws IOException {
+ if (result.isError()) {
+ result.throwException();
+ }
+ }
+
+ private void doDecode() throws IOException {
+ charbuf.flip();
+ final int chunk = charbuf.remaining();
+ if (chunk > 0) {
+ consumeData(charbuf);
+ }
+ charbuf.compact();
+ }
+
+ public final void consume(final ByteBuffer src) throws IOException {
+ Args.notNull(src, "ByteBuffer");
+ if (charsetDecoder == null) {
+ Charset charset = contentType != null ? contentType.getCharset() : null;
+ if (charset == null) {
+ charset = StandardCharsets.US_ASCII;
+ }
+ charsetDecoder = charset.newDecoder();
+ }
+ if (charbuf == null) {
+ charbuf = CharBuffer.allocate(2048);
+ }
+ while (src.hasRemaining()) {
+ checkResult(charsetDecoder.decode(src, charbuf, false));
+ doDecode();
+ }
+ }
+
+ @Override
+ public final void streamEnd(final List<Header> trailers) throws IOException {
+ if (charsetDecoder != null) {
+ if (charbuf == null) {
+ charbuf = CharBuffer.allocate(512);
+ }
+ checkResult(charsetDecoder.decode(EMPTY, charbuf, true));
+ doDecode();
+ checkResult(charsetDecoder.flush(charbuf));
+ doDecode();
+ }
+ dataEnd();
+ }
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractCharAsyncEntityConsumer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractCharAsyncEntityConsumer.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractCharAsyncEntityConsumer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic