lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ans...@apache.org
Subject lucene-solr:master: SOLR-11004: Consolidate SolrClient builder code into an abstract base class to reduce duplication.
Date Wed, 05 Jul 2017 18:47:54 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/master 6e36ad7c5 -> 30e9b51af


SOLR-11004: Consolidate SolrClient builder code into an abstract base class to reduce duplication.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/30e9b51a
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/30e9b51a
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/30e9b51a

Branch: refs/heads/master
Commit: 30e9b51af71161d2e775ec438e0d14295537cf34
Parents: 6e36ad7
Author: Anshum Gupta <anshumg@apple.com>
Authored: Wed Jul 5 11:46:22 2017 -0700
Committer: Anshum Gupta <anshumg@apple.com>
Committed: Wed Jul 5 11:47:01 2017 -0700

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  3 +
 .../solr/client/solrj/impl/CloudSolrClient.java | 43 ++----------
 .../solrj/impl/ConcurrentUpdateSolrClient.java  | 43 ++----------
 .../solr/client/solrj/impl/HttpSolrClient.java  | 51 ++------------
 .../client/solrj/impl/LBHttpSolrClient.java     | 52 ++------------
 .../client/solrj/impl/SolrClientBuilder.java    | 72 ++++++++++++++++++++
 6 files changed, 99 insertions(+), 165 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/30e9b51a/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 8d90b02..296f470 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -449,6 +449,9 @@ Other Changes
 * SOLR-10456: Deprecate timeout related setters from SolrClients, and replace with Builder
based implementation
   (Jason Gerlowski, Anshum Gupta)
 
+* SOLR-11004: Consolidate SolrClient builder code in an abstract base class (Jason Gerlowski,
+  Anshum Gupta)
+
 ==================  6.7.0 ==================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/30e9b51a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
