]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/UpdateMessageBroker.java
Version 1, September 2006
[GpsPrune.git] / tim / prune / UpdateMessageBroker.java
diff --git a/tim/prune/UpdateMessageBroker.java b/tim/prune/UpdateMessageBroker.java
new file mode 100644 (file)
index 0000000..f2dfd2a
--- /dev/null
@@ -0,0 +1,49 @@
+package tim.prune;
+
+/**
+ * Class responsible for distributing update information
+ * to all registered listeners
+ */
+public class UpdateMessageBroker
+{
+       private DataSubscriber[] _subscribers;
+       private int _subscriberNum = 0;
+       private static final int MAXIMUM_NUMBER_SUBSCRIBERS = 4;
+
+
+       /**
+        * Constructor
+        * @param inTrack Track object
+        */
+       public UpdateMessageBroker()
+       {
+               _subscribers = new DataSubscriber[MAXIMUM_NUMBER_SUBSCRIBERS];
+       }
+
+
+       /**
+        * Add a data subscriber to the list
+        * @param inSub DataSubscriber to add
+        */
+       public void addSubscriber(DataSubscriber inSub)
+       {
+               _subscribers[_subscriberNum] = inSub;
+               _subscriberNum++;
+       }
+
+
+       /**
+        * Send a message to all subscribers that
+        * the data has been updated
+        */
+       public void informSubscribers()
+       {
+               for (int i=0; i<_subscribers.length; i++)
+               {
+                       if (_subscribers[i] != null)
+                       {
+                               _subscribers[i].dataUpdated();
+                       }
+               }
+       }
+}