This repository was archived by the owner on Feb 12, 2023. It is now read-only.
forked from influxdata/influxdb-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInfluxDBFactory.java
108 lines (98 loc) · 3.55 KB
/
InfluxDBFactory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package org.influxdb;
import org.influxdb.InfluxDB.ResponseFormat;
import org.influxdb.impl.InfluxDBImpl;
import okhttp3.OkHttpClient;
import org.influxdb.impl.Preconditions;
import java.util.Objects;
/**
* A Factory to create a instance of a InfluxDB Database adapter.
*
* @author stefan.majer [at] gmail.com
*
*/
public enum InfluxDBFactory {
INSTANCE;
/**
* Create a connection to a InfluxDB.
*
* @param url
* the url to connect to.
* @return a InfluxDB adapter suitable to access a InfluxDB.
*/
public static InfluxDB connect(final String url) {
Preconditions.checkNonEmptyString(url, "url");
return new InfluxDBImpl(url, null, null, new OkHttpClient.Builder());
}
/**
* Create a connection to a InfluxDB.
*
* @param url
* the url to connect to.
* @param username
* the username which is used to authorize against the influxDB instance.
* @param password
* the password for the username which is used to authorize against the influxDB
* instance.
* @return a InfluxDB adapter suitable to access a InfluxDB.
*/
public static InfluxDB connect(final String url, final String username, final String password) {
Preconditions.checkNonEmptyString(url, "url");
Preconditions.checkNonEmptyString(username, "username");
return new InfluxDBImpl(url, username, password, new OkHttpClient.Builder());
}
/**
* Create a connection to a InfluxDB.
*
* @param url
* the url to connect to.
* @param client
* the HTTP client to use
* @return a InfluxDB adapter suitable to access a InfluxDB.
*/
public static InfluxDB connect(final String url, final OkHttpClient.Builder client) {
Preconditions.checkNonEmptyString(url, "url");
Objects.requireNonNull(client, "client");
return new InfluxDBImpl(url, null, null, client);
}
/**
* Create a connection to a InfluxDB.
*
* @param url
* the url to connect to.
* @param username
* the username which is used to authorize against the influxDB instance.
* @param password
* the password for the username which is used to authorize against the influxDB
* instance.
* @param client
* the HTTP client to use
* @return a InfluxDB adapter suitable to access a InfluxDB.
*/
public static InfluxDB connect(final String url, final String username, final String password,
final OkHttpClient.Builder client) {
return connect(url, username, password, client, ResponseFormat.JSON);
}
/**
* Create a connection to a InfluxDB.
*
* @param url
* the url to connect to.
* @param username
* the username which is used to authorize against the influxDB instance.
* @param password
* the password for the username which is used to authorize against the influxDB
* instance.
* @param client
* the HTTP client to use
* @param responseFormat
* The {@code ResponseFormat} to use for response from InfluxDB server
* @return a InfluxDB adapter suitable to access a InfluxDB.
*/
public static InfluxDB connect(final String url, final String username, final String password,
final OkHttpClient.Builder client, final ResponseFormat responseFormat) {
Preconditions.checkNonEmptyString(url, "url");
Preconditions.checkNonEmptyString(username, "username");
Objects.requireNonNull(client, "client");
return new InfluxDBImpl(url, username, password, client, responseFormat);
}
}