aboutsummaryrefslogtreecommitdiffstats
path: root/container-core/src/main/java/com/yahoo/processing/rendering
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@verizonmedia.com>2021-12-06 14:35:27 +0100
committerBjørn Christian Seime <bjorncs@verizonmedia.com>2021-12-06 17:23:01 +0100
commit2c8d19b82de5ec4b47a5eb4ab566bbcb1725d118 (patch)
tree1d535de3b8621d827c6657edfb1eb26fa803410d /container-core/src/main/java/com/yahoo/processing/rendering
parentffdbd053a2b57383b2d463e8050394776b14abdf (diff)
Deprecate public APIs using Guava's ListenableFuture
Public methods: - com.yahoo.processing.rendering.Renderer.render() - com.yahoo.search.handler.HttpSearchResponse.waitableRender() - com.yahoo.processing.rendering.AsynchronousSectionedRenderer.renderBeforeHandover()
Diffstat (limited to 'container-core/src/main/java/com/yahoo/processing/rendering')
-rw-r--r--container-core/src/main/java/com/yahoo/processing/rendering/AsynchronousSectionedRenderer.java36
-rw-r--r--container-core/src/main/java/com/yahoo/processing/rendering/Renderer.java22
2 files changed, 42 insertions, 16 deletions
diff --git a/container-core/src/main/java/com/yahoo/processing/rendering/AsynchronousSectionedRenderer.java b/container-core/src/main/java/com/yahoo/processing/rendering/AsynchronousSectionedRenderer.java
index b77d493ea30..21375ee3d76 100644
--- a/container-core/src/main/java/com/yahoo/processing/rendering/AsynchronousSectionedRenderer.java
+++ b/container-core/src/main/java/com/yahoo/processing/rendering/AsynchronousSectionedRenderer.java
@@ -3,11 +3,10 @@ package com.yahoo.processing.rendering;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
-import com.google.common.util.concurrent.SettableFuture;
+import com.yahoo.concurrent.CompletableFutures;
import com.yahoo.concurrent.ThreadFactoryFactory;
import com.yahoo.jdisc.handler.CompletionHandler;
import com.yahoo.jdisc.handler.ContentChannel;
-import java.util.logging.Level;
import com.yahoo.processing.Request;
import com.yahoo.processing.Response;
import com.yahoo.processing.execution.Execution;
@@ -23,12 +22,14 @@ import java.util.ArrayDeque;
import java.util.Collections;
import java.util.Deque;
import java.util.List;
+import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
+import java.util.logging.Level;
import java.util.logging.Logger;
/**
@@ -126,7 +127,7 @@ public abstract class AsynchronousSectionedRenderer<RESPONSE extends Response> e
return executor;
}
- private SettableFuture<Boolean> success;
+ private CompletableFuture<Boolean> success;
private ContentChannel channel;
private CompletionHandler completionHandler;
@@ -173,8 +174,8 @@ public abstract class AsynchronousSectionedRenderer<RESPONSE extends Response> e
* @return a future indicating whether rendering was successful
*/
@Override
- public final ListenableFuture<Boolean> render(OutputStream stream, RESPONSE response,
- Execution execution, Request request) {
+ public final CompletableFuture<Boolean> renderResponse(OutputStream stream, RESPONSE response,
+ Execution execution, Request request) {
if (beforeHandoverMode) { // rendering has already started or is already complete
beforeHandoverMode = false;
if ( ! dataListListenerStack.isEmpty() &&
@@ -215,22 +216,31 @@ public abstract class AsynchronousSectionedRenderer<RESPONSE extends Response> e
* At this point the worker thread still owns the Response, so all this rendering must happen
* on the caller thread invoking freeze (that is, on the thread calling this).
*/
- public final ListenableFuture<Boolean> renderBeforeHandover(OutputStream stream, RESPONSE response,
- Execution execution, Request request) {
+ public final CompletableFuture<Boolean> renderResponseBeforeHandover(OutputStream stream, RESPONSE response,
+ Execution execution, Request request) {
beforeHandoverMode = true;
if ( ! isInitialized) throw new IllegalStateException("render() invoked before init().");
return startRender(stream, response, execution, request);
}
- private ListenableFuture<Boolean> startRender(OutputStream stream, RESPONSE response,
+
+ /** @deprecated Use {@link #renderResponseBeforeHandover(OutputStream, Response, Execution, Request)} */
+ @Deprecated(forRemoval = true, since = "7")
+ @SuppressWarnings("removal")
+ public final ListenableFuture<Boolean> renderBeforeHandover(OutputStream stream, RESPONSE response,
+ Execution execution, Request request) {
+ return CompletableFutures.toGuavaListenableFuture(renderResponseBeforeHandover(stream, response, execution, request));
+ }
+
+ private CompletableFuture<Boolean> startRender(OutputStream stream, RESPONSE response,
Execution execution, Request request) {
this.response = response;
this.stream = stream;
this.execution = execution;
DataListListener parentOfTopLevelListener = new DataListListener(new ParentOfTopLevel(request,response.data()), null);
dataListListenerStack.addFirst(parentOfTopLevelListener);
- success = SettableFuture.create();
+ success = new CompletableFuture<>();
try {
getExecutor().execute(parentOfTopLevelListener);
} catch (RejectedExecutionException e) {
@@ -471,11 +481,11 @@ public abstract class AsynchronousSectionedRenderer<RESPONSE extends Response> e
logger.log(Level.WARNING, "Exception caught while closing stream to client.", e);
} finally {
if (failed != null) {
- success.setException(failed);
+ success.completeExceptionally(failed);
} else if (closeException != null) {
- success.setException(closeException);
+ success.completeExceptionally(closeException);
} else {
- success.set(true);
+ success.complete(true);
}
if (channel != null) {
channel.close(completionHandler);
@@ -541,7 +551,7 @@ public abstract class AsynchronousSectionedRenderer<RESPONSE extends Response> e
} catch (Exception ignored) {
}
}
- success.setException(e);
+ success.completeExceptionally(e);
}
}
} catch (Error e) {
diff --git a/container-core/src/main/java/com/yahoo/processing/rendering/Renderer.java b/container-core/src/main/java/com/yahoo/processing/rendering/Renderer.java
index 14ec3002b0a..8db4ed4f624 100644
--- a/container-core/src/main/java/com/yahoo/processing/rendering/Renderer.java
+++ b/container-core/src/main/java/com/yahoo/processing/rendering/Renderer.java
@@ -3,11 +3,13 @@ package com.yahoo.processing.rendering;
import com.google.common.util.concurrent.ListenableFuture;
import com.yahoo.component.AbstractComponent;
+import com.yahoo.concurrent.CompletableFutures;
import com.yahoo.processing.Request;
import com.yahoo.processing.Response;
import com.yahoo.processing.execution.Execution;
import java.io.OutputStream;
+import java.util.concurrent.CompletableFuture;
/**
* Renders a response to a stream. The renderers are cloned just before
@@ -41,6 +43,17 @@ public abstract class Renderer<RESPONSE extends Response> extends AbstractCompon
}
/**
+ * @deprecated Use/implement {@link #renderResponse(OutputStream, Response, Execution, Request)} instead.
+ * Return type changed from {@link ListenableFuture} to {@link CompletableFuture}.
+ */
+ @Deprecated(forRemoval = true, since = "7")
+ @SuppressWarnings("removal")
+ public ListenableFuture<Boolean> render(OutputStream stream, RESPONSE response, Execution execution,
+ Request request) {
+ return CompletableFutures.toGuavaListenableFuture(renderResponse(stream, response, execution, request));
+ }
+
+ /**
* Render a response to a stream. The stream also exposes a ByteBuffer API
* for efficient transactions to JDisc. The returned future will throw the
* exception causing failure wrapped in an ExecutionException if rendering
@@ -50,10 +63,13 @@ public abstract class Renderer<RESPONSE extends Response> extends AbstractCompon
* @param response the response to render
* @param execution the execution which created this response
* @param request the request matching the response
- * @return a ListenableFuture containing a boolean where true indicates a successful rendering
+ * @return a {@link CompletableFuture} containing a boolean where true indicates a successful rendering
*/
- public abstract ListenableFuture<Boolean> render(OutputStream stream, RESPONSE response,
- Execution execution, Request request);
+ @SuppressWarnings("removal")
+ public CompletableFuture<Boolean> renderResponse(OutputStream stream, RESPONSE response,
+ Execution execution, Request request) {
+ return CompletableFutures.toCompletableFuture(render(stream, response, execution, request));
+ }
/**
* Name of the output encoding, if applicable.