fix some warnings
This commit is contained in:
parent
fa54c5fbb3
commit
6f51ae0341
@ -7,8 +7,8 @@ public abstract class DataPoint{
|
|||||||
|
|
||||||
|
|
||||||
public static Map<String, DataPoint> dataPointMap = new HashMap<>(); // Map of all DataPoints
|
public static Map<String, DataPoint> dataPointMap = new HashMap<>(); // Map of all DataPoints
|
||||||
private String label; // Label of this DataPoint
|
private final String label; // Label of this DataPoint
|
||||||
private boolean isOutput; // True if this DataPoint is an output, false if it's an input
|
private final boolean isOutput; // True if this DataPoint is an output, false if it's an input
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor of DataPoint
|
* Constructor of DataPoint
|
||||||
|
@ -15,12 +15,13 @@ import java.net.HttpURLConnection;
|
|||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.ProtocolException;
|
import java.net.ProtocolException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
|
||||||
public class DatabaseConnector implements DataPointListener {
|
public class DatabaseConnector implements DataPointListener {
|
||||||
private final 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 URL urlForWrite = null; // URL of the InfluxDB server
|
||||||
private HttpURLConnection con = null; // Connection to 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 boolean initialized = false; // Boolean to know if the database connector is initialized
|
||||||
@ -40,7 +41,7 @@ public class DatabaseConnector implements DataPointListener {
|
|||||||
*/
|
*/
|
||||||
private DatabaseConnector (){
|
private DatabaseConnector (){
|
||||||
// Read the config.properties file
|
// Read the config.properties file
|
||||||
try (InputStream input = new FileInputStream("src/config.properties")) {
|
try (InputStream input = Files.newInputStream(Paths.get("src/config.properties"))) {
|
||||||
properties.load(input);
|
properties.load(input);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -77,6 +78,8 @@ public class DatabaseConnector implements DataPointListener {
|
|||||||
* @param url URL of the database. If null take the URL from the config.properties file
|
* @param url URL of the database. If null take the URL from the config.properties file
|
||||||
*/
|
*/
|
||||||
public void initialize(String url){
|
public void initialize(String url){
|
||||||
|
// Full URL of the InfluxDB server
|
||||||
|
String fullURL = null;
|
||||||
try{
|
try{
|
||||||
if(urlForWrite == null){
|
if(urlForWrite == null){
|
||||||
if(url == null){
|
if(url == null){
|
||||||
@ -106,10 +109,6 @@ public class DatabaseConnector implements DataPointListener {
|
|||||||
con.setRequestProperty("Content-Type", "text/plain");
|
con.setRequestProperty("Content-Type", "text/plain");
|
||||||
con.setRequestProperty("Accept", "application/json");
|
con.setRequestProperty("Accept", "application/json");
|
||||||
con.setDoOutput(true);
|
con.setDoOutput(true);
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
} catch (ProtocolException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -122,7 +121,7 @@ public class DatabaseConnector implements DataPointListener {
|
|||||||
data += "}";
|
data += "}";
|
||||||
Utility.pDebug(data);
|
Utility.pDebug(data);
|
||||||
sendDataToDatabase(data);
|
sendDataToDatabase(data);
|
||||||
fullURL=null; // Reset the full URL
|
fullURL =null; // Reset the full URL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user