Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 5DA58200B17 for ; Tue, 7 Jun 2016 03:27:57 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 5C07B160A55; Tue, 7 Jun 2016 01:27:57 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 7DB7D160A24 for ; Tue, 7 Jun 2016 03:27:56 +0200 (CEST) Received: (qmail 42975 invoked by uid 500); 7 Jun 2016 01:27:55 -0000 Mailing-List: contact dev-help@drill.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@drill.apache.org Delivered-To: mailing list dev@drill.apache.org Received: (qmail 42964 invoked by uid 99); 7 Jun 2016 01:27:55 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Jun 2016 01:27:55 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id F154BE03B9; Tue, 7 Jun 2016 01:27:54 +0000 (UTC) From: parthchandra To: dev@drill.apache.org Reply-To: dev@drill.apache.org References: In-Reply-To: Subject: [GitHub] drill pull request #480: DRILL-4606: Add DrillClient.Builder class Content-Type: text/plain Message-Id: <20160607012754.F154BE03B9@git1-us-west.apache.org> Date: Tue, 7 Jun 2016 01:27:54 +0000 (UTC) archived-at: Tue, 07 Jun 2016 01:27:57 -0000 Github user parthchandra commented on a diff in the pull request: https://github.com/apache/drill/pull/480#discussion_r65997533 --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/client/DrillClient.java --- @@ -74,81 +78,173 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; -import com.google.common.base.Strings; -import com.google.common.util.concurrent.AbstractCheckedFuture; -import com.google.common.util.concurrent.SettableFuture; /** * Thin wrapper around a UserClient that handles connect/close and transforms * String into ByteBuf. + * + * To create non-default objects, use {@link DrillClient.Builder the builder class}. + * E.g. + * + * DrillClient client = DrillClient.newBuilder() + * .setConfig(...) + * .setIsDirectConnection(true) + * .build(); + * + * + * Except for {@link #runQuery} and {@link #cancelQuery}, this class is generally not thread safe. */ public class DrillClient implements Closeable, ConnectionThrottle { private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillClient.class); private static final ObjectMapper objectMapper = new ObjectMapper(); private final DrillConfig config; - private UserClient client; - private UserProperties props = null; - private volatile ClusterCoordinator clusterCoordinator; - private volatile boolean connected = false; private final BufferAllocator allocator; - private int reconnectTimes; - private int reconnectDelay; - private boolean supportComplexTypes; - private final boolean ownsZkConnection; + private final EventLoopGroup eventLoopGroup; + private final ExecutorService executor; + private final boolean isDirectConnection; + private final int reconnectTimes; + private final int reconnectDelay; + + // TODO: clusterCoordinator should be initialized in the constructor. + // Currently, initialization is tightly coupled with #connect. + private ClusterCoordinator clusterCoordinator; + + // checks if this client owns these resources (used when closing) private final boolean ownsAllocator; - private final boolean isDirectConnection; // true if the connection bypasses zookeeper and connects directly to a drillbit - private EventLoopGroup eventLoopGroup; - private ExecutorService executor; + private final boolean ownsZkConnection; + private final boolean ownsEventLoopGroup; + private final boolean ownsExecutor; - public DrillClient() throws OutOfMemoryException { - this(DrillConfig.create(), false); + // once #setSupportComplexTypes() is removed, make this final + private boolean supportComplexTypes; + + private UserClient client; + private UserProperties props; + private boolean connected; + + public DrillClient() { + this(newBuilder()); } - public DrillClient(boolean isDirect) throws OutOfMemoryException { - this(DrillConfig.create(), isDirect); + /** + * @deprecated Create a DrillClient using {@link DrillClient.Builder}. + */ + @Deprecated + public DrillClient(boolean isDirect) { + this(newBuilder() + .setDirectConnection(isDirect)); } - public DrillClient(String fileName) throws OutOfMemoryException { - this(DrillConfig.create(fileName), false); + /** + * @deprecated Create a DrillClient using {@link DrillClient.Builder}. + */ + @Deprecated + public DrillClient(String fileName) { + this(newBuilder() + .setConfigFromFile(fileName)); } - public DrillClient(DrillConfig config) throws OutOfMemoryException { - this(config, null, false); + /** + * @deprecated Create a DrillClient using {@link DrillClient.Builder}. + */ + @Deprecated + public DrillClient(DrillConfig config) { + this(newBuilder() + .setConfig(config)); } - public DrillClient(DrillConfig config, boolean isDirect) - throws OutOfMemoryException { - this(config, null, isDirect); + /** + * @deprecated Create a DrillClient using {@link DrillClient.Builder}. + */ + @Deprecated + public DrillClient(DrillConfig config, boolean isDirect) { + this(newBuilder() + .setConfig(config) + .setDirectConnection(isDirect)); } - public DrillClient(DrillConfig config, ClusterCoordinator coordinator) - throws OutOfMemoryException { - this(config, coordinator, null, false); + /** + * @deprecated Create a DrillClient using {@link DrillClient.Builder}. + */ + @Deprecated + public DrillClient(DrillConfig config, ClusterCoordinator coordinator) { + this(newBuilder() + .setConfig(config) + .setClusterCoordinator(coordinator)); } - public DrillClient(DrillConfig config, ClusterCoordinator coordinator, boolean isDirect) - throws OutOfMemoryException { - this(config, coordinator, null, isDirect); + /** + * @deprecated Create a DrillClient using {@link DrillClient.Builder}. + */ + @Deprecated + public DrillClient(DrillConfig config, ClusterCoordinator coordinator, boolean isDirect) { + this(newBuilder() + .setConfig(config) + .setClusterCoordinator(coordinator) + .setDirectConnection(isDirect)); } - public DrillClient(DrillConfig config, ClusterCoordinator coordinator, BufferAllocator allocator) - throws OutOfMemoryException { - this(config, coordinator, allocator, false); + /** + * @deprecated Create a DrillClient using {@link DrillClient.Builder}. + */ + @Deprecated + public DrillClient(DrillConfig config, ClusterCoordinator coordinator, BufferAllocator allocator) { + this(newBuilder() + .setConfig(config) + .setClusterCoordinator(coordinator) + .setAllocator(allocator)); + } + + /** + * @deprecated Create a DrillClient using {@link DrillClient.Builder}. + */ + @Deprecated --- End diff -- Usually, this is a good thing, deprecating a method you intend to remove. But in this case the number of ctors is getting too messy. Should we just remove them altogether? --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---