- * Defaults: - *
- * - *- * {@link Protocol#VST} == 1 - * {@link Protocol#HTTP_JSON} == 20 - * {@link Protocol#HTTP_VPACK} == 20 - *- * - * @param maxConnections max number of connections - * @return {@link ArangoDB.Builder} - */ - public Builder maxConnections(final Integer maxConnections) { - setMaxConnections(maxConnections); - return this; - } - - /** - * Set the maximum time to life of a connection. After this time the connection will be closed automatically. - * - * @param connectionTtl the maximum time to life of a connection in milliseconds - * @return {@link ArangoDB.Builder} - */ - public Builder connectionTtl(final Long connectionTtl) { - setConnectionTtl(connectionTtl); - return this; - } - - /** - * Set the keep-alive interval for VST connections. If set, every VST connection will perform a no-op request - * every {@code keepAliveInterval} seconds, to avoid to be closed due to inactivity by the server (or by the - * external environment, eg. firewall, intermediate routers, operating system). - * - * @param keepAliveInterval interval in seconds - * @return {@link ArangoDB.Builder} - */ - public Builder keepAliveInterval(final Integer keepAliveInterval) { - setKeepAliveInterval(keepAliveInterval); - return this; - } - - /** - * Whether or not the driver should acquire a list of available coordinators in an ArangoDB cluster or a single - * server with active failover. In case of Active-Failover deployment set to {@code true} to enable automatic - * master discovery. - * - *
- * The host list will be used for failover and load balancing. - *
- * - * @param acquireHostList whether or not automatically acquire a list of available hosts (default: false) - * @return {@link ArangoDB.Builder} - */ - public Builder acquireHostList(final Boolean acquireHostList) { - setAcquireHostList(acquireHostList); - return this; - } - - /** - * Setting the Interval for acquireHostList - * - * @param acquireHostListInterval Interval in milliseconds - * @return {@link ArangoDB.Builder} - */ - public Builder acquireHostListInterval(final Integer acquireHostListInterval) { - setAcquireHostListInterval(acquireHostListInterval); - return this; - } - - /** - * Sets the load balancing strategy to be used in an ArangoDB cluster setup. In case of Active-Failover - * deployment set to {@link LoadBalancingStrategy#NONE} or not set at all, since that would be the default. - * - * @param loadBalancingStrategy the load balancing strategy to be used (default: - * {@link LoadBalancingStrategy#NONE} - * @return {@link ArangoDB.Builder} - */ - public Builder loadBalancingStrategy(final LoadBalancingStrategy loadBalancingStrategy) { - setLoadBalancingStrategy(loadBalancingStrategy); - return this; - } - - /** - * Setting the amount of samples kept for queue time metrics - * - * @param responseQueueTimeSamples amount of samples to keep - * @return {@link ArangoDB.Builder} - */ - public Builder responseQueueTimeSamples(final Integer responseQueueTimeSamples) { - setResponseQueueTimeSamples(responseQueueTimeSamples); - return this; - } - - /** - * Sets the serde for the user data. - * This is used to serialize and deserialize all the data payload such as: - * - documents, vertexes, edges - * - AQL bind vars - * - body payload of requests and responses in {@link ArangoDB#execute(Request, Class)} - *
- * However, note that the following types will always be serialized and deserialized using the internal serde:
- * - {@link com.fasterxml.jackson.databind.JsonNode}
- * - {@link com.arangodb.util.RawJson}
- * - {@link com.arangodb.util.RawBytes}
- * - {@link com.arangodb.entity.BaseDocument}
- * - {@link com.arangodb.entity.BaseEdgeDocument}
- *
- * @param serde custom serde for the user data
- * @return {@link ArangoDB.Builder}
- */
- public Builder serde(final ArangoSerde serde) {
- setUserDataSerde(serde);
+ config.setProtocol(protocol);
return this;
}
@@ -574,53 +331,25 @@ public Builder serde(final ArangoSerde serde) {
* @return {@link ArangoDB}
*/
public ArangoDB build() {
- if (hosts.isEmpty()) {
+ if (config.getHosts().isEmpty()) {
throw new ArangoDBException("No host has been set!");
}
- final ArangoSerde userSerde = this.userDataSerde != null ? this.userDataSerde :
- serdeProvider().of(ContentTypeFactory.of(protocol));
- final InternalSerde serde = InternalSerdeProvider.create(ContentTypeFactory.of(protocol), userSerde);
-
- int protocolMaxConnections;
- switch (protocol) {
- case VST:
- protocolMaxConnections = ArangoDefaults.MAX_CONNECTIONS_VST_DEFAULT;
- break;
- case HTTP_JSON:
- case HTTP_VPACK:
- protocolMaxConnections = ArangoDefaults.MAX_CONNECTIONS_HTTP_DEFAULT;
- break;
- case HTTP2_JSON:
- case HTTP2_VPACK:
- protocolMaxConnections = ArangoDefaults.MAX_CONNECTIONS_HTTP2_DEFAULT;
- break;
- default:
- throw new IllegalArgumentException();
- }
-
- final int max = maxConnections != null ? Math.max(1, maxConnections) : protocolMaxConnections;
-
- final ConnectionFactory connectionFactory = Protocol.VST == protocol
- ? new VstConnectionFactorySync(timeout, connectionTtl, keepAliveInterval, useSsl, sslContext)
- : new HttpConnectionFactory(timeout, user, password, useSsl, sslContext, verifyHost, serde,
- protocol, connectionTtl);
+ ProtocolProvider protocolProvider = protocolProvider(config.getProtocol());
+ config.setProtocolModule(protocolProvider.protocolModule());
- final Collection
- * In an ArangoDB cluster setup with {@link LoadBalancingStrategy#ROUND_ROBIN} set, this value should be at
- * least as high as the number of ArangoDB coordinators in the cluster.
- *
- * The host list will be used for failover and load balancing.
- *
- *
+ * Defaults:
+ *
+ * The host list will be used for failover and load balancing.
+ *
+ * However, note that the following types will always be serialized and deserialized using the internal serde:
+ * - {@link com.fasterxml.jackson.databind.JsonNode}
+ * - {@link com.arangodb.util.RawJson}
+ * - {@link com.arangodb.util.RawBytes}
+ * - {@link com.arangodb.entity.BaseDocument}
+ * - {@link com.arangodb.entity.BaseEdgeDocument}
+ *
+ * @param serde custom serde for the user data
+ * @return {@link ArangoDB.Builder}
+ */
+ @SuppressWarnings("unchecked")
+ public T serde(final ArangoSerde serde) {
+ config.setUserDataSerde(serde);
+ return (T) this;
+ }
+
+ protected ProtocolProvider protocolProvider(Protocol protocol) {
+ ServiceLoaderroot
)
- * @return {@link ArangoDBAsync.Builder}
- */
- public Builder user(final String user) {
- setUser(user);
- return this;
- }
-
- /**
- * Sets the password for the user for authentication.
- *
- * @param password the password of the user in the database (default: null
)
- * @return {@link ArangoDBAsync.Builder}
- */
- public Builder password(final String password) {
- setPassword(password);
- return this;
- }
-
- /**
- * Sets the JWT for the user authentication.
- *
- * @param jwt token to use (default: {@code null})
- * @return {@link ArangoDBAsync.Builder}
- */
- public Builder jwt(final String jwt) {
- setJwt(jwt);
- return this;
- }
-
- /**
- * If set to true
SSL will be used when connecting to an ArangoDB server.
- *
- * @param useSsl whether or not use SSL (default: false
)
- * @return {@link ArangoDBAsync.Builder}
- */
- public Builder useSsl(final Boolean useSsl) {
- setUseSsl(useSsl);
- return this;
- }
-
- /**
- * Sets the SSL context to be used when true
is passed through {@link #useSsl(Boolean)}.
- *
- * @param sslContext SSL context to be used
- * @return {@link ArangoDBAsync.Builder}
- */
- public Builder sslContext(final SSLContext sslContext) {
- setSslContext(sslContext);
- return this;
- }
-
- /**
- * Sets the chunk size when {@link Protocol#VST} is used.
- *
- * @param chunksize size of a chunk in bytes
- * @return {@link ArangoDBAsync.Builder}
- */
- public Builder chunksize(final Integer chunksize) {
- setChunkSize(chunksize);
- return this;
- }
-
- /**
- * Sets the maximum number of connections the built in connection pool will open.
- *
- *
- * ATTENTION!: Any registered custom serializer/deserializer or module will be ignored.
- *
- * @param serialization custom serializer/deserializer
- * @return {@link ArangoDBAsync.Builder}
- */
- public Builder serializer(final ArangoSerde serialization) {
- setUserDataSerde(serialization);
- return this;
+ class Builder extends InternalArangoDBBuilder
+ * {@link Protocol#VST} == 1
+ * {@link Protocol#HTTP_JSON} == 20
+ * {@link Protocol#HTTP_VPACK} == 20
+ *
+ *
+ * @param maxConnections max number of connections
+ * @return {@link ArangoDB.Builder}
+ */
+ @SuppressWarnings("unchecked")
+ public T maxConnections(final Integer maxConnections) {
+ config.setMaxConnections(maxConnections);
+ return (T) this;
+ }
+
+ /**
+ * Set the maximum time to life of a connection. After this time the connection will be closed automatically.
+ *
+ * @param connectionTtl the maximum time to life of a connection in milliseconds
+ * @return {@link ArangoDB.Builder}
+ */
+ @SuppressWarnings("unchecked")
+ public T connectionTtl(final Long connectionTtl) {
+ config.setConnectionTtl(connectionTtl);
+ return (T) this;
+ }
+
+ /**
+ * Set the keep-alive interval for VST connections. If set, every VST connection will perform a no-op request
+ * every {@code keepAliveInterval} seconds, to avoid to be closed due to inactivity by the server (or by the
+ * external environment, eg. firewall, intermediate routers, operating system).
+ *
+ * @param keepAliveInterval interval in seconds
+ * @return {@link ArangoDB.Builder}
+ */
+ @SuppressWarnings("unchecked")
+ public T keepAliveInterval(final Integer keepAliveInterval) {
+ config.setKeepAliveInterval(keepAliveInterval);
+ return (T) this;
+ }
+
+ /**
+ * Whether or not the driver should acquire a list of available coordinators in an ArangoDB cluster or a single
+ * server with active failover. In case of Active-Failover deployment set to {@code true} to enable automatic
+ * master discovery.
+ *
+ *