com.mtp.pounder
Class Player

java.lang.Object
  |
  +--com.mtp.pounder.Player
All Implemented Interfaces:
KeyEventDispatcher, PounderConstants

public class Player
extends Object
implements PounderConstants, KeyEventDispatcher

Plays a Pounder script. Has several options for controlling the playback.

Author:
Matthew Pekar
See Also:
WindowWatcher, PounderPrefs

Field Summary
protected  ClassLoader classLoader
          ClassLoader used to instantiate test objects.
protected  boolean disposeWindows
          Whether to dispose windows when playback has ended.
protected  boolean paused
          Whether the playback is paused.
protected  PounderPrefs prefs
          Preferences to determine how the playback operates.
protected  RecordingRecord record
          Record of items to play.
protected  boolean stopRequested
          Whether a stop has been requested.
protected  TestInstanceFactory testInstanceFactory
          TestInstanceFactory used to manage test object.
protected  WindowWatcher windowWatcher
           
 
Fields inherited from interface com.mtp.pounder.PounderConstants
FILE_EXTENSION, FILE_FORMAT_VERSION, VERSION
 
Constructor Summary
Player(InputStream script, ClassLoader cl)
          Construct with data from script stored on given InputStream.
Player(PounderModel pm)
          Construct with given PounderModel.
Player(PounderModel pm, ClassLoader cl)
          Construct with given PounderModel.
Player(PounderPrefs prefs, TestInstanceFactory tif, RecordingRecord record, ClassLoader cl)
          Use given preferences to configure playback.
Player(String script)
          Construct with data from given script.
Player(String scriptFile, ClassLoader cl)
          Construct with data from script stored in given File.
Player(URL script)
          Construct with data from given script.
Player(URL script, ClassLoader cl)
          Construct with data from given script.
 
Method Summary
protected  void addStopShortcutListener()
          Add ourselves a keyboard listener for the stop shortcut.
protected  Object buildTestObject()
          Build Object used for playback.
protected  WindowWatcher buildWindowWatcher()
          Return a new WindowWatcher for playback.
protected  boolean checkStopRequested(BoundedRangeModel rm)
          Return true if stop was requested.
protected  void clearEventQueue()
          Make sure the system event queue is empty before returning.
 boolean dispatchKeyEvent(KeyEvent e)
          Inherited from KeyEventDispatcher.
protected  void doDelayWhileCheckingForStop(long amount)
          Delay for given amount, but do it fine grained; checking if stop is requested along the way.
protected  int getTotalDelay()
          Return the total delay for our RecordingItem's.
protected  void init(PounderPrefs prefs, TestInstanceFactory tif, RecordingRecord record, ClassLoader cl)
          Initializer member varaiables.
protected  void initRangeModel(BoundedRangeModel rm)
           
 boolean isPaused()
           
 Object play()
          Play and return created test object.
 Object play(BoundedRangeModel rm)
          Playback the script and update the given range model.
protected  void playbackEnded(BoundedRangeModel rm)
          Function called when playback has ended.
protected  void playItem(RecordingItem item)
          Calls playback on the given item with the given WindowWatcher.
protected  void playItem(RecordingItem item, int attempts)
          Calls playback on the given item.
protected  void removeStopShortcutListener()
          Remvoe ourselves a keyboard listener for the stop shortcut.
 void setDisposeWindows(boolean b)
          Set whether to dispose of windows at end of playback.
 void setFailedPlaybackDelay(long d)
          Shortcut that calls setFailedPlaybackDelay() on my PounderPrefs.
 void setItemDelayEnabled(boolean b)
          Shortcut that calls setItemDelayEnabled() on my PounderPrefs.
 void setPaused(boolean b)
           
 void setPlaybackAttempts(int count)
          Shortcut that calls setPlaybackAttempts() on my PounderPrefs.
 void setStopRequested(boolean b)
          If true, will stop as soon as possible.
protected  void sleepWhilePaused()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

prefs

protected PounderPrefs prefs
Preferences to determine how the playback operates.


classLoader

protected ClassLoader classLoader
ClassLoader used to instantiate test objects.


testInstanceFactory

protected TestInstanceFactory testInstanceFactory
TestInstanceFactory used to manage test object.


record

protected RecordingRecord record
Record of items to play.


stopRequested

protected volatile boolean stopRequested
Whether a stop has been requested.


disposeWindows

protected boolean disposeWindows
Whether to dispose windows when playback has ended.


paused

protected volatile boolean paused
Whether the playback is paused.


