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