com.bluemarsh.jswat.event
Class VMEventManager

java.lang.Object
  |
  +--com.bluemarsh.jswat.DefaultManager
        |
        +--com.bluemarsh.jswat.event.VMEventManager
All Implemented Interfaces:
Manager, java.lang.Runnable, SessionListener

public class VMEventManager
extends DefaultManager
implements java.lang.Runnable

This class is responsible for maintaining a list of all the objects interested in events sent from the back-end of the JPDA debugger. Listeners registered for VM events are listed according to the event they are interested in. Within each of these lists the listeners are sorted in priority order. Those with a higher priority will be notified of the event before those of a lower priority.

Author:
Nathan Fiedler

Field Summary
protected  com.sun.jdi.event.EventQueue eventQueue
          VM event queue.
protected  java.lang.Object[] listenerList
          The list of event class-listener pairs.
protected static Category logCategory
          Reporting category.
protected static java.lang.Object[] NULL_ARRAY
          A null array to be shared by all empty listener lists.
protected  Session owningSession
          Owning session.
protected  java.lang.Thread runningThread
          Thread running this runnable object.
protected  boolean vmConnected
          True if we are connected to the debuggee VM.
 
Fields inherited from class com.bluemarsh.jswat.DefaultManager
swat
 
Constructor Summary
VMEventManager()
          Creates a new VMEventManager object.
 
Method Summary
 void activate(Session session)
          Called when the Session is about to begin an active debugging session.
 void addListener(java.lang.Class event, VMEventListener listener, int priority)
          Adds the given listener as a listener for events of the given type.
 void close(Session session)
          Called when the Session is about to close down.
 void deactivate(Session session)
          Called when the Session is about to end an active debugging session.
protected  com.bluemarsh.adt.PriorityList getList(java.lang.Object event)
          Get the priority list matching the given event.
 void init(Session session)
          Called after the Session has instantiated this mananger.
protected  boolean processEvent(com.sun.jdi.event.Event event, com.bluemarsh.adt.PriorityList listeners)
          Send the given event to the listeners on the list.
protected  void processExitEvents()
          A VMDisconnectedException has happened while dealing with another event.
 void removeListener(java.lang.Class event, VMEventListener listener)
          Removes the given listener from the event listener list.
 void run()
          Start waiting for events from the back-end of the JPDA debugger.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL_ARRAY

protected static final java.lang.Object[] NULL_ARRAY
A null array to be shared by all empty listener lists.

logCategory

protected static Category logCategory
Reporting category.

eventQueue

protected com.sun.jdi.event.EventQueue eventQueue
VM event queue.

runningThread

protected java.lang.Thread runningThread
Thread running this runnable object.

vmConnected

protected boolean vmConnected
True if we are connected to the debuggee VM.

owningSession

protected Session owningSession
Owning session.

listenerList

protected java.lang.Object[] listenerList
The list of event class-listener pairs.
Constructor Detail

VMEventManager

public VMEventManager()
Creates a new VMEventManager object.
Method Detail

activate

public void activate(Session session)
Called when the Session is about to begin an active debugging session. That is, JSwat is about to debug a debuggee VM. Managers are not activated in any particular order.
Overrides:
activate in class DefaultManager
Parameters:
session - Session being activated.

addListener

public void addListener(java.lang.Class event,
                        VMEventListener listener,
                        int priority)
Adds the given listener as a listener for events of the given type. When an event of type event occurs, all registered listeners for that type will be notified.
Parameters:
event - VM event to listen for.
listener - Listener to add for event.
priority - Priority for this listener (1-255), where higher values give higher priority.
Throws:
java.lang.IllegalArgumentException - Thrown if listener is null or priority out of bounds.

close

public void close(Session session)
Called when the Session is about to close down.
Overrides:
close in class DefaultManager
Parameters:
session - Session being closed.

deactivate

public void deactivate(Session session)
Called when the Session is about to end an active debugging session. That is, JSwat is about to terminate the connection with the debuggee VM. Managers are not deactivated in any particular order.
Overrides:
deactivate in class DefaultManager
Parameters:
session - Session being deactivated.

getList

protected com.bluemarsh.adt.PriorityList getList(java.lang.Object event)
Get the priority list matching the given event. Checks the event's class and whether it "is an instance of" any of the events in our list.
Parameters:
event - VM event to find in list.
Returns:
PriorityList if found, or null.

init

public void init(Session session)
Called after the Session has instantiated this mananger. To avoid problems with circular dependencies between managers, iniitialize data members before calling Session.getManager().
Overrides:
init in class DefaultManager
Parameters:
session - Session initializing this manager.

processEvent

protected boolean processEvent(com.sun.jdi.event.Event event,
                               com.bluemarsh.adt.PriorityList listeners)
Send the given event to the listeners on the list. The listeners are notified in order of the priority enforced by the list.
Parameters:
event - event to process.
listeners - list of listeners to handle event.
Returns:
true to resume VM, false to suspend VM.

processExitEvents

protected void processExitEvents()
A VMDisconnectedException has happened while dealing with another event. We need to flush the event queue, dealing only with exit events (VMDeath, VMDisconnect) so that we allow the listeners to clean up.

removeListener

public void removeListener(java.lang.Class event,
                           VMEventListener listener)
Removes the given listener from the event listener list.
Parameters:
event - VM event to listen for.
listener - Listener to remove from list.

run

public void run()
Start waiting for events from the back-end of the JPDA debugger. When events occur the notifications will be sent out to all of the registered listeners. This thread dies automatically when the debuggee VM disconnects from the debugger.
Specified by:
run in interface java.lang.Runnable
See Also:
activate(com.bluemarsh.jswat.Session), deactivate(com.bluemarsh.jswat.Session)