edu.berkeley.guir.ptk.output
Class OutputPolicy

java.lang.Object
  extended byedu.berkeley.guir.ptk.PTK
      extended byedu.berkeley.guir.ptk.output.OutputPolicy
All Implemented Interfaces:
java.lang.Runnable

public class OutputPolicy
extends PTK
implements java.lang.Runnable

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

The method run() first starts all the Output threads running. When events arrive, it loops through the Outputs that are installed and asks them if they want the event The Outputs installed correspond to an array of Outputs or a single Output passed into a makeConnection call). Different instances of this class can have different Outputs installed. These control the devices that display data. Default for the run() method is to continue looping through all installed Outputs.

In run(), this policy determines if it should call an Output's handleEvent method by comparing the metadata of the event (and possibly data IDs) with the metadata (and possibly data IDs) the Output indicates it can display.

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

Author:
tmatthew Created: Mar 2, 2003

Field Summary
 EventPriorityQueue inQ
          This is the queue that houses incoming events to be processed by this policy.
protected  java.util.Vector outputs
          The outputs to which this policy will offer the event.
 EventPriorityQueue outQ
          This is the queue where the policy places processed events.
 
Fields inherited from class edu.berkeley.guir.ptk.PTK
debug, MAX_DEBUG, MED_DEBUG, MIN_DEBUG, NO_DEBUG
 
Constructor Summary
OutputPolicy()
          Default constructor which sets all data fields to null.
OutputPolicy(java.util.Vector outputs)
          Constructor that takes two parameters.
 
Method Summary
 void addOutput(Output out)
          Add an Output to this policy.
 Metadata[][] getAllMetadata()
          Returns an array of Metadata arrays, one for each output installed in outputs.
 Metadata[] getFirstMetadata()
          Returns an array of the first Metadata for each output installed in outputs.
 void run()
          Called once when the OutputPolicy thread is started.
protected  void sendEventToOutputs(Event[] new_events)
          Called by run to send the input events to the outputs.
 
Methods inherited from class edu.berkeley.guir.ptk.PTK
getMAX, getMED, getMIN, getNO, printDebug, printDebug, printError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

outputs

protected java.util.Vector outputs
The outputs to which this policy will offer the event. Outputs will be offered the event in the order they appear in the vector: index 0 first.


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. Given that this is the Output policy, this might be empty

Constructor Detail

OutputPolicy

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


OutputPolicy

public OutputPolicy(java.util.Vector outputs)
Constructor that takes two parameters.

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

sendEventToOutputs

protected void sendEventToOutputs(Event[] new_events)
Called by run to send the input events to the outputs. This default policy sends the event to every output that wants it by calling their handleEvent methods.


run

public void run()
Called once when the OutputPolicy thread is started. It starts all the output threads first. Then, it performs the periodic check on its in-queue. If there is an event, it is processed and put into the outQ. Processing for this policy involves calling processEvents(). 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()

getAllMetadata

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

Returns:
Metadata[][]

getFirstMetadata

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

Returns:
Metadata[]

addOutput

public void addOutput(Output out)
Add an Output to this policy.

Parameters:
out - The Output object to add.