]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/UpdateMessageBroker.java
Version 5, May 2008
[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                 for (int i=0; i<_subscribers.length; i++)
42                 {
43                         if (_subscribers[i] != null)
44                         {
45                                 _subscribers[i].dataUpdated(inChange);
46                         }
47                 }
48         }
49
50         /**
51          * Send message to all subscribers
52          * @param inMessage message to display informing of action completed
53          */
54         public static void informSubscribers(String inMessage)
55         {
56                 for (int i=0; i<_subscribers.length; i++)
57                 {
58                         if (_subscribers[i] != null)
59                         {
60                                 _subscribers[i].actionCompleted(inMessage);
61                         }
62                 }
63         }
64 }