]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/UpdateMessageBroker.java
Version 11, August 2010
[GpsPrune.git] / tim / prune / UpdateMessageBroker.java
1 package tim.prune;
2
3 /**
4  * Class responsible for distributing update information
5  * to all registered listeners
6  */
7 public abstract class UpdateMessageBroker
8 {
9         private static final int MAXIMUM_NUMBER_SUBSCRIBERS = 6;
10         private static DataSubscriber[] _subscribers = new DataSubscriber[MAXIMUM_NUMBER_SUBSCRIBERS];
11         private static int _subscriberNum = 0;
12
13
14         /**
15          * Add a data subscriber to the list
16          * @param inSub DataSubscriber to add
17          */
18         public static void addSubscriber(DataSubscriber inSub)
19         {
20                 _subscribers[_subscriberNum] = inSub;
21                 _subscriberNum++;
22         }
23
24
25         /**
26          * Send a message to all subscribers that
27          * the data has been updated
28          */
29         public static void informSubscribers()
30         {
31                 informSubscribers(DataSubscriber.ALL);
32         }
33
34
35         /**
36          * Send message to all subscribers
37          * @param inChange Change that occurred
38          */
39         public static void informSubscribers(byte inChange)
40         {
41                 // TODO: Launch separate thread so that whatever caused the inform can finish
42                 for (int i=0; i<_subscribers.length; i++)
43                 {
44                         if (_subscribers[i] != null)
45                         {
46                                 _subscribers[i].dataUpdated(inChange);
47                         }
48                 }
49         }
50
51         /**
52          * Send message to all subscribers
53          * @param inMessage message to display informing of action completed
54          */
55         public static void informSubscribers(String inMessage)
56         {
57                 for (int i=0; i<_subscribers.length; i++)
58                 {
59                         if (_subscribers[i] != null)
60                         {
61                                 _subscribers[i].actionCompleted(inMessage);
62                         }
63                 }
64         }
65 }