index e660fd5..9948857 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
@@ -1367,18 +1367,15 @@ public class CloudSolrClient extends SolrClient {
   /**
    * Constructs {@link CloudSolrClient} instances from provided configuration.
    */
-  public static class Builder {
+  public static class Builder extends SolrClientBuilder<Builder> {
     protected Collection<String> zkHosts;
     protected List<String> solrUrls;
-    protected HttpClient httpClient;
     protected String zkChroot;
     protected LBHttpSolrClient loadBalancedSolrClient;
     protected LBHttpSolrClient.Builder lbClientBuilder;
     protected boolean shardLeadersOnly;
     protected boolean directUpdatesToLeadersOnly;
     protected ClusterStateProvider stateProvider;
-    protected Integer connectionTimeoutMillis;
-    protected Integer socketTimeoutMillis;
 
 
     public Builder() {
@@ -1437,15 +1434,6 @@ public class CloudSolrClient extends SolrClient {
     }
 
     /**
-     * Provides a {@link HttpClient} for the builder to use when creating clients.
-     */
-    public Builder withHttpClient(HttpClient httpClient) {
-      this.httpClient = httpClient;
-      return this;
-    }
-
-
-    /**
      * Provide a series of ZooKeeper client endpoints for the builder to use when creating
clients.
      * 
      * Method may be called multiple times.  All provided values will be used.
@@ -1516,30 +1504,6 @@ public class CloudSolrClient extends SolrClient {
     }
     
     /**
-     * Tells {@link Builder} that created clients should obey the following timeout when
connecting to Solr servers.
-     */
-    public Builder withConnectionTimeout(int connectionTimeoutMillis) {
-      if (connectionTimeoutMillis <= 0) {
-        throw new IllegalArgumentException("connectionTimeoutMillis must be a positive integer.");
-      }
-      
-      this.connectionTimeoutMillis = connectionTimeoutMillis;
-      return this;
-    }
-    
-    /**
-     * Tells {@link Builder} that created clients should set the following read timeout on
all sockets.
-     */
-    public Builder withSocketTimeout(int socketTimeoutMillis) {
-      if (socketTimeoutMillis <= 0) {
-        throw new IllegalArgumentException("socketTimeoutMillis must be a positive integer.");
-      }
-      
-      this.socketTimeoutMillis = socketTimeoutMillis;
-      return this;
-    }
-
-    /**
      * Create a {@link CloudSolrClient} based on the provided configuration.
      */
     public CloudSolrClient build() {
@@ -1560,5 +1524,10 @@ public class CloudSolrClient extends SolrClient {
       }
       return new CloudSolrClient(this);
     }
+
+    @Override
+    public Builder getThis() {
+      return this;
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/30e9b51a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
index 2d9bfb1..f14d953 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
@@ -770,15 +770,12 @@ public class ConcurrentUpdateSolrClient extends SolrClient {
   /**
    * Constructs {@link ConcurrentUpdateSolrClient} instances from provided configuration.
    */
-  public static class Builder {
+  public static class Builder extends SolrClientBuilder<Builder> {
     protected String baseSolrUrl;
-    protected HttpClient httpClient;
     protected int queueSize;
     protected int threadCount;
     protected ExecutorService executorService;
     protected boolean streamDeletes;
-    protected Integer connectionTimeoutMillis;
-    protected Integer socketTimeoutMillis;
 
     /**
      * Create a Builder object, based on the provided Solr URL.
@@ -804,14 +801,6 @@ public class ConcurrentUpdateSolrClient extends SolrClient {
     public Builder(String baseSolrUrl) {
       this.baseSolrUrl = baseSolrUrl;
     }
-
-    /**
-     * Provides a {@link HttpClient} for the builder to use when creating clients.
-     */
-    public Builder withHttpClient(HttpClient httpClient) {
-      this.httpClient = httpClient;
-      return this;
-    }
     
     /**
      * The number of documents to batch together before sending to Solr.
@@ -861,31 +850,6 @@ public class ConcurrentUpdateSolrClient extends SolrClient {
     }
     
     /**
-     * Tells {@link Builder} that created clients should obey the following timeout when
connecting to Solr servers.
-     */
-    public Builder withConnectionTimeout(int connectionTimeoutMillis) {
-      if (connectionTimeoutMillis <= 0) {
-        throw new IllegalArgumentException("connectionTimeoutMillis must be a positive integer.");
-      }
-      
-      this.connectionTimeoutMillis = connectionTimeoutMillis;
-      return this;
-    }
-    
-    /**
-     * Tells {@link Builder} that created clients should set the following read timeout on
all sockets.
-     */
-    public Builder withSocketTimeout(int socketTimeoutMillis) {
-      if (socketTimeoutMillis <= 0) {
-        throw new IllegalArgumentException("socketTimeoutMillis must be a positive integer.");
-      }
-      
-      this.socketTimeoutMillis = socketTimeoutMillis;
-      return this;
-    }
-
-    
-    /**
      * Create a {@link ConcurrentUpdateSolrClient} based on the provided configuration options.
      */
     public ConcurrentUpdateSolrClient build() {
@@ -895,5 +859,10 @@ public class ConcurrentUpdateSolrClient extends SolrClient {
       
       return new ConcurrentUpdateSolrClient(this);
     }
+
+    @Override
+    public Builder getThis() {
+      return this;
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/30e9b51a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java
index 1b0354f..7566ba0 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java
@@ -827,14 +827,10 @@ s   * @deprecated since 7.0  Use {@link Builder} methods instead.
   /**
    * Constructs {@link HttpSolrClient} instances from provided configuration.
    */
-  public static class Builder {
+  public static class Builder extends SolrClientBuilder<Builder> {
     protected String baseSolrUrl;
-    protected HttpClient httpClient;
-    protected ResponseParser responseParser;
     protected boolean compression;
     protected ModifiableSolrParams invariantParams = new ModifiableSolrParams();
-    protected Integer connectionTimeoutMillis;
-    protected Integer socketTimeoutMillis;
 
     public Builder() {
       this.responseParser = new BinaryResponseParser();
@@ -895,22 +891,6 @@ s   * @deprecated since 7.0  Use {@link Builder} methods instead.
     }
 
     /**
-     * Provides a {@link HttpClient} for the builder to use when creating clients.
-     */
-    public Builder withHttpClient(HttpClient httpClient) {
-      this.httpClient = httpClient;
-      return this;
-    }
-
-    /**
-     * Provides a {@link ResponseParser} for created clients to use when handling requests.
-     */
-    public Builder withResponseParser(ResponseParser responseParser) {
-      this.responseParser = responseParser;
-      return this;
-    }
-
-    /**
      * Chooses whether created {@link HttpSolrClient}s use compression by default.
      */
     public Builder allowCompression(boolean compression) {
@@ -941,30 +921,6 @@ s   * @deprecated since 7.0  Use {@link Builder} methods instead.
       this.invariantParams.add(params);
       return this;
     }
-    
-    /**
-     * Tells {@link Builder} that created clients should obey the following timeout when
connecting to Solr servers.
-     */
-    public Builder withConnectionTimeout(int connectionTimeoutMillis) {
-      if (connectionTimeoutMillis <= 0) {
-        throw new IllegalArgumentException("connectionTimeoutMillis must be a positive integer.");
-      }
-      
-      this.connectionTimeoutMillis = connectionTimeoutMillis;
-      return this;
-    }
-    
-    /**
-     * Tells {@link Builder} that created clients should set the following read timeout on
all sockets.
-     */
-    public Builder withSocketTimeout(int socketTimeoutMillis) {
-      if (socketTimeoutMillis <= 0) {
-        throw new IllegalArgumentException("socketTimeoutMillis must be a positive integer.");
-      }
-      
-      this.socketTimeoutMillis = socketTimeoutMillis;
-      return this;
-    }
 
     /**
      * Create a {@link HttpSolrClient} based on provided configuration.
@@ -980,5 +936,10 @@ s   * @deprecated since 7.0  Use {@link Builder} methods instead.
         return new DelegationTokenHttpSolrClient(this);
       }
     }
+
+    @Override
+    public Builder getThis() {
+      return this;
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/30e9b51a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java
index 2dfd4b4..6c2737d 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java
@@ -881,13 +881,9 @@ public class LBHttpSolrClient extends SolrClient {
   /**
    * Constructs {@link LBHttpSolrClient} instances from provided configuration.
    */
-  public static class Builder {
+  public static class Builder extends SolrClientBuilder<Builder> {
     protected final List<String> baseSolrUrls;
-    protected HttpClient httpClient;
-    protected ResponseParser responseParser;
     protected HttpSolrClient.Builder httpSolrClientBuilder;
-    protected Integer connectionTimeoutMillis;
-    protected Integer socketTimeoutMillis;
 
     public Builder() {
       this.baseSolrUrls = new ArrayList<>();
@@ -955,23 +951,6 @@ public class LBHttpSolrClient extends SolrClient {
       }
       return this;
     }
-    
-    
-    /**
-     * Provides a {@link HttpClient} for the builder to use when creating clients.
-     */
-    public Builder withHttpClient(HttpClient httpClient) {
-      this.httpClient = httpClient;
-      return this;
-    }
-    
-    /**
-     * Provides a {@link ResponseParser} for created clients to use when handling requests.
-     */
-    public Builder withResponseParser(ResponseParser responseParser) {
-      this.responseParser = responseParser;
-      return this;
-    }
 
     /**
      * Provides a {@link HttpSolrClient.Builder} to be used for building the internally used
clients.
@@ -980,30 +959,6 @@ public class LBHttpSolrClient extends SolrClient {
       this.httpSolrClientBuilder = builder;
       return this;
     }
-    
-    /**
-     * Tells {@link Builder} that created clients should obey the following timeout when
connecting to Solr servers.
-     */
-    public Builder withConnectionTimeout(int connectionTimeoutMillis) {
-      if (connectionTimeoutMillis <= 0) {
-        throw new IllegalArgumentException("connectionTimeoutMillis must be a positive integer.");
-      }
-      
-      this.connectionTimeoutMillis = connectionTimeoutMillis;
-      return this;
-    }
-    
-    /**
-     * Tells {@link Builder} that created clients should set the following read timeout on
all sockets.
-     */
-    public Builder withSocketTimeout(int socketTimeoutMillis) {
-      if (socketTimeoutMillis <= 0) {
-        throw new IllegalArgumentException("socketTimeoutMillis must be a positive integer.");
-      }
-      
-      this.socketTimeoutMillis = socketTimeoutMillis;
-      return this;
-    }
 
     /**
      * Create a {@link HttpSolrClient} based on provided configuration.
@@ -1011,5 +966,10 @@ public class LBHttpSolrClient extends SolrClient {
     public LBHttpSolrClient build() {
       return new LBHttpSolrClient(this);
     }
+
+    @Override
+    public Builder getThis() {
+      return this;
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/30e9b51a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientBuilder.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientBuilder.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientBuilder.java
new file mode 100644
index 0000000..ec149bd
--- /dev/null
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientBuilder.java
@@ -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.
+ */
+package org.apache.solr.client.solrj.impl;
+
+import org.apache.http.client.HttpClient;
+import org.apache.solr.client.solrj.ResponseParser;
+import org.apache.solr.client.solrj.impl.HttpSolrClient.Builder;
+
+public abstract class SolrClientBuilder<B extends SolrClientBuilder<B>> {
+
+  protected HttpClient httpClient;
+  protected ResponseParser responseParser;
+  protected Integer connectionTimeoutMillis;
+  protected Integer socketTimeoutMillis;
+
+  /** The solution for the unchecked cast warning. */
+  public abstract B getThis();
+  
+  /**
+   * Provides a {@link HttpClient} for the builder to use when creating clients.
+   */
+  public B withHttpClient(HttpClient httpClient) {
+    this.httpClient = httpClient;
+    return getThis();
+  }
+  
+  /**
+   * Provides a {@link ResponseParser} for created clients to use when handling requests.
+   */
+  public B withResponseParser(ResponseParser responseParser) {
+    this.responseParser = responseParser;
+    return getThis();
+  }
+  
+  /**
+   * Tells {@link Builder} that created clients should obey the following timeout when connecting
to Solr servers.
+   */
+  public B withConnectionTimeout(int connectionTimeoutMillis) {
+    if (connectionTimeoutMillis <= 0) {
+      throw new IllegalArgumentException("connectionTimeoutMillis must be a positive integer.");
+    }
+    
+    this.connectionTimeoutMillis = connectionTimeoutMillis;
+    return getThis();
+  }
+  
+  /**
+   * Tells {@link Builder} that created clients should set the following read timeout on
all sockets.
+   */
+  public B withSocketTimeout(int socketTimeoutMillis) {
+    if (socketTimeoutMillis <= 0) {
+      throw new IllegalArgumentException("socketTimeoutMillis must be a positive integer.");
+    }
+    
+    this.socketTimeoutMillis = socketTimeoutMillis;
+    return getThis();
+  }
+}


Mime
View raw message