windowWatcher

protected WindowWatcher windowWatcher
Constructor Detail

Player

public Player(PounderModel pm)
Construct with given PounderModel. Use our ClassLoader to load test object.


Player

public Player(PounderModel pm,
              ClassLoader cl)
Construct with given PounderModel. Use given ClassLoader to load test object.


Player

public Player(String script)
       throws Exception
Construct with data from given script. Use our ClassLoader to load test object.


Player

public Player(URL script)
       throws Exception
Construct with data from given script. Use our ClassLoader to load test object.


Player

public Player(URL script,
              ClassLoader cl)
       throws Exception
Construct with data from given script. Use given ClassLoader to load test object.


Player

public Player(String scriptFile,
              ClassLoader cl)
       throws Exception
Construct with data from script stored in given File. Use given ClassLoader to load test object.


Player

public Player(InputStream script,
              ClassLoader cl)
       throws Exception
Construct with data from script stored on given InputStream. Use given ClassLoader to load test object, or Class ClassLoader if null is passed.


Player

public Player(PounderPrefs prefs,
              TestInstanceFactory tif,
              RecordingRecord record,
              ClassLoader cl)
Use given preferences to configure playback. Use given TestInstanceFactory to manage the test object. Play items in given RecordingRecord. Use given ClassLoader to load test object.

Method Detail

init

protected void init(PounderPrefs prefs,
                    TestInstanceFactory tif,
                    RecordingRecord record,
                    ClassLoader cl)
Initializer member varaiables.


setItemDelayEnabled

public void setItemDelayEnabled(boolean b)
Shortcut that calls setItemDelayEnabled() on my PounderPrefs.


setPlaybackAttempts

public void setPlaybackAttempts(int count)
Shortcut that calls setPlaybackAttempts() on my PounderPrefs.


setFailedPlaybackDelay

public void setFailedPlaybackDelay(long d)
Shortcut that calls setFailedPlaybackDelay() on my PounderPrefs.


setDisposeWindows

public void setDisposeWindows(boolean b)
Set whether to dispose of windows at end of playback.


setStopRequested

public void setStopRequested(boolean b)
If true, will stop as soon as possible.


getTotalDelay

protected int getTotalDelay()
Return the total delay for our RecordingItem's.


buildTestObject

protected Object buildTestObject()
                          throws PlaybackException
Build Object used for playback.

PlaybackException

play

public Object play()
            throws PlaybackException
Play and return created test object.

PlaybackException

clearEventQueue

protected void clearEventQueue()
Make sure the system event queue is empty before returning.


addStopShortcutListener

protected void addStopShortcutListener()
Add ourselves a keyboard listener for the stop shortcut.


removeStopShortcutListener

protected void removeStopShortcutListener()
Remvoe ourselves a keyboard listener for the stop shortcut.


dispatchKeyEvent

public boolean dispatchKeyEvent(KeyEvent e)
Inherited from KeyEventDispatcher. We check if it's the stop shorcut.

Specified by:
dispatchKeyEvent in interface KeyEventDispatcher

doDelayWhileCheckingForStop

protected void doDelayWhileCheckingForStop(long amount)
Delay for given amount, but do it fine grained; checking if stop is requested along the way.


buildWindowWatcher

protected WindowWatcher buildWindowWatcher()
Return a new WindowWatcher for playback.


initRangeModel

protected void initRangeModel(BoundedRangeModel rm)

setPaused

public void setPaused(boolean b)

isPaused

public boolean isPaused()

play

public Object play(BoundedRangeModel rm)
            throws PlaybackException
Playback the script and update the given range model. Return created test object.

PlaybackException

checkStopRequested

protected boolean checkStopRequested(BoundedRangeModel rm)
Return true if stop was requested. If stop requested, perform necessary cleanup before returning.


playbackEnded

protected void playbackEnded(BoundedRangeModel rm)
Function called when playback has ended. Destroys TestInstanceFactory and disconnects WindowWatcher. Clears given BoundedRangeModel.


sleepWhilePaused

protected void sleepWhilePaused()

playItem

protected void playItem(RecordingItem item)
                 throws Throwable
Calls playback on the given item with the given WindowWatcher. Will pause if needed.

Throwable

playItem

protected void playItem(RecordingItem item,
                        int attempts)
                 throws Throwable
Calls playback on the given item. Will attempt to play multiple times if errors occur.

Parameters:
attempts - The number of times to attempt playback if failures occur.
Throwable


Copyright © 2002 Matthew Pekar. All Rights Reserved.