edu.berkeley.guir.ptk.abstraction
Class AbstractionPolicy

java.lang.Object
  extended byedu.berkeley.guir.ptk.abstraction.AbstractionPolicy
All Implemented Interfaces:
java.lang.Runnable

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

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

The method doAbstraction loops through the Abstractors that are installed (these correspond to an array of Abstractors or a single Abstractor passed into a makeConnection call). Different instances of this class can have different Abstractors installed. These abstract the event data. Default for the doAbstraction method is to continue looping through all installed Abstractors.

In doAbstraction, this policy determines if it should call an Abstractor's doAbstract method by comparing the metadata of the event (and possibly data IDs) with the metadata (and possibly data IDs) the Abstractor indicates it can abstract.

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 Abstractors.

Author:
tmatthew Created: Mar 2, 2003

Field Summary
 boolean add_to_history
          Flag used to indicate whether this policy should add its processed event to its history queue (see history queue above)
 History h
          All abstraction policies can look at the application's event history.
 EventPriorityQueue inQ
          This is the queue that houses incoming events to be processed by this policy.
 EventPriorityQueue outQ
          This is the queue where the policy places processed events.
 
Constructor Summary
AbstractionPolicy()
          Default constructor which sets all data fields to null.
AbstractionPolicy(Abstractor abs)
           
AbstractionPolicy(Abstractor[] abs)
           
AbstractionPolicy(java.util.Vector abstractors)
          Constructor that takes two parameters.
 
Method Summary
 void addAbstractor(Abstractor ab)
          Adds the given Abstractor to this policy.
 void addAll(Abstractor[] abs)
           
 boolean doAbstraction(Event e)
          This method loops through the abstractors that are installed in this policy.
 Metadata[][] getAllMetadata()
          Returns an array of Metadata arrays, one for each abstractor installed in abstractors.
 Metadata[] getFirstMetadata()
          Returns an array of the first Metadata for each abstractor installed in abstractors.
 void run()
          Processing loop that periodically checks the inQ for new events to be processed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inQ

public EventPriorityQueue inQ
This is the queue that houses incoming events to be processed by this policy.


outQ

public EventPriorityQueue outQ
This is the queue where the policy places processed events.


h

public History h
All abstraction 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.


add_to_history

public boolean add_to_history
Flag used to indicate whether this policy should add its processed event to its history queue (see history queue above)

Constructor Detail

AbstractionPolicy

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


AbstractionPolicy

public AbstractionPolicy(Abstractor abs)

AbstractionPolicy

public AbstractionPolicy(Abstractor[] abs)

AbstractionPolicy

public AbstractionPolicy(java.util.Vector abstractors)
Constructor that takes two parameters. Used by PeripheralDisplay.

Parameters:
abstractors - Vector of abstractors 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

doAbstraction

public boolean doAbstraction(Event e)
This method loops through the abstractors that are installed in this policy. Calls doAbstract for each abstractor. The default is to loop through all the abstractors in order, passing the output event of one abstractor as input to the next abstractor.

Parameters:
e - The event that will be abstracted.
Returns:
boolean True/false indication of success/failure.

addAbstractor

public void addAbstractor(Abstractor ab)
Adds the given Abstractor to this policy. The new Abstractor will be the last Abstractor in the chain to be called in doAbstraction.

Parameters:
ab -

addAll

public void addAll(Abstractor[] abs)

getAllMetadata

public Metadata[][] getAllMetadata()
Returns an array of Metadata arrays, one for each abstractor installed in abstractors.

Returns:
Metadata[][]

getFirstMetadata

public Metadata[] getFirstMetadata()
Returns an array of the first Metadata for each abstractor installed in abstractors.

Returns:
Metadata[]

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 doAbstraction(). This method is called in between sleeping periods of Application.POLICY_SLEEP_TIME.

Specified by:
run in interface java.lang.Runnable
See Also:
Runnable.run()