org.bff.javampd.monitor
Class MPDStandAloneMonitor

java.lang.Object
  extended by org.bff.javampd.monitor.MPDEventMonitor
      extended by org.bff.javampd.monitor.MPDStandAloneMonitor
All Implemented Interfaces:
java.lang.Runnable

public class MPDStandAloneMonitor
extends MPDEventMonitor
implements java.lang.Runnable

MPDStandAloneMonitor monitors a MPD connection by querying the status and statistics of the MPD server at given delay intervals. As statistics change appropriate events are fired indicating these changes. If more detailed events are desired attach listeners to the different controllers of a connection or use the MPDEventRelayer class.


Nested Class Summary
static class MPDStandAloneMonitor.PlayerStatus
          The status of the player.
 
Constructor Summary
MPDStandAloneMonitor(MPD mpd)
          Creates a new instance of MPDStandAloneMonitor using the default delay of 1 second.
MPDStandAloneMonitor(MPD mpd, int delay)
          Creates a new instance of MPDStandAloneMonitor using the given delay interval for queries.
 
Method Summary
 void addMPDErrorListener(MPDErrorListener el)
          Adds a MPDErrorListener to this object to receive MPDErrorEvents.
 void addPlayerChangeListener(PlayerBasicChangeListener pcl)
          Adds a PlayerBasicChangeListener to this object to receive PlayerChangeEvents.
 void addPlaylistChangeListener(PlaylistBasicChangeListener pcl)
          Adds a PlaylistBasicChangeListener to this object to receive PlaylistChangeEvents.
 void addVolumeChangeListener(VolumeChangeListener vcl)
          Adds a VolumeChangeListener to this object to receive VolumeChangeEvents.
protected  void fireMPDErrorEvent(java.lang.String msg)
          Sends the appropriate MPDErrorListener to all registered MPDErrorListeners.
protected  void firePlayerChangeEvent(int id)
          Sends the appropriate PlayerBasicChangeEvent to all registered PlayerBasicChangeListeners.
protected  void firePlaylistChangeEvent(int id)
          Sends the appropriate PlaylistChangeEvent to all registered PlaylistChangeListener.
protected  void fireVolumeChangeEvent(int volume)
          Sends the appropriate VolumeChangeEvent to all registered VolumeChangeListener.
 MPDStandAloneMonitor.PlayerStatus getStatus()
          Returns the current status of the player.
 boolean isStopped()
          Returns true if the monitor is stopped, false if the monitor is still running.
 void removeMPDErrorListener(MPDErrorListener el)
          Removes a MPDErrorListener from this object.
 void removePlayerChangeListener(PlayerBasicChangeListener pcl)
          Removes a PlayerBasicChangeListener from this object.
 void removePlaylistStatusChangedListener(PlaylistBasicChangeListener pcl)
          Removes a PlaylistBasicChangeListener from this object.
 void removeVolumeChangedListener(VolumeChangeListener vcl)
          Removes a VolumeChangeListener from this object.
 void run()
          Implements the Runnable run method to monitor the MPD connection.
 void start()
          Starts the monitor by creating and starting a thread using this instance as the Runnable interface.
 void stop()
          Stops the thread.
 
Methods inherited from class org.bff.javampd.monitor.MPDEventMonitor
addConnectionChangeListener, addTrackPositionChangeListener, checkConnection, checkTrackPosition, fireConnectionChangeEvent, fireTrackPositionChangeEvent, removeConnectionChangeListener, removeTrackPositionChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MPDStandAloneMonitor

public MPDStandAloneMonitor(MPD mpd)
Creates a new instance of MPDStandAloneMonitor using the default delay of 1 second.

Parameters:
mpd - a connection to a MPD server

MPDStandAloneMonitor

public MPDStandAloneMonitor(MPD mpd,
                            int delay)
Creates a new instance of MPDStandAloneMonitor using the given delay interval for queries.

Parameters:
mpd - a connection to a MPD server
delay - the delay interval
Method Detail

addPlayerChangeListener

public void addPlayerChangeListener(PlayerBasicChangeListener pcl)
Adds a PlayerBasicChangeListener to this object to receive PlayerChangeEvents.

Parameters:
pcl - the PlayerBasicChangeListener to add

removePlayerChangeListener

public void removePlayerChangeListener(PlayerBasicChangeListener pcl)
Removes a PlayerBasicChangeListener from this object.

Parameters:
pcl - the PlayerBasicChangeListener to remove

firePlayerChangeEvent

protected void firePlayerChangeEvent(int id)
Sends the appropriate PlayerBasicChangeEvent to all registered PlayerBasicChangeListeners.

Parameters:
id - the event id to send

addVolumeChangeListener

public void addVolumeChangeListener(VolumeChangeListener vcl)
Adds a VolumeChangeListener to this object to receive VolumeChangeEvents.

Parameters:
vcl - the VolumeChangeListener to add

removeVolumeChangedListener

public void removeVolumeChangedListener(VolumeChangeListener vcl)
Removes a VolumeChangeListener from this object.

Parameters:
vcl - the VolumeChangeListener to remove

fireVolumeChangeEvent

protected void fireVolumeChangeEvent(int volume)
Sends the appropriate VolumeChangeEvent to all registered VolumeChangeListener.

Parameters:
volume - the new volume

addPlaylistChangeListener

public void addPlaylistChangeListener(PlaylistBasicChangeListener pcl)
Adds a PlaylistBasicChangeListener to this object to receive PlaylistChangeEvents.

Parameters:
pcl - the PlaylistChangeListener to add

removePlaylistStatusChangedListener

public void removePlaylistStatusChangedListener(PlaylistBasicChangeListener pcl)
Removes a PlaylistBasicChangeListener from this object.

Parameters:
pcl - the PlaylistBasicChangeListener to remove

firePlaylistChangeEvent

protected void firePlaylistChangeEvent(int id)
Sends the appropriate PlaylistChangeEvent to all registered PlaylistChangeListener.

Parameters:
id - the event id to send

addMPDErrorListener

public void addMPDErrorListener(MPDErrorListener el)
Adds a MPDErrorListener to this object to receive MPDErrorEvents.

Parameters:
el - the MPDErrorListener to add

removeMPDErrorListener

public void removeMPDErrorListener(MPDErrorListener el)
Removes a MPDErrorListener from this object.

Parameters:
el - the MPDErrorListener to remove

fireMPDErrorEvent

protected void fireMPDErrorEvent(java.lang.String msg)
Sends the appropriate MPDErrorListener to all registered MPDErrorListeners.

Parameters:
msg - the event message

run

public void run()
Implements the Runnable run method to monitor the MPD connection.

Specified by:
run in interface java.lang.Runnable

start

public void start()
Starts the monitor by creating and starting a thread using this instance as the Runnable interface.


stop

public void stop()
Stops the thread.


isStopped

public boolean isStopped()
Returns true if the monitor is stopped, false if the monitor is still running.

Returns:
true if monitor is running, false otherwise false

getStatus

public MPDStandAloneMonitor.PlayerStatus getStatus()
Returns the current status of the player.

Returns:
the status of the player