public final class JFluxClient extends Object implements AutoCloseable
Provides convenient abstractions over JFluxHttpClient.
JFluxHttpClient| Modifier and Type | Class and Description |
|---|---|
static class |
JFluxClient.Builder
Used to construct instances of
JFluxClient. |
| Modifier and Type | Method and Description |
|---|---|
void |
alterRetentionPolicy(String retentionPolicyName,
RetentionPolicy newDefinition)
Alters the specified retention policy.
|
void |
alterRetentionPolicy(String retentionPolicyName,
String databaseName,
RetentionPolicy newDefinition)
Alters the specified retention policy.
|
void |
close() |
void |
createDatabase(String databaseName)
Creates a new database with the specified name.
|
void |
createRetentionPolicy(RetentionPolicy retentionPolicy)
Creates a new retention policy on the selected database.
|
void |
createRetentionPolicy(RetentionPolicy retentionPolicy,
String databaseName)
Creates a new retention policy on the specified database.
|
boolean |
databaseExists(String databaseName)
Gets a value indicating whether the specified database exists.
|
void |
dropDatabase(String databaseName)
Drops the specified database.
|
void |
dropRetentionPolicy(String retentionPolicyName)
Drops the specified retention policy on the selected database.
|
void |
dropRetentionPolicy(String retentionPolicyName,
String databaseName)
Drops the specified retention policy.
|
<T> List<T> |
getAllPoints(Class<T> targetType)
Alias for
getAllPoints(String, Class) using a preselected database. |
List<Point> |
getAllPoints(String measurementName)
Alias for
getAllPoints(String, String) using a preselected database. |
<T> List<T> |
getAllPoints(String databaseName,
Class<T> targetType)
Retrieves all points for the specified class.
|
List<Point> |
getAllPoints(String databaseName,
String measurementName)
Retrieves all points for the specified measurement.
|
List<String> |
getDatabases()
Gets the existing databases.
|
List<RetentionPolicy> |
getRetentionPolicies()
Gets all the retention policies defined on the currently selected database.
|
List<RetentionPolicy> |
getRetentionPolicies(String databaseName)
Gets all the retention policies defined on the specified database.
|
RetentionPolicy |
getRetentionPolicy(String retentionPolicyName)
Gets the definition of the specified retention policy.
|
RetentionPolicy |
getRetentionPolicy(String retentionPolicyName,
String databaseName)
Gets the definition of the specified retention policy.
|
boolean |
retentionPolicyExists(String retentionPolicyName)
Returns a value indicating whether the specified retention policy exists on the selected
database.
|
boolean |
retentionPolicyExists(String retentionPolicyName,
String databaseName)
Returns a value indicating whether the specified retention policy exists on the specified
database.
|
void |
useDatabase(String databaseName)
Selects a database to use implicitly with methods in this class.
|
void |
write(Collection<?> data)
Writes the specified data using the specified retention policy.
|
void |
write(Collection<?> data,
String retentionPolicyName)
Writes the specified data using the specified retention policy.
|
void |
write(Object data)
Alias for
write(Collection) for a single object. |
void |
write(Object data,
String retentionPolicyName)
Alias for
write(Collection, String) for a single point. |
void |
write(String databaseName,
Collection<?> data)
Writes the specified data to the specified database, using the default retention policy.
|
void |
write(String databaseName,
Collection<?> data,
String retentionPolicyName)
Writes the specified data to the specified database, using the specified retention policy.
|
void |
write(String databaseName,
Object data)
Alias for
write(String, Collection) for a single point. |
void |
write(String databaseName,
Object data,
String retentionPolicyName)
Alias for
write(String, Collection, String) for a single point. |
void |
writePoint(String measurementName,
Point point)
Alias for
writePoints(String, Collection) for a single point. |
void |
writePoint(String measurementName,
Point point,
String retentionPolicyName)
Alias for
writePoints(String, Collection, String) for a single point. |
void |
writePoint(String databaseName,
String measurementName,
Point point)
Alias for
writePoints(String, String, Collection) for a single point. |
void |
writePoint(String databaseName,
String measurementName,
Point point,
String retentionPolicyName)
Alias for
writePoints(String, String, Collection, String) for a single point. |
void |
writePoints(String measurementName,
Collection<Point> points)
Writes the specified points to InfluxDB, using the default retention policy.
|
void |
writePoints(String measurementName,
Collection<Point> points,
String retentionPolicyName)
Writes the specified points to InfluxDB.
|
void |
writePoints(String databaseName,
String measurementName,
Collection<Point> points)
Writes the specified points to InfluxDB, using the default retention policy.
|
void |
writePoints(String databaseName,
String measurementName,
Collection<Point> points,
String retentionPolicyName)
Writes the specified points to InfluxDB.
|
public List<String> getDatabases()
public boolean databaseExists(String databaseName)
databaseName - the database name to check, not nulltrue if the database exists, false otherwiseIllegalArgumentException - if databaseName is nullpublic void createDatabase(String databaseName)
databaseName - the database to create, not nullIllegalArgumentException - if databaseName is nullDatabaseAlreadyExistsException - if the database already existspublic void dropDatabase(String databaseName)
databaseName - the database to drop, not nullIllegalArgumentException - if trying to drop the internal InfluxDB databaseIllegalArgumentException - if databaseName is nullUnknownDatabaseException - if the database does not existpublic void useDatabase(String databaseName)
This is convenience method to avoid having to specify the database to perform operations on
in every method call, similar to InfluxDB's own USE DATABASE statement.
databaseName - the database to use, not nullIllegalArgumentException - if databaseName is nullUnknownDatabaseException - if the specified database does not existpublic List<RetentionPolicy> getRetentionPolicies()
Note that a database must have been already selected with useDatabase(String) before
calling this method.
NoDatabaseSelectedException - if no database has been selectedpublic List<RetentionPolicy> getRetentionPolicies(String databaseName)
databaseName - name of the database to check, not nullUnknownDatabaseException - if the database does not existpublic RetentionPolicy getRetentionPolicy(String retentionPolicyName)
Note that a database must have been already selected with useDatabase(String) before
calling this method.
retentionPolicyName - the retention policy to getnull if not foundIllegalArgumentException - if retentionPolicyName is nullNoDatabaseSelectedException - if no database has been selectedpublic RetentionPolicy getRetentionPolicy(String retentionPolicyName, String databaseName)
retentionPolicyName - the retention policy to getdatabaseName - the database the retention policy is defined onnull if not foundIllegalArgumentException - if retentionPolicyName or databaseName are
nullUnknownDatabaseException - if the database does not existpublic boolean retentionPolicyExists(String retentionPolicyName)
Note that a database must have been already selected with useDatabase(String) before
calling this method.
retentionPolicyName - the retention policy to checktrue if the retention policy exists, false otherwiseNoDatabaseSelectedException - if no database has been selectedpublic boolean retentionPolicyExists(String retentionPolicyName, String databaseName)
retentionPolicyName - the retention policy to checkdatabaseName - the database to checktrue if the retention policy exists, false otherwiseIllegalArgumentException - if the retention policy or database names are nullUnknownDatabaseException - if the database does not existpublic void createRetentionPolicy(RetentionPolicy retentionPolicy)
Note that a database must have been already selected with useDatabase(String) before
calling this method.
retentionPolicy - the retention policy to createNoDatabaseSelectedException - if no database has been selectedIllegalArgumentException - if retentionPolicy is nullRetentionPolicyAlreadyExistsException - if the retention policy already existspublic void createRetentionPolicy(RetentionPolicy retentionPolicy, String databaseName)
retentionPolicy - the retention policy to createdatabaseName - the database to create the retention policy onIllegalArgumentException - if retentionPolicy or databaseName is nullUnknownDatabaseException - if the database does not existRetentionPolicyAlreadyExistsException - if the retention policy already existspublic void alterRetentionPolicy(String retentionPolicyName, RetentionPolicy newDefinition)
Note that the name of the retention policy cannot be altered and thus the original name will always be kept, even if the new definition specifies a different one.
Note also that a database must have been already selected with useDatabase(String)
before calling this method.
retentionPolicyName - the retention policy to alternewDefinition - the new definition for the retention policyNoDatabaseSelectedException - if no database has been selectedIllegalArgumentException - if any of the arguments are nullUnknownRetentionPolicyException - if the retention policy does not existpublic void alterRetentionPolicy(String retentionPolicyName, String databaseName, RetentionPolicy newDefinition)
Note that the name of the retention policy cannot be altered and thus the original name will always be kept, even if the new definition specifies a different one.
retentionPolicyName - the retention policy to alterdatabaseName - the database the retention policy is defined onnewDefinition - the new definition for the retention policyIllegalArgumentException - if any of the arguments are nullUnknownDatabaseException - if the database does not existUnknownRetentionPolicyException - if the retention policy does not existpublic void dropRetentionPolicy(String retentionPolicyName)
Note that a database must have been already selected with useDatabase(String) before
calling this method.
retentionPolicyName - the retention policy to dropNoDatabaseSelectedException - if no database has been selectedIllegalArgumentException - if retentionPolicy is nullUnknownRetentionPolicyException - if the retention policy does not existpublic void dropRetentionPolicy(String retentionPolicyName, String databaseName)
retentionPolicyName - the retention policy to dropdatabaseName - the database the retention policy is defined onIllegalArgumentException - if retentionPolicy or databaseName
are nullUnknownDatabaseException - if the database does not existUnknownRetentionPolicyException - if the retention policy does not existpublic void write(Object data)
write(Collection) for a single object.data - the data to write, not nullNoDatabaseSelectedException - if no database has been selectedIllegalArgumentException - if data is nullAnnotationProcessingException - if the data object is not correctly annotatedpublic void write(String databaseName, Object data)
write(String, Collection) for a single point.databaseName - the database to write to, not nulldata - the data to write, not nullAnnotationProcessingException - if the data object is not correctly annotatedIllegalArgumentException - if the input data is nullUnknownDatabaseException - if the database does not existwritePoint(String, String, Point)public void write(Collection<?> data)
Note that a database must have been already selected with useDatabase(String) before
calling this method.
data - the data to writeNoDatabaseSelectedException - if no database has been selectedAnnotationProcessingException - if the data objects are not correctly annotated.public void write(String databaseName, Collection<?> data)
The data object must be annotated in order to be converted to points and written to InfluxDB.
databaseName - the database to write to, not nulldata - the data to writeAnnotationProcessingException - if the data objects are not correctly annotatedUnknownDatabaseException - if the database does not existwritePoints(String, String, Collection)public void write(Object data, String retentionPolicyName)
write(Collection, String) for a single point.data - the data to write, not nullretentionPolicyName - the retention policy to write to, not nullNoDatabaseSelectedException - if no database has been selectedIllegalArgumentException - if any of the arguments is nullAnnotationProcessingException - if the data objects are not correctly annotatedUnknownRetentionPolicyException - if the retenion policy does not existpublic void write(String databaseName, Object data, String retentionPolicyName)
write(String, Collection, String) for a single point.databaseName - the database to write to, not nulldata - the data to write, not nullretentionPolicyName - the retention policy to write to, not nullAnnotationProcessingException - if the data object is not correctly annotatedUnknownDatabaseException - if the database does not existIllegalArgumentException - if the retention policy does not existwritePoint(String, String, Point, String)public void write(Collection<?> data, String retentionPolicyName)
Note that a database must have been already selected with useDatabase(String) before
calling this method.
data - the data to writeretentionPolicyName - the retention policy to write to, not nullNoDatabaseSelectedException - if no database has been selectedIllegalArgumentException - if retentionPolicyName is nullAnnotationProcessingException - if the data objects are not correctly annotatedUnknownRetentionPolicyException - if the retention policy does not existpublic void write(String databaseName, Collection<?> data, String retentionPolicyName)
The data object must be annotated in order to be converted to points and written to InfluxDB.
databaseName - the database to write to, not nulldata - the data to writeretentionPolicyName - the retention policy to write to, not nullAnnotationProcessingException - if the data objects are not correctly annotatedUnknownDatabaseException - if the database does not existIllegalArgumentException - if the retention policy does not existwritePoints(String, String, Collection, String)public void writePoint(String measurementName, Point point)
writePoints(String, Collection) for a single point.measurementName - the measurement to write to, not nullpoint - the point to write, not nullNoDatabaseSelectedException - if no database has been selectedIllegalArgumentException - if any of the arguments is nullpublic void writePoint(String databaseName, String measurementName, Point point)
writePoints(String, String, Collection) for a single point.databaseName - the database to write to, not nullmeasurementName - the measurement to write to, not nullpoint - the point to writeIllegalArgumentException - if the database or measurement name is nullUnknownDatabaseException - if the database does not existpublic void writePoint(String measurementName, Point point, String retentionPolicyName)
writePoints(String, Collection, String) for a single point.measurementName - the measurement to write to, not nullpoint - the point to write, not nullretentionPolicyName - the retention policy to write to, not nullNoDatabaseSelectedException - if no database has been selectedIllegalArgumentException - if any of the arguments is nullUnknownRetentionPolicyException - if the retention policy does not existpublic void writePoint(String databaseName, String measurementName, Point point, String retentionPolicyName)
writePoints(String, String, Collection, String) for a single point.databaseName - the database to write to, not nullmeasurementName - the measurement to write to, not nullpoint - the point to writeretentionPolicyName - the retention policy to write to, not nullUnknownDatabaseException - if the database does not existIllegalArgumentException - if the retention policy does not existpublic void writePoints(String measurementName, Collection<Point> points)
Note that a database must have been already selected with useDatabase(String) before
calling this method.
measurementName - the measurement to write to, not nullpoints - the points to writeNoDatabaseSelectedException - if no database has been selectedIllegalArgumentException - if measurementName is nullpublic void writePoints(String databaseName, String measurementName, Collection<Point> points)
databaseName - the database to write to, not nullmeasurementName - the measurement to write to, not nullpoints - the points to writeIllegalArgumentException - if the database or measurement name is nullUnknownDatabaseException - if the database does not existpublic void writePoints(String measurementName, Collection<Point> points, String retentionPolicyName)
Note that a database must have been already selected with useDatabase(String) before
calling this method.
measurementName - the measurement to write to, not nullpoints - the points to writeretentionPolicyName - the retention policy to write to, not nullNoDatabaseSelectedException - if no database has been selectedIllegalArgumentException - if any of the arguments is nullUnknownRetentionPolicyException - if the retention policy does not existpublic void writePoints(String databaseName, String measurementName, Collection<Point> points, String retentionPolicyName)
databaseName - the database to write to, not nullmeasurementName - the measurement to write to, not nullpoints - the points to writeretentionPolicyName - the retention policy to write to, not nullUnknownDatabaseException - if the database does not existUnknownRetentionPolicyException - if the retention policy does not existpublic <T> List<T> getAllPoints(Class<T> targetType)
getAllPoints(String, Class) using a preselected database.
Note that a database must have been already selected with useDatabase(String) before
calling this method.
T - type of the resultstargetType - the class to convert to, not nulltargetType, or an empty list if no
resultsNoDatabaseSelectedException - if no database selectedpublic <T> List<T> getAllPoints(String databaseName, Class<T> targetType)
The measurement name is read from the class name, or the
Measurement annotation if present. The resulting
points are converted to instances of the class, setting the values of fields annotated with
Timestamp, Field, and Tag.
T - type of the resultsdatabaseName - the database where the measurement is found, not nulltargetType - the class to convert the results to, not nulltargetType, or an empty list if no
resultsIllegalArgumentException - if databaseName or targetType is nullUnknownDatabaseException - if the database cannot be foundAnnotationBasedPointConverterpublic List<Point> getAllPoints(String measurementName)
getAllPoints(String, String) using a preselected database.
Note that a database must have been already selected with useDatabase(String) before
calling this method.
measurementName - the measurement to query, not nullNoDatabaseSelectedException - if no database has been selectedIllegalArgumentException - if the measurement name is nullpublic List<Point> getAllPoints(String databaseName, String measurementName)
databaseName - the database where the measurement is found, not nullmeasurementName - the measurement to query, not nullIllegalArgumentException - if the database or measurement name is nullUnknownDatabaseException - if the database does not existpublic void close()
throws Exception
close in interface AutoCloseableExceptionCopyright © 2020. All rights reserved.