A client that uses the PostgreSQL wire protocol to initiate a connection, but then switches over to use the transport protocol
| 86 | * but then switches over to use the transport protocol |
| 87 | **/ |
| 88 | public class PgClient implements Client { |
| 89 | |
| 90 | private static final Logger LOGGER = LogManager.getLogger(PgClient.class); |
| 91 | |
| 92 | final String name; |
| 93 | final NettyBootstrap nettyBootstrap; |
| 94 | final Netty4Transport transport; |
| 95 | final PageCacheRecycler pageCacheRecycler; |
| 96 | final DiscoveryNode host; |
| 97 | final TransportService transportService; |
| 98 | final AtomicBoolean isClosing = new AtomicBoolean(false); |
| 99 | final ConnectionInfo connectionInfo; |
| 100 | final ConnectionProfile profile; |
| 101 | final SslContextProvider sslContextProvider; |
| 102 | final Settings settings; |
| 103 | |
| 104 | private CompletableFuture<Transport.Connection> connectionFuture; |
| 105 | |
| 106 | |
| 107 | public PgClient(String name, |
| 108 | Settings nodeSettings, |
| 109 | TransportService transportService, |
| 110 | NettyBootstrap nettyBootstrap, |
| 111 | Netty4Transport transport, |
| 112 | SslContextProvider sslContextProvider, |
| 113 | PageCacheRecycler pageCacheRecycler, |
| 114 | ConnectionInfo connectionInfo) { |
| 115 | this.name = name; |
| 116 | this.settings = nodeSettings; |
| 117 | this.transportService = transportService; |
| 118 | this.nettyBootstrap = nettyBootstrap; |
| 119 | this.transport = transport; |
| 120 | this.sslContextProvider = sslContextProvider; |
| 121 | this.pageCacheRecycler = pageCacheRecycler; |
| 122 | this.host = toDiscoveryNode(connectionInfo.hosts()); |
| 123 | this.connectionInfo = connectionInfo; |
| 124 | this.profile = new ConnectionProfile.Builder() |
| 125 | .setConnectTimeout(TransportSettings.CONNECT_TIMEOUT.get(nodeSettings)) |
| 126 | .setHandshakeTimeout(TransportSettings.CONNECT_TIMEOUT.get(nodeSettings)) |
| 127 | .setPingInterval(TransportSettings.PING_SCHEDULE.get(nodeSettings)) |
| 128 | .setCompressionEnabled(TransportSettings.TRANSPORT_COMPRESS.get(nodeSettings)) |
| 129 | .addConnections(1, TransportRequestOptions.Type.BULK) |
| 130 | .addConnections(1, TransportRequestOptions.Type.PING) |
| 131 | .addConnections(1, TransportRequestOptions.Type.STATE) |
| 132 | .addConnections(1, TransportRequestOptions.Type.RECOVERY) |
| 133 | .addConnections(1, TransportRequestOptions.Type.REG) |
| 134 | .build(); |
| 135 | } |
| 136 | |
| 137 | Settings settings() { |
| 138 | return settings; |
| 139 | } |
| 140 | |
| 141 | private DiscoveryNode toDiscoveryNode(List<String> hosts) { |
| 142 | if (hosts.isEmpty()) { |
| 143 | throw new IllegalArgumentException("No hosts configured for pg tunnel " + name); |
| 144 | } |
| 145 | String host = hosts.get(0); |