Skip to content

Commit

Permalink
Adapt RestClient to support connection reuse
Browse files Browse the repository at this point in the history
Change-Id: I328065488049ec81e507b469104570d8f094f1af
  • Loading branch information
Linary committed Apr 8, 2019
1 parent 33b3724 commit 3da786a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.baidu.hugegraph</groupId>
<artifactId>hugegraph-client</artifactId>
<version>1.6.11</version>
<version>1.6.12</version>
<packaging>jar</packaging>

<name>hugegraph-client</name>
Expand Down Expand Up @@ -53,8 +53,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<compiler.source>1.8</compiler.source>
<compiler.target>1.8</compiler.target>
<hugegraph.common.version>1.5.8</hugegraph.common.version>
<jersey.version>2.25.1</jersey.version>
<hugegraph.common.version>1.5.9</hugegraph.common.version>
<jersey.version>2.22</jersey.version>
<mockito.version>2.8.47</mockito.version>
</properties>

Expand Down Expand Up @@ -113,7 +113,7 @@
<manifestEntries>
<!-- Must be on one line, otherwise the automatic
upgrade script cannot replace the version number -->
<Implementation-Version>1.6.11.0</Implementation-Version>
<Implementation-Version>1.6.12.0</Implementation-Version>
</manifestEntries>
</archive>
</configuration>
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/baidu/hugegraph/client/RestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public RestClient(String url, int timeout) {
super(url, timeout * SECOND);
}

public RestClient(String url, int timeout, int maxTotal, int maxPerRoute) {
super(url, timeout * SECOND, maxTotal, maxPerRoute);
}

public RestClient(String url, String username, String password, int timeout) {
super(url, username, password, timeout * SECOND);
}
Expand Down
24 changes: 18 additions & 6 deletions src/main/java/com/baidu/hugegraph/driver/HugeClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class HugeClient {
ClientVersion.check();
}

private final RestClient client;

private VersionManager version;
private GraphsManager graphs;
private SchemaManager schema;
Expand All @@ -49,14 +51,22 @@ public HugeClient(String url, String graph) {
}

public HugeClient(String url, String graph, int timeout) {
RestClient client = null;
try {
client = new RestClient(url, timeout);
this.client = new RestClient(url, timeout);
} catch (ProcessingException e) {
throw new ServerException("Failed to connect url '%s'", url);
}
this.initManagers(this.client, graph);
}

this.initManagers(client, graph);
public HugeClient(String url, String graph, int timeout,
int maxTotal, int maxPerRoute) {
try {
this.client = new RestClient(url, timeout, maxTotal, maxPerRoute);
} catch (ProcessingException e) {
throw new ServerException("Failed to connect url '%s'", url);
}
this.initManagers(this.client, graph);
}

public HugeClient(String url, String graph,
Expand All @@ -67,14 +77,16 @@ public HugeClient(String url, String graph,
public HugeClient(String url, String graph,
String username, String password,
int timeout) {
RestClient client = null;
try {
client = new RestClient(url, username, password, timeout);
this.client = new RestClient(url, username, password, timeout);
} catch (ProcessingException e) {
throw new ServerException("Failed to connect url '%s'", url);
}
this.initManagers(this.client, graph);
}

this.initManagers(client, graph);
public void close() {
this.client.close();
}

private void initManagers(RestClient client, String graph) {
Expand Down

0 comments on commit 3da786a

Please sign in to comment.