Browse Source

add waitTime option in ConnectParam

Zhiru Zhu 5 years ago
parent
commit
d9d493e768

+ 2 - 2
README.md

@@ -14,13 +14,13 @@ Apache Maven
 <dependency>
     <groupId>io.milvus</groupId>
     <artifactId>milvus-sdk-java</artifactId>
-    <version>0.2.0</version>
+    <version>0.2.1</version>
 </dependency>
 ```
 
 Gradle/Grails 
 
-`compile 'io.milvus:milvus-sdk-java:0.2.0'`
+`compile 'io.milvus:milvus-sdk-java:0.2.1'`
 
 ### Examples
 

+ 15 - 1
examples/pom.xml

@@ -44,11 +44,25 @@
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     </properties>
 
+    <!-- For deploying SNAPSHOT -->
+    <repositories>
+        <repository>
+            <id>oss.sonatype.org-snapshot</id>
+            <url>http://oss.sonatype.org/content/repositories/snapshots</url>
+            <releases>
+                <enabled>false</enabled>
+            </releases>
+            <snapshots>
+                <enabled>true</enabled>
+            </snapshots>
+        </repository>
+    </repositories>
+
     <dependencies>
         <dependency>
             <groupId>io.milvus</groupId>
             <artifactId>milvus-sdk-java</artifactId>
-            <version>0.2.0</version>
+            <version>0.2.1-SNAPSHOT</version>
         </dependency>
     </dependencies>
 

+ 6 - 4
examples/src/main/java/MilvusClientExample.java

@@ -42,7 +42,7 @@ public class MilvusClientExample {
     return vectors;
   }
 
-  // Helper function that normalizes a vector if you are using IP (Inner product) as your metric
+  // Helper function that normalizes a vector if you are using IP (Inner Product) as your metric
   // type
   static List<Float> normalizeVector(List<Float> vector) {
     float squareSum = vector.stream().map(x -> x * x).reduce((float) 0, Float::sum);
@@ -54,14 +54,16 @@ public class MilvusClientExample {
   public static void main(String[] args) throws InterruptedException, ConnectFailedException {
 
     // You may need to change the following to the host and port of your Milvus server
-    final String host = "localhost";
+    final String host = "192.168.1.149";
     final String port = "19530";
 
     // Create Milvus client
     MilvusClient client = new MilvusGrpcClient();
 
     // Connect to Milvus server
-    ConnectParam connectParam = new ConnectParam.Builder().withHost(host).withPort(port).build();
+    final long waitTime = 1000; // Wait 1000 ms for client to establish a connection
+    ConnectParam connectParam =
+        new ConnectParam.Builder().withHost(host).withPort(port).withWaitTime(waitTime).build();
     try {
       Response connectResponse = client.connect(connectParam);
     } catch (ConnectFailedException e) {
@@ -77,7 +79,7 @@ public class MilvusClientExample {
     final String tableName = "example"; // table name
     final long dimension = 128; // dimension of each vector
     final long indexFileSize = 1024; // maximum size (in MB) of each index file
-    final MetricType metricType = MetricType.IP; // we choose IP (Inner project) as our metric type
+    final MetricType metricType = MetricType.IP; // we choose IP (Inner Product) as our metric type
     TableSchema tableSchema =
         new TableSchema.Builder(tableName, dimension)
             .withIndexFileSize(indexFileSize)

+ 1 - 1
pom.xml

@@ -25,7 +25,7 @@
 
     <groupId>io.milvus</groupId>
     <artifactId>milvus-sdk-java</artifactId>
-    <version>0.2.0</version>
+    <version>0.2.1-SNAPSHOT</version>
     <packaging>jar</packaging>
 
     <name>io.milvus:milvus-sdk-java</name>

+ 19 - 0
src/main/java/io/milvus/client/ConnectParam.java

@@ -25,10 +25,12 @@ import javax.annotation.Nonnull;
 public class ConnectParam {
   private final String host;
   private final String port;
+  private final long waitTime;
 
   private ConnectParam(@Nonnull Builder builder) {
     this.host = builder.host;
     this.port = builder.port;
+    this.waitTime = builder.waitTime;
   }
 
   public String getHost() {
@@ -39,6 +41,10 @@ public class ConnectParam {
     return port;
   }
 
+  public long getWaitTime() {
+    return waitTime;
+  }
+
   @Override
   public String toString() {
     return "ConnectParam{" + "host='" + host + '\'' + ", port='" + port + '\'' + '}';
@@ -49,6 +55,7 @@ public class ConnectParam {
     // Optional parameters - initialized to default values
     private String host = "127.0.0.1";
     private String port = "19530";
+    private long waitTime = 500; // ms
 
     /**
      * Optional. Default to "127.0.0.1".
@@ -72,6 +79,18 @@ public class ConnectParam {
       return this;
     }
 
+    /**
+     * Optional. Default to 500 ms
+     *
+     * @param waitTime Wait time (in ms) for channel to establish a connection. BEWARE: this is not
+     *     timeout, so the program will essentially sleep for the entire duration
+     * @return <code>Builder</code>
+     */
+    public Builder withWaitTime(long waitTime) {
+      this.waitTime = waitTime;
+      return this;
+    }
+
     public ConnectParam build() {
       return new ConnectParam(this);
     }

+ 2 - 1
src/main/java/io/milvus/client/MilvusClient.java

@@ -22,7 +22,7 @@ package io.milvus.client;
 /** The Milvus Client Interface */
 public interface MilvusClient {
 
-  String clientVersion = "0.2.0";
+  String clientVersion = "0.2.1";
 
   /** @return the current Milvus client version */
   default String getClientVersion() {
@@ -39,6 +39,7 @@ public interface MilvusClient {
    * ConnectParam connectParam = new ConnectParam.Builder()
    *                                             .withHost("localhost")
    *                                             .withPort("19530")
+   *                                             .withWaitTime(500)
    *                                             .build();
    * </code>
    * </pre>

+ 3 - 2
src/main/java/io/milvus/client/MilvusGrpcClient.java

@@ -70,8 +70,9 @@ public class MilvusGrpcClient implements MilvusClient {
       ConnectivityState connectivityState;
       connectivityState = channel.getState(true);
 
-      logInfo("Waiting to connect...");
-      TimeUnit.MILLISECONDS.sleep(500);
+      logInfo(
+          "Waiting for {0} ms for channel to establish connection...", connectParam.getWaitTime());
+      TimeUnit.MILLISECONDS.sleep(connectParam.getWaitTime());
 
       connectivityState = channel.getState(false);
       if (connectivityState != ConnectivityState.READY) {

+ 1 - 1
src/test/java/io/milvus/client/MilvusGrpcClientTest.java

@@ -52,7 +52,7 @@ class MilvusClientTest {
     return vectors;
   }
 
-  // Helper function that normalizes a vector if you are using IP (Inner product) as your metric
+  // Helper function that normalizes a vector if you are using IP (Inner Product) as your metric
   // type
   static List<Float> normalizeVector(List<Float> vector) {
     float squareSum = vector.stream().map(x -> x * x).reduce((float) 0, Float::sum);