NebulaGraph Java Client  release-3.6
All Classes Functions Variables
SessionPoolConfig.java
1 /* Copyright (c) 2022 vesoft inc. All rights reserved.
2  *
3  * This source code is licensed under Apache 2.0 License.
4  */
5 
6 package com.vesoft.nebula.client.graph;
7 
8 import com.vesoft.nebula.client.graph.data.HostAddress;
9 import com.vesoft.nebula.client.graph.data.SSLParam;
10 import java.io.Serializable;
11 import java.util.HashMap;
12 import java.util.List;
13 import java.util.Map;
14 
15 public class SessionPoolConfig implements Serializable {
16 
17  private static final long serialVersionUID = -2266013330384849132L;
18 
19  private final List<HostAddress> graphAddressList;
20 
21  private final String username;
22  private final String password;
23  private final String spaceName;
24 
25  // The min connections in pool for all addresses
26  private int minSessionSize = 1;
27 
28  // The max connections in pool for all addresses
29  private int maxSessionSize = 10;
30 
31  // Socket timeout and Socket connection timeout, unit: millisecond
32  private int timeout = 0;
33 
34  // The idleTime for clean the idle session
35  // must be less than NebulaGraph's session_idle_timeout_secs, unit: second
36  private int cleanTime = 3600;
37 
38  // The healthCheckTime for schedule check the health of session, unit: second
39  private int healthCheckTime = 600;
40 
41  // retry times to get session
42  private int retryConnectTimes = 1;
43 
44  // The wait time to get idle connection, unit ms
45  private int waitTime = 0;
46 
47  // retry times for failed execute
48  private int retryTimes = 3;
49 
50  // interval time for retry, unit ms
51  private int intervalTime = 0;
52 
53  // whether reconnect when create session using a broken graphd server
54  private boolean reconnect = false;
55 
56  // Set to true to turn on ssl encrypted traffic
57  private boolean enableSsl = false;
58 
59  // SSL param is required if ssl is turned on
60  private SSLParam sslParam = null;
61 
62  private boolean useHttp2 = false;
63 
64  private Map<String, String> customHeaders = new HashMap<>();
65 
66 
67  public SessionPoolConfig(List<HostAddress> addresses,
68  String spaceName,
69  String username,
70  String password) {
71  if (addresses == null || addresses.size() == 0) {
72  throw new IllegalArgumentException("Graph addresses cannot be empty.");
73  }
74  if (spaceName == null || spaceName.trim().isEmpty()) {
75  throw new IllegalArgumentException("space name cannot be blank.");
76  }
77  if (username == null || username.trim().isEmpty()) {
78  throw new IllegalArgumentException("user name cannot be blank.");
79  }
80  if (password == null || password.trim().isEmpty()) {
81  throw new IllegalArgumentException("password cannot be blank.");
82  }
83 
84  this.graphAddressList = addresses;
85  this.spaceName = spaceName;
86  this.username = username;
87  this.password = password;
88  }
89 
90  public String getUsername() {
91  return username;
92  }
93 
94  public String getPassword() {
95  return password;
96  }
97 
98  public List<HostAddress> getGraphAddressList() {
99  return graphAddressList;
100  }
101 
102  public String getSpaceName() {
103  return spaceName;
104  }
105 
106  public int getMinSessionSize() {
107  return minSessionSize;
108  }
109 
110  public SessionPoolConfig setMinSessionSize(int minSessionSize) {
111  if (minSessionSize < 1) {
112  throw new IllegalArgumentException("minSessionSize cannot be less than 1.");
113  }
114  this.minSessionSize = minSessionSize;
115  return this;
116  }
117 
118  public int getMaxSessionSize() {
119  return maxSessionSize;
120  }
121 
122  public SessionPoolConfig setMaxSessionSize(int maxSessionSize) {
123  if (maxSessionSize < 1) {
124  throw new IllegalArgumentException("maxSessionSize cannot be less than 1.");
125  }
126  this.maxSessionSize = maxSessionSize;
127  return this;
128  }
129 
130  public int getTimeout() {
131  return timeout;
132  }
133 
134  public SessionPoolConfig setTimeout(int timeout) {
135  if (timeout < 0) {
136  throw new IllegalArgumentException("timeout cannot be less than 0.");
137  }
138  this.timeout = timeout;
139  return this;
140  }
141 
142  public int getCleanTime() {
143  return cleanTime;
144  }
145 
146  public SessionPoolConfig setCleanTime(int cleanTime) {
147  if (cleanTime < 0) {
148  throw new IllegalArgumentException("cleanTime cannot be less than 0.");
149  }
150  this.cleanTime = cleanTime;
151  return this;
152  }
153 
154  public int getHealthCheckTime() {
155  return healthCheckTime;
156  }
157 
158  public SessionPoolConfig setHealthCheckTime(int healthCheckTime) {
159  if (healthCheckTime < 0) {
160  throw new IllegalArgumentException("cleanTime cannot be less than 0.");
161  }
162  this.healthCheckTime = healthCheckTime;
163  return this;
164  }
165 
166  public int getRetryConnectTimes() {
167  return retryConnectTimes;
168  }
169 
170  public SessionPoolConfig setRetryConnectTimes(int retryConnectTimes) {
171  if (retryConnectTimes < 0) {
172  throw new IllegalArgumentException("retryConnectTimes cannot be less than 0.");
173  }
174  this.retryConnectTimes = retryConnectTimes;
175  return this;
176  }
177 
178  public int getWaitTime() {
179  return waitTime;
180  }
181 
182  public SessionPoolConfig setWaitTime(int waitTime) {
183  if (waitTime < 0) {
184  throw new IllegalArgumentException("waitTime cannot be less than 0.");
185  }
186  this.waitTime = waitTime;
187  return this;
188  }
189 
190  public int getRetryTimes() {
191  return retryTimes;
192  }
193 
194  public SessionPoolConfig setRetryTimes(int retryTimes) {
195  if (retryTimes < 0) {
196  throw new IllegalArgumentException("retryTimes cannot be less than 0.");
197  }
198  this.retryTimes = retryTimes;
199  return this;
200  }
201 
202  public int getIntervalTime() {
203  return intervalTime;
204  }
205 
206  public SessionPoolConfig setIntervalTime(int intervalTime) {
207  if (intervalTime < 0) {
208  throw new IllegalArgumentException("intervalTime cannot be less than 0.");
209  }
210  this.intervalTime = intervalTime;
211  return this;
212  }
213 
214  public boolean isReconnect() {
215  return reconnect;
216  }
217 
218  public SessionPoolConfig setReconnect(boolean reconnect) {
219  this.reconnect = reconnect;
220  return this;
221  }
222 
223  public boolean isEnableSsl() {
224  return enableSsl;
225  }
226 
227  public SessionPoolConfig setEnableSsl(boolean enableSsl) {
228  this.enableSsl = enableSsl;
229  return this;
230  }
231 
232  public SSLParam getSslParam() {
233  return sslParam;
234  }
235 
236  public SessionPoolConfig setSslParam(SSLParam sslParam) {
237  this.sslParam = sslParam;
238  return this;
239  }
240 
241  public boolean isUseHttp2() {
242  return useHttp2;
243  }
244 
245  public SessionPoolConfig setUseHttp2(boolean useHttp2) {
246  this.useHttp2 = useHttp2;
247  return this;
248  }
249 
250  public Map<String, String> getCustomHeaders() {
251  return customHeaders;
252  }
253 
254  public SessionPoolConfig setCustomHeaders(Map<String, String> customHeaders) {
255  this.customHeaders = customHeaders;
256  return this;
257  }
258 
259  @Override
260  public String toString() {
261  return "SessionPoolConfig{"
262  + "username='" + username + '\''
263  + ", graphAddressList=" + graphAddressList
264  + ", spaceName='" + spaceName + '\''
265  + ", minSessionSize=" + minSessionSize
266  + ", maxSessionSize=" + maxSessionSize
267  + ", timeout=" + timeout
268  + ", idleTime=" + cleanTime
269  + ", healthCheckTime=" + healthCheckTime
270  + ", waitTime=" + waitTime
271  + ", retryTimes=" + retryTimes
272  + ", intervalTIme=" + intervalTime
273  + ", reconnect=" + reconnect
274  + ", enableSsl=" + enableSsl
275  + ", sslParam=" + sslParam
276  + ", useHttp2=" + useHttp2
277  + ", customHeaders=" + customHeaders
278  + '}';
279  }
280 }