edu.berkeley.guir.ptk.notification
Class NotificationPolicy

java.lang.Object
  extended byedu.berkeley.guir.ptk.notification.NotificationPolicy
All Implemented Interfaces:
java.lang.Runnable

public class NotificationPolicy
extends java.lang.Object
implements java.lang.Runnable

Handles the routing of events to Notification Setters. An instance of class is initialized by the PeripheralDisplay class each time makeConnection is called.

The method setNotification loops through the Abstractors that are installed (these correspond to an array of Notification Setters or a single Notification Setter passed into a makeConnection call). Different instances of this class can have different Notification Setters installed. These set the notification level of the event. Default for the setNotification method is to continue looping through all installed Notification Setters unless the notify level is set to "demand action" (in which case it would stop all remaining notification setting).

In setNotification, this policy determines if it should call a Notification Setter's set method by comparing the metadata of the event and data IDs with the metadata and data IDs the Notification Setter indicates it can handle.

Developers will rarely need to modify this class or worry about how it works. One case in which developers may want to modify this class is if they want to modify the way in which events are passed to a chain of installed Notification Setters.

Author:
tmatthew Created: Mar 2, 2003

Field Summary
 History h
          All notification policies can look at the application's event history.
 EventPriorityQueue inQ
          The queue that houses incoming events to be processed by this policy.
protected  java.util.Vector notification_setters
           
 EventPriorityQueue outQ
          The queue where the policy places processed events.
 PeripheralDisplay pd
          This is a pointer to the Application that contains this NotificationPolicy.
 
Constructor Summary
NotificationPolicy()
          Default constructor which sets all data fields to null.
NotificationPolicy(java.util.Vector notify_setters)
          Constructor that takes two parameters.
 
Method Summary
 void addNotificationSetter(NotificationSetter ns)
          Adds a notification setter to this policy.
 void run()
          Processing loop that periodically checks the inQ for new events to be processed.
 int setNotification(Event e)
          This is the most important method in this class - it handles event processing by looping through all notification setters installed in the policy and asking them to set the events notification level (depending on the event metadata/data).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

notification_setters

protected java.util.Vector notification_setters

inQ

public EventPriorityQueue inQ
The queue that houses incoming events to be processed by this policy.


outQ

public EventPriorityQueue outQ
The queue where the policy places processed events.


h

public History h
All notification policies can look at the application's event history. This History member just points to the application's event history. It is set during the application's initialize_policies() method.


pd

public PeripheralDisplay pd
This is a pointer to the Application that contains this NotificationPolicy. Used to check the interruptibility of the user of the application (see Application.checkInterruptibility(), which is called in the setNotification() method). This feature is currently not used.

Constructor Detail

NotificationPolicy

public NotificationPolicy()
Default constructor which sets all data fields to null.


NotificationPolicy

public NotificationPolicy(java.util.Vector notify_setters)
Constructor that takes two parameters.

Parameters:
notify_setters - Vector of notification setters to be installed in this policy. The order of this Vector dictates the order in which the setters will process a new event. The setter in the first (0th) position of Vector will process the event first.
Method Detail

setNotification

public int setNotification(Event e)
This is the most important method in this class - it handles event processing by looping through all notification setters installed in the policy and asking them to set the events notification level (depending on the event metadata/data). A notification setter will only set the notification level of an event whose data ID is included in one of its data fields.

The default for this method is to discontinue looping if an event's notification level is set to "demand action." To change this, subclass and reimplement this method.

Parameters:
e - the event with new input data for which the notification level will be set
Returns:
int the notification level to which the event was set

run

public void run()
Processing loop that periodically checks the inQ for new events to be processed. As with all java threads, this is the main thread method. If there is an event, it is processed and put into the outQ. Processing for this policy involves calling setNotification(). This method is called in between sleeping periods of Application.POLICY_SLEEP_TIME.

Specified by:
run in interface java.lang.Runnable

addNotificationSetter

public void addNotificationSetter(NotificationSetter ns)
Adds a notification setter to this policy. Used by PeripheralDisplay.

Parameters:
ns - notification setter to add.