6 package com.vesoft.nebula.client.storage;
8 import com.vesoft.nebula.client.graph.data.HostAddress;
9 import java.io.Serializable;
10 import org.apache.commons.pool2.KeyedPooledObjectFactory;
11 import org.apache.commons.pool2.PooledObject;
12 import org.apache.commons.pool2.impl.DefaultPooledObject;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
16 @SuppressWarnings(
"checkstyle:Indentation")
28 public PooledObject<GraphStorageConnection> makeObject(
HostAddress address)
throws Exception {
34 config.getSslParam());
35 return new DefaultPooledObject<>(connection);
40 PooledObject<GraphStorageConnection> pooledObject) {
41 pooledObject.getObject().close();
45 public boolean validateObject(
HostAddress hostAndPort,
46 PooledObject<GraphStorageConnection> pooledObject) {
48 if (connection ==
null) {
52 return connection.transport.isOpen();
53 }
catch (Exception e) {
54 LOGGER.warn(String.format(
"storage connection with %s:%d is not open",
55 hostAndPort.getHost(), hostAndPort.getPort()), e);
62 PooledObject<GraphStorageConnection> pooledObject)
64 if (pooledObject.getObject() ==
null) {
65 throw new RuntimeException(
"The connection is null.");
67 if (!pooledObject.getObject().transport.isOpen()) {
68 throw new RuntimeException(
"The connection is broken.");
73 public void passivateObject(
HostAddress hostAndPort,
74 PooledObject<GraphStorageConnection> pooledObject) {
75 pooledObject.markReturning();