Change update DataPoints by a subscription way
This commit is contained in:
		| @@ -22,9 +22,9 @@ public abstract class DataPoint{ | ||||
|         } else { | ||||
|             dataPointMap.replace(this.label, this); | ||||
|         } | ||||
|         DatabaseConnector.getMySelf().onNewValue(this); | ||||
|         WebConnector.getMySelf().onNewValue(this); | ||||
|         FieldConnector.getMySelf().onNewValue(this); | ||||
|  | ||||
|         // Update every connector | ||||
|         DataPointListener.listeners.forEach(listener -> listener.onNewValue(this)); | ||||
|     } | ||||
|     public static DataPoint getDataPointFromLabel(String label){ | ||||
|         if( !dataPointMap.containsKey(label) ){ | ||||
|   | ||||
| @@ -1,6 +1,20 @@ | ||||
| package ch.hevs.isi.core; | ||||
|  | ||||
| import java.util.Vector; | ||||
|  | ||||
| public interface DataPointListener { | ||||
|  | ||||
|     // Vector of listeners | ||||
|     Vector<DataPointListener> listeners = new Vector<>(); | ||||
|  | ||||
|     void onNewValue(DataPoint dp); | ||||
|  | ||||
|     /** | ||||
|      * Subscribe to the update of the DataPoint | ||||
|      * @param listener the listener to subscribe | ||||
|      */ | ||||
|     static void subscribeUpdate(DataPointListener listener){ | ||||
|         // Call by final class for subscribe update | ||||
|         listeners.add(listener); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -10,6 +10,8 @@ public class FieldConnector implements DataPointListener { | ||||
|  | ||||
|     private FieldConnector(){ | ||||
|  | ||||
|         // Subscribe to the update of DataPoints | ||||
|         DataPointListener.subscribeUpdate(this); | ||||
|     } | ||||
|  | ||||
|     public static FieldConnector getMySelf(){ | ||||
|   | ||||
| @@ -8,6 +8,8 @@ public class WebConnector implements DataPointListener { | ||||
|  | ||||
|     private WebConnector (){ | ||||
|  | ||||
|         // Subscribe to the update of DataPoints | ||||
|         DataPointListener.subscribeUpdate(this); | ||||
|     } | ||||
|  | ||||
|     public static WebConnector  getMySelf(){ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user