4 * Class responsible for distributing update information
5 * to all registered listeners
7 public abstract class UpdateMessageBroker
9 private static final int MAXIMUM_NUMBER_SUBSCRIBERS = 7;
10 /** Array of all subscribers */
11 private static DataSubscriber[] _subscribers = new DataSubscriber[MAXIMUM_NUMBER_SUBSCRIBERS];
12 /** Counter of the number of subscribers added so far */
13 private static int _subscriberNum = 0;
14 /** Enable/disabled flag */
15 private static boolean _enabled = true;
19 * Add a data subscriber to the list
20 * @param inSub DataSubscriber to add
22 public static void addSubscriber(DataSubscriber inSub)
24 _subscribers[_subscriberNum] = inSub;
29 * Enable or disable the messaging (to allow temporary disabling for multiple operations)
30 * @param inEnabled false to disable, true to enable again
32 public static void enableMessaging(boolean inEnabled)
38 * Send a message to all subscribers that
39 * the data has been updated
41 public static void informSubscribers()
43 informSubscribers(DataSubscriber.ALL);
48 * Send message to all subscribers
49 * @param inChange Change that occurred
51 public static void informSubscribers(byte inChange)
53 // TODO: Launch separate thread so that whatever caused the inform can finish
54 if (!_enabled) return;
55 for (int i=0; i<_subscribers.length; i++)
57 if (_subscribers[i] != null)
59 _subscribers[i].dataUpdated(inChange);
65 * Send message to all subscribers
66 * @param inMessage message to display informing of action completed
68 public static void informSubscribers(String inMessage)
70 if (!_enabled) return;
71 for (int i=0; i<_subscribers.length; i++)
73 if (_subscribers[i] != null)
75 _subscribers[i].actionCompleted(inMessage);