1 package com.vesoft.nebula.client.graph.net;
3 import com.vesoft.nebula.client.graph.NebulaPoolConfig;
4 import com.vesoft.nebula.client.graph.data.HostAddress;
5 import com.vesoft.nebula.client.graph.exception.ClientServerIncompatibleException;
6 import com.vesoft.nebula.client.graph.exception.IOErrorException;
7 import java.io.Serializable;
8 import org.apache.commons.pool2.BasePooledObjectFactory;
9 import org.apache.commons.pool2.PooledObject;
10 import org.apache.commons.pool2.impl.DefaultPooledObject;
13 implements Serializable {
15 private static final long serialVersionUID = 6101157301791971560L;
19 private static final int retryTime = 3;
22 this.loadBalancer = loadBalancer;
29 if (address ==
null) {
31 "All servers are broken.");
33 int retry = retryTime;
37 if (config.isEnableSsl()) {
38 if (config.getSslParam() ==
null) {
39 throw new IllegalArgumentException(
"SSL Param is required when enableSsl "
42 conn.open(address, config.getTimeout(),
43 config.getSslParam(), config.isUseHttp2(), config.getCustomHeaders());
45 conn.open(address, config.getTimeout(),
46 config.isUseHttp2(), config.getCustomHeaders());
53 this.loadBalancer.updateServersStatus();
60 public PooledObject<SyncConnection> wrap(
SyncConnection connection) {
61 return new DefaultPooledObject<>(connection);
65 public void destroyObject(PooledObject<SyncConnection> p)
throws Exception {
66 p.getObject().close();
68 super.destroyObject(p);
72 public boolean validateObject(PooledObject<SyncConnection> p) {
73 if (p.getObject() ==
null) {
76 if (!p.getObject().ping()) {
77 p.getObject().close();
84 public void activateObject(PooledObject<SyncConnection> p)
throws Exception {
85 if (p.getObject() ==
null) {
86 throw new RuntimeException(
"The connection is null.");
88 if (!p.getObject().ping()) {
89 throw new RuntimeException(
"The connection is broken.");
91 super.activateObject(p);
94 public boolean init() {
95 return loadBalancer.isServersOK();
98 public void updateServerStatus() {
99 loadBalancer.updateServersStatus();