1
0

Subscription (#7)

* Change update DataPoints by a subscription way

* Remove unused import

* small polish
This commit is contained in:
Rémi Heredero
2023-05-26 12:46:35 +02:00
committed by GitHub
parent 9fdcda2a00
commit d58097d723
6 changed files with 32 additions and 18 deletions

View File

@@ -19,12 +19,12 @@ import java.util.Properties;
public class DatabaseConnector implements DataPointListener {
private Properties properties = new Properties(); // Properties of the config.properties file
private final Properties properties = new Properties(); // Properties of the config.properties file
private String fullURL = null; // Full URL of the InfluxDB server
private URL urlForWrite = null; // URL of the InfluxDB server
private HttpURLConnection con = null; // Connection to the InfluxDB server
private boolean initialized = false; // Boolean to know if the database connector is initialized
private TimeManager _timeManager = new TimeManager(3); // Time manager to manage the time of the data points
private final TimeManager _timeManager = new TimeManager(3); // Time manager to manage the time of the data points
private long _timestamp = 0; // Timestamp of the data points
String default_token = System.getenv("SECRET_TOKEN"); // Token to access the InfluxDB server
public static String url = null; // URL of the InfluxDB server
@@ -56,6 +56,9 @@ public class DatabaseConnector implements DataPointListener {
if (bucket == null){
bucket = properties.getProperty("BUCKET");
}
// Subscribe to the update of DataPoints
DataPointListener.subscribeUpdate(this);
}
/**
@@ -129,7 +132,7 @@ public class DatabaseConnector implements DataPointListener {
*/
private void pushToDatabase(DataPoint dp) {
// Initialize the database connector if not already done
if(initialized == false){
if(!initialized){
initialize(null);
}