Github user parthchandra commented on a diff in the pull request: https://github.com/apache/drill/pull/480#discussion_r65997722 --- 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. + * <code> + * DrillClient client = DrillClient.newBuilder() + * .setConfig(...) + * .setIsDirectConnection(true) + * .build(); + * </code> + * + * 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 -- Hmm, I take that back, on reflection. Some apps might be using this class. Probably good idea to log a JIRA to remove these. in future.
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. ---