diff options
author | Jon Bratseth <bratseth@verizonmedia.com> | 2019-04-25 22:42:45 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@verizonmedia.com> | 2019-04-25 22:42:45 +0200 |
commit | b89ccbc43e55dc458d65374f8c265330565ca7ea (patch) | |
tree | e9f39a1fa629e1d7ace5d06197045c345648f807 /vespa-http-client | |
parent | 249fe76c9437d0f1a033294df98d8d8101baef2c (diff) |
Revert "Merge pull request #9188 from vespa-engine/revert-9183-bratseth/deprecate-httpclient-session"
This reverts commit a21f0b780458f792dc7e30c134d917fa60d72d02, reversing
changes made to 59effeb20e153dd4c00eaf071f288d19b15d455d.
Diffstat (limited to 'vespa-http-client')
14 files changed, 68 insertions, 40 deletions
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/FeedClientFactory.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/FeedClientFactory.java index 6095134b7a2..4d50905da7b 100644 --- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/FeedClientFactory.java +++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/FeedClientFactory.java @@ -5,7 +5,9 @@ package com.yahoo.vespa.http.client; import com.yahoo.vespa.http.client.config.SessionParams; import com.yahoo.vespa.http.client.core.api.FeedClientImpl; -import static com.yahoo.vespa.http.client.SessionFactory.createTimeoutExecutor; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.ThreadFactory; /** * Factory for creating FeedClient. @@ -15,7 +17,7 @@ import static com.yahoo.vespa.http.client.SessionFactory.createTimeoutExecutor; public class FeedClientFactory { /** - * Creates a FeedClient. + * Creates a FeedClient. Call this sparingly: Feed clients are expensive and should be as long-lived as possible. * * @param sessionParams parameters for connection, hosts, cluster configurations and more. * @param resultCallback on each result, this callback is called. @@ -25,4 +27,31 @@ public class FeedClientFactory { return new FeedClientImpl(sessionParams, resultCallback, createTimeoutExecutor()); } + static ScheduledThreadPoolExecutor createTimeoutExecutor() { + ScheduledThreadPoolExecutor timeoutExecutor; + timeoutExecutor = new ScheduledThreadPoolExecutor(1, new DaemonThreadFactory("timeout-")); + timeoutExecutor.setRemoveOnCancelPolicy(true); + timeoutExecutor.setContinueExistingPeriodicTasksAfterShutdownPolicy(false); + timeoutExecutor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); + return timeoutExecutor; + } + + private static class DaemonThreadFactory implements ThreadFactory { + + private final ThreadFactory defaultThreadFactory = Executors.defaultThreadFactory(); + private final String prefix; + + private DaemonThreadFactory(String prefix) { + this.prefix = prefix; + } + + @Override + public Thread newThread(Runnable runnable) { + Thread t = defaultThreadFactory.newThread(runnable); + t.setDaemon(true); + t.setName(prefix + t.getName()); + return t; + } + } + } diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/Session.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/Session.java index de39eabd3ee..3089717c260 100644 --- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/Session.java +++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/Session.java @@ -15,7 +15,9 @@ import java.util.concurrent.BlockingQueue; * * @author Einar M R Rosenvinge * @see SessionFactory + * @deprecated use either FeedClient or SyncFeedClient // TODO: Remove on Vespa 8 */ +@Deprecated public interface Session extends AutoCloseable { /** diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/SessionFactory.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/SessionFactory.java index 2e47e45dff0..04d45afe2d0 100644 --- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/SessionFactory.java +++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/SessionFactory.java @@ -14,7 +14,9 @@ import java.util.concurrent.ThreadFactory; * Factory for creating {@link Session} instances. * * @author Einar M R Rosenvinge + * @deprecated use either FeedClient or SyncFeedClient // TODO: Remove on Vespa 8 */ +@Deprecated public final class SessionFactory { /** diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/ConnectionParams.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/ConnectionParams.java index bd187ea3371..f503190864b 100644 --- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/ConnectionParams.java +++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/ConnectionParams.java @@ -16,10 +16,7 @@ import java.util.Objects; import java.util.concurrent.TimeUnit; /** - * Parameters given to a {@link com.yahoo.vespa.http.client.SessionFactory} - * when creating {@link com.yahoo.vespa.http.client.Session}s. The parameters - * contained in this class are related to the connections from the node running - * the Session to the Vespa clusters. + * Connection level parameters. * This class is immutable * and has no public constructor - to instantiate one, use a {@link Builder}. * @@ -31,9 +28,9 @@ public final class ConnectionParams { * Builder for {@link ConnectionParams}. */ public static final class Builder { + private SSLContext sslContext = null; private HostnameVerifier hostnameVerifier = SSLConnectionSocketFactory.getDefaultHostnameVerifier(); - private long connectionTimeout = TimeUnit.SECONDS.toMillis(60); private final Multimap<String, String> headers = ArrayListMultimap.create(); private final Map<String, HeaderProvider> headerProviders = new HashMap<>(); private int numPersistentConnectionsPerEndpoint = 1; @@ -225,7 +222,6 @@ public final class ConnectionParams { return new ConnectionParams( sslContext, hostnameVerifier, - connectionTimeout, headers, headerProviders, numPersistentConnectionsPerEndpoint, @@ -280,7 +276,6 @@ public final class ConnectionParams { } private final SSLContext sslContext; private final HostnameVerifier hostnameVerifier; - private final long connectionTimeout; private final Multimap<String, String> headers = ArrayListMultimap.create(); private final Map<String, HeaderProvider> headerProviders = new HashMap<>(); private final int numPersistentConnectionsPerEndpoint; @@ -297,7 +292,6 @@ public final class ConnectionParams { private ConnectionParams( SSLContext sslContext, HostnameVerifier hostnameVerifier, - long connectionTimeout, Multimap<String, String> headers, Map<String, HeaderProvider> headerProviders, int numPersistentConnectionsPerEndpoint, @@ -312,7 +306,6 @@ public final class ConnectionParams { boolean printTraceToStdErr) { this.sslContext = sslContext; this.hostnameVerifier = hostnameVerifier; - this.connectionTimeout = connectionTimeout; this.headers.putAll(headers); this.headerProviders.putAll(headerProviders); this.numPersistentConnectionsPerEndpoint = numPersistentConnectionsPerEndpoint; diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/FeedParams.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/FeedParams.java index 30f1ad11d3a..008f3b63a89 100644 --- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/FeedParams.java +++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/FeedParams.java @@ -6,8 +6,7 @@ import com.google.common.annotations.Beta; import java.util.concurrent.TimeUnit; /** - * Parameters given to a {@link com.yahoo.vespa.http.client.SessionFactory} - * when creating {@link com.yahoo.vespa.http.client.Session}s. This class is immutable + * Feed level parameters. This class is immutable * and has no public constructor - to instantiate one, use a {@link Builder}. * @author Einar M R Rosenvinge @@ -25,8 +24,8 @@ public final class FeedParams { public boolean getSilentUpgrade() { return silentUpgrade; } /** - * Enumeration of data formats that are acceptable by the OutputStream - * returned by {@link com.yahoo.vespa.http.client.Session#stream(CharSequence)}. + * Enumeration of data formats that are acceptable by the + * {@link com.yahoo.vespa.http.client.FeedClient} methods. */ public enum DataFormat { /** UTF-8-encoded XML. Preamble is not necessary. */ @@ -117,9 +116,7 @@ public final class FeedParams { * * Note that the TOTAL timeout of any one operation in this API would be * {@link #getServerTimeout(java.util.concurrent.TimeUnit)} + - * {@link #getClientTimeout(java.util.concurrent.TimeUnit)}, - * after which {@link com.yahoo.vespa.http.client.Session#results()} is guaranteed - * to produce a Result. + * {@link #getClientTimeout(java.util.concurrent.TimeUnit)}. * * @param serverTimeout timeout value * @param unit unit of timeout value @@ -135,14 +132,13 @@ public final class FeedParams { /** * Sets the client-side timeout for each operation. If BOTH the server-side - * timeout AND this timeout has passed, {@link com.yahoo.vespa.http.client.Session} + * timeout AND this timeout has passed, the {@link com.yahoo.vespa.http.client.FeedClient} * will synthesize a {@link com.yahoo.vespa.http.client.Result}. * * Note that the TOTAL timeout of any one operation in this API would be * {@link #getServerTimeout(java.util.concurrent.TimeUnit)} + * {@link #getClientTimeout(java.util.concurrent.TimeUnit)}, - * after which {@link com.yahoo.vespa.http.client.Session#results()} is guaranteed - * to produce a Result. + * after which a result callback is guaranteed to be made. * * @param clientTimeout timeout value * @param unit unit of timeout value diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/SessionParams.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/SessionParams.java index daa6eecb823..48fd21e2b1f 100644 --- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/SessionParams.java +++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/SessionParams.java @@ -8,12 +8,12 @@ import java.util.LinkedList; import java.util.List; /** - * Parameters given to a {@link com.yahoo.vespa.http.client.SessionFactory} - * when creating {@link com.yahoo.vespa.http.client.Session}s. This class is immutable + * Parameters given to a {@link com.yahoo.vespa.http.client.FeedClientFactory} + * when creating {@link com.yahoo.vespa.http.client.FeedClient}s. This class is immutable * and has no public constructor - to instantiate one, use a {@link Builder}. * * @author Einar M R Rosenvinge - * @see com.yahoo.vespa.http.client.SessionFactory + * @see com.yahoo.vespa.http.client.FeedClientFactory * @see Builder */ public final class SessionParams { @@ -85,8 +85,7 @@ public final class SessionParams { /** * Sets the maximum number of document operations to hold in memory, waiting to be - * sent to Vespa. When this threshold is reached, {@link java.io.OutputStream#close()} will block, - * see {@link com.yahoo.vespa.http.client.Session#stream(CharSequence)}. + * sent to Vespa. When this threshold is reached, {@link java.io.OutputStream#close()} will block. * * @param clientQueueSize the maximum number of document operations to hold in memory. * @return pointer to builder. @@ -111,7 +110,7 @@ public final class SessionParams { } /** - * Instantiates a {@link SessionParams} that can be given to a {@link com.yahoo.vespa.http.client.SessionFactory}. + * Instantiates a {@link SessionParams} that can be given to a {@link com.yahoo.vespa.http.client.FeedClientFactory}. * * @return a SessionParams object with the parameters of this Builder */ @@ -133,6 +132,7 @@ public final class SessionParams { return throttlerMinSize; } } + private final List<Cluster> clusters; private final FeedParams feedParams; private final ConnectionParams connectionParams; diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/api/SessionImpl.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/api/SessionImpl.java index c3b5d9912de..e11903d7ba7 100644 --- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/api/SessionImpl.java +++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/api/SessionImpl.java @@ -16,7 +16,10 @@ import java.util.concurrent.ScheduledThreadPoolExecutor; /** * This class wires up the Session API using MultiClusterHandler and MultiClusterSessionOutputStream. + * + * @deprecated */ +@Deprecated // TODO: Remove on Vespa 8 public class SessionImpl implements Session { private final OperationProcessor operationProcessor; diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java index f9357ab16d8..5289a7a562a 100644 --- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java +++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java @@ -361,12 +361,12 @@ class ApacheGatewayConnection implements GatewayConnection { @Override public void handshake() throws ServerResponseException, IOException { - final boolean useCompression = false; - final boolean drain = false; - final boolean handshake = true; + boolean useCompression = false; + boolean drain = false; + boolean handshake = true; HttpPost httpPost = createPost(drain, useCompression, handshake); - final String oldSessionID = sessionId; + String oldSessionID = sessionId; sessionId = null; try (InputStream stream = executePost(httpPost)) { if (oldSessionID != null && !oldSessionID.equals(sessionId)) { diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/package-info.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/package-info.java index b14c2ffa4cc..c54c19a2eb1 100644 --- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/package-info.java +++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/package-info.java @@ -1,10 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. /** * Programmatic API for feeding to Vespa clusters independently of the - * cluster configuration. {@link com.yahoo.vespa.http.client.Session} - * is the central interface which is used to interact with a cluster. - * Use {@link com.yahoo.vespa.http.client.SessionFactory} to - * instantiate a {@link com.yahoo.vespa.http.client.Session}. + * cluster configuration. * * NOTE: This is a PUBLIC API, but not annotated as such because this is not a bundle and * we don't want to introduce Vespa dependencies. diff --git a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/FeedClientTest.java b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/FeedClientTest.java index 33afc759f59..88deaa07e12 100644 --- a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/FeedClientTest.java +++ b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/FeedClientTest.java @@ -34,13 +34,14 @@ public class FeedClientTest { .build()) .build(); final AtomicInteger resultsReceived = new AtomicInteger(0); + FeedClient.ResultCallback resultCallback = (docId, documentResult) -> { assertTrue(documentResult.isSuccess()); assertEquals(DOCID, docId); resultsReceived.incrementAndGet(); }; - FeedClient feedClient = new FeedClientImpl(sessionParams, resultCallback, SessionFactory.createTimeoutExecutor()); + FeedClient feedClient = new FeedClientImpl(sessionParams, resultCallback, FeedClientFactory.createTimeoutExecutor()); @Test public void testStreamAndClose() { diff --git a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/QueueBoundsTest.java b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/QueueBoundsTest.java index 357296eb789..344f8b46639 100644 --- a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/QueueBoundsTest.java +++ b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/QueueBoundsTest.java @@ -33,6 +33,7 @@ import static org.junit.Assert.fail; * * @author Einar M R Rosenvinge */ +@SuppressWarnings("deprecation") public class QueueBoundsTest extends TestOnCiBuildingSystemOnly { public static final List<TestDocument> documents; diff --git a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/TestUtils.java b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/TestUtils.java index 8827c863024..b44385e11ff 100644 --- a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/TestUtils.java +++ b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/TestUtils.java @@ -13,10 +13,11 @@ import java.util.zip.GZIPInputStream; import static org.junit.Assert.assertNull; /** - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> - * @since 5.1.20 + * @author Einar M R Rosenvinge */ +@SuppressWarnings("deprecation") public class TestUtils { + public static void writeDocuments(Session session, List<TestDocument> documents) throws IOException { for (TestDocument document : documents) { writeDocument(session, document); @@ -57,4 +58,5 @@ public class TestUtils { } return rawContent.toString(); } + } diff --git a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/V3HttpAPIMultiClusterTest.java b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/V3HttpAPIMultiClusterTest.java index 88f5496d929..8c4b24f74c2 100644 --- a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/V3HttpAPIMultiClusterTest.java +++ b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/V3HttpAPIMultiClusterTest.java @@ -23,9 +23,10 @@ import static org.junit.Assert.fail; /** * Only runs on screwdriver to save time! - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> - * @since 5.1.27 + * + * @author Einar M R Rosenvinge */ +@SuppressWarnings("deprecation") public class V3HttpAPIMultiClusterTest extends TestOnCiBuildingSystemOnly { private void writeDocuments(Session session) throws IOException { diff --git a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/V3HttpAPITest.java b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/V3HttpAPITest.java index 594a49e7d91..ad54bbc6a90 100644 --- a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/V3HttpAPITest.java +++ b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/V3HttpAPITest.java @@ -28,6 +28,7 @@ import static org.junit.Assert.assertThat; * * @author Einar M R Rosenvinge */ +@SuppressWarnings("deprecation") public class V3HttpAPITest extends TestOnCiBuildingSystemOnly { public static final List<TestDocument> documents; |