com.bluemarsh.jswat.breakpoint
Class BreakpointManager

java.lang.Object
  |
  +--com.bluemarsh.jswat.DefaultManager
        |
        +--com.bluemarsh.jswat.breakpoint.BreakpointManager
All Implemented Interfaces:
java.util.EventListener, Manager, SessionListener, VMEventListener

public class BreakpointManager
extends DefaultManager
implements VMEventListener

Class BreakpointManager defines is responsible for managing groups of breakpoints. It does not contain any breakpoints directly, but rather contains the groups which contain the breakpoints. The breakpoint manager acts as a factory for creating all types of breakpoints.

The breakpoint manager contains a breakpoint group called "Default". This default breakpoint group takes all the new breakpoints that are not associated with any other group.

Author:
Nathan Fiedler

Field Summary
protected  com.bluemarsh.util.IntHashtable breakpointsTable
          Table of all breakpoints, keyed by a unique number.
protected  BreakpointGroup defaultGroup
          The default breakpoint group, into which all new groups and breakpoints will go by default.
protected  com.sun.jdi.request.EventRequestManager eventManager
          The EventRequestManager for this session.
protected  int lastBreakpointNumber
          Value representing the last number assigned to a new breakpoint.
protected  com.bluemarsh.util.EventListenerList listeners
          List of breakpoint listeners.
protected  boolean listeningForClassPrepare
          If true, indicates we are presently listening for class prepare events from the debuggee VM.
protected static Category logCategory
          Reporting category.
protected  Session owningSession
          Session that owns this breakpoint manager.
 
Fields inherited from class com.bluemarsh.jswat.DefaultManager
swat
 
Fields inherited from interface com.bluemarsh.jswat.event.VMEventListener
PRIORITY_BREAKPOINT, PRIORITY_DEFAULT, PRIORITY_HIGH, PRIORITY_HIGHEST, PRIORITY_LOW, PRIORITY_LOWEST, PRIORITY_SESSION
 
Constructor Summary
BreakpointManager()
          Creates a BreakpointManager with the default parameters.
 
Method Summary
 void activate(Session session)
          Ready this breakpoint manager for handling breakpoint requests.
 void addBreakListener(BreakpointListener listener)
          Add a breakpoint listener to this manager object.
 void addBreakpoint(Breakpoint bp)
          Adds the given breakpoint to this breakpoint group.
 void addGroupListener(GroupListener listener)
          Add a breakpoint group listener to this manager object.
 void addNewBreakpoint(Breakpoint bp)
          Adds the given breakpoint to this breakpoint group and initializes and resolves it.
 int breakpointCount(boolean recurse)
          Returns a count of the breakpoints under this manager.
 java.util.Iterator breakpoints(boolean recurse)
          Returns an iterator over the set of breakpoints under this manager.
 void close(Session session)
          Called when the Session is about to close down.
 Breakpoint createBreakpoint(java.lang.String classPattern, int line)
          Creates a Breakpoint to stop at the specified line within the specified class.
 Breakpoint createBreakpoint(java.lang.String classPattern, java.lang.String methodId, java.util.List methodArgs)
          Creates a Breakpoint to stop at the specified method within the specified class.
 BreakpointGroup createBreakpointGroup(java.lang.String name)
          Creates a new breakpoint group and adds it to this manager.
 BreakpointGroup createBreakpointGroup(java.lang.String name, BreakpointGroup parent)
          Creates a new breakpoint group and adds it to the given breakpoint group.
 void createExceptionCatch()
          Creates a Breakpoint to stop when any uncaught exception is thrown.
 Breakpoint createExceptionCatch(java.lang.String classPattern)
          Creates a Breakpoint to stop when the specified exception occurs.
 void deactivate(Session session)
          Prepare the breakpoint manager for disconnection from the virtual machine we're debugging.
 void disableBreakpoint(Breakpoint bp)
          Disables the given breakpoint and notifies any listeners.
 void disableBreakpointGroup(BreakpointGroup group)
          Disables the given breakpoint group and notifies any listeners.
 void enableBreakpoint(Breakpoint bp)
          Enables the given breakpoint and notifies any listeners.
 void enableBreakpointGroup(BreakpointGroup group)
          Enables the given breakpoint group and notifies any listeners.
 boolean eventOccurred(com.sun.jdi.event.Event e)
          Invoked when a VM event has occurred.
protected  void fireChange(Breakpoint bp, int type)
          Let all the change listeners know of a recent change in the breakpoints.
protected  void fireGroupChange(BreakpointGroup group, int type)
          Let all the group change listeners know of a recent change in the breakpoint groups.
 Breakpoint getBreakpoint(int n)
          Retrieve the nth breakpoint.
 Breakpoint getBreakpoint(com.sun.jdi.ReferenceType cls, int line)
          Look through the existing breakpoints to see if there is one with the given class type and line number.
 int getBreakpointNumber(Breakpoint bp)
          Retrieve the number assigned to the given breakpoint.
 BreakpointGroup getDefaultGroup()
          Returns the default breakpoint group.
 java.util.Iterator groups(boolean recurse)
          Returns an iterator over the set of groups under this manager.
 void init(Session session)
          Called after the Session has instantiated this mananger.
protected  void listenForClassPrepareEvents()
          Listen to all class prepare events.
 Breakpoint parseBreakpointSpec(com.bluemarsh.util.StringTokenizer tokenizer)
          Try to parse the given user breakpoint specification into it's component parts and create a Breakpoint object.
 void removeBreakListener(BreakpointListener listener)
          Remove a break listener from the listener list.
 void removeBreakpoint(Breakpoint bp)
          Removes the given breakpoint from this breakpoint manager.
 void removeBreakpointGroup(BreakpointGroup group)
          Removes the given breakpoint group from this breakpoint manager.
 void removeGroupListener(GroupListener listener)
          Remove a breakpoint group listener from the listener list.
 void resolveBreakpoint(ResolvableBreakpoint bp)
          Try to resolve the given breakpoint.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logCategory

protected static Category logCategory
Reporting category.

eventManager

protected com.sun.jdi.request.EventRequestManager eventManager
The EventRequestManager for this session.

listeners

protected com.bluemarsh.util.EventListenerList listeners
List of breakpoint listeners.

owningSession

protected Session owningSession
Session that owns this breakpoint manager.

listeningForClassPrepare

protected boolean listeningForClassPrepare
If true, indicates we are presently listening for class prepare events from the debuggee VM.

defaultGroup

protected BreakpointGroup defaultGroup
The default breakpoint group, into which all new groups and breakpoints will go by default.

breakpointsTable

protected com.bluemarsh.util.IntHashtable breakpointsTable
Table of all breakpoints, keyed by a unique number. The number is assigned at the time the breakpoint is created and will be unique among the set of breakpoints.
See Also:
lastBreakpointNumber

lastBreakpointNumber

protected int lastBreakpointNumber
Value representing the last number assigned to a new breakpoint. Used to key breakpoints in a table so they may be referred to by a unique number.
See Also:
breakpointsTable
Constructor Detail

BreakpointManager

public BreakpointManager()
Creates a BreakpointManager with the default parameters.
Method Detail

activate

public void activate(Session session)
Ready this breakpoint manager for handling breakpoint requests.
Overrides:
activate in class DefaultManager
Parameters:
session - Session being activated.

addBreakListener

public void addBreakListener(BreakpointListener listener)
Add a breakpoint listener to this manager object.
Parameters:
listener - new listener to add notification list

addBreakpoint

public void addBreakpoint(Breakpoint bp)
Adds the given breakpoint to this breakpoint group.
Parameters:
bp - breakpoint to add.

addGroupListener

public void addGroupListener(GroupListener listener)
Add a breakpoint group listener to this manager object.
Parameters:
listener - new listener to add notification list

addNewBreakpoint

public void addNewBreakpoint(Breakpoint bp)
                      throws ResolveException
Adds the given breakpoint to this breakpoint group and initializes and resolves it.
Parameters:
bp - breakpoint to add.
Throws:
ResolveException - Thrown if error resolving breakpoint.

breakpointCount

public int breakpointCount(boolean recurse)
Returns a count of the breakpoints under this manager.
Parameters:
recurse - true to include subgroup counts, false to ignore subgroups.
Returns:
number of breakpoints.

breakpoints

public java.util.Iterator breakpoints(boolean recurse)
Returns an iterator over the set of breakpoints under this manager.
Parameters:
recurse - true to recurse through all the groups.
Returns:
Iterator over the breakpoints.

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.

createBreakpoint

public Breakpoint createBreakpoint(java.lang.String classPattern,
                                   int line)
                            throws java.lang.ClassNotFoundException,
                                   ResolveException
Creates a Breakpoint to stop at the specified line within the specified class. The class name pattern may have a wildcard (asterisk, *) at either the beginning or end.
Parameters:
classPattern - class name pattern.
line - line within class at which to stop.
Returns:
new Breakpoint.
Throws:
java.lang.ClassNotFoundException - Thrown if the class pattern was invalid.
ResolveException - Thrown if error resolving breakpoint request.

createBreakpoint

public Breakpoint createBreakpoint(java.lang.String classPattern,
                                   java.lang.String methodId,
                                   java.util.List methodArgs)
                            throws java.lang.ClassNotFoundException,
                                   MalformedMemberNameException,
                                   ResolveException
Creates a Breakpoint to stop at the specified method within the specified class. The class name pattern may have a wildcard (asterisk, *) at either the beginning or end.
Parameters:
classPattern - class name pattern.
methodId - name of method.
methodArgs - list of argument types in method.
Returns:
new Breakpoint.
Throws:
java.lang.ClassNotFoundException - Thrown if the class pattern was invalid.
ResolveException - Thrown if error resolving breakpoint request.

createBreakpointGroup

public BreakpointGroup createBreakpointGroup(java.lang.String name)
Creates a new breakpoint group and adds it to this manager.
Parameters:
name - new breakpoint group's name.

createBreakpointGroup

public BreakpointGroup createBreakpointGroup(java.lang.String name,
                                             BreakpointGroup parent)
Creates a new breakpoint group and adds it to the given breakpoint group.
Parameters:
name - new breakpoint group's name.
parent - parent breakpoint group.

createExceptionCatch

public Breakpoint createExceptionCatch(java.lang.String classPattern)
                                throws java.lang.ClassNotFoundException,
                                       ResolveException
Creates a Breakpoint to stop when the specified exception occurs. The exception class name pattern may have a wildcard (asterisk, *) at either the beginning or end.
Parameters:
classPattern - name of the exception to catch.
Returns:
new Breakpoint.
Throws:
java.lang.ClassNotFoundException - Thrown if the class pattern was invalid.
ResolveException - Thrown if error resolving breakpoint request.

createExceptionCatch

public void createExceptionCatch()
Creates a Breakpoint to stop when any uncaught exception is thrown. This breakpoint is never added to the default breakpoint group, nor is it necessary for it to be resolved. In fact, for all intents and purposes, this breakpoint won't really exist. It won't be persisted nor will it be customizable.
Throws:
java.lang.IllegalStateException - Thrown if the session is not currently active.

deactivate

public void deactivate(Session session)
Prepare the breakpoint manager for disconnection from the virtual machine we're debugging. This means dropping the association with the EventRequestManager given in the activate method.
Overrides:
deactivate in class DefaultManager
Parameters:
session - Session being deactivated.

disableBreakpoint

public void disableBreakpoint(Breakpoint bp)
Disables the given breakpoint and notifies any listeners.
Parameters:
bp - Breakpoint to disable.

disableBreakpointGroup

public void disableBreakpointGroup(BreakpointGroup group)
Disables the given breakpoint group and notifies any listeners.
Parameters:
group - breakpoint group to disable.

enableBreakpoint

public void enableBreakpoint(Breakpoint bp)
Enables the given breakpoint and notifies any listeners.
Parameters:
bp - Breakpoint to enable.

enableBreakpointGroup

public void enableBreakpointGroup(BreakpointGroup group)
Enables the given breakpoint group and notifies any listeners.
Parameters:
group - breakpoint group to enable.

eventOccurred

public boolean eventOccurred(com.sun.jdi.event.Event e)
Invoked when a VM event has occurred.
Specified by:
eventOccurred in interface VMEventListener
Parameters:
e - VM event (class prepare event)
Returns:
true if debuggee VM should be resumed, false otherwise.

fireChange

protected void fireChange(Breakpoint bp,
                          int type)
Let all the change listeners know of a recent change in the breakpoints. This creates a BreakpointEvent object and sends it out to the listeners.
Parameters:
bp - breakpoint
type - breakpoint event type

fireGroupChange

protected void fireGroupChange(BreakpointGroup group,
                               int type)
Let all the group change listeners know of a recent change in the breakpoint groups. This creates a GroupEvent object and sends it out to the listeners.
Parameters:
group - breakpoint group.
type - breakpoint group event type.

getBreakpoint

public Breakpoint getBreakpoint(com.sun.jdi.ReferenceType cls,
                                int line)
Look through the existing breakpoints to see if there is one with the given class type and line number. If a match is found, this method returns the breakpoint; otherwise it returns null.
Parameters:
cls - class type.
line - line number.
Returns:
Breakpoint, or null if none were found.

getBreakpoint

public Breakpoint getBreakpoint(int n)
Retrieve the nth breakpoint. Each and every breakpoint managed by this breakpoint manager has a unique, invariant number assigned to it. The breakpoints can be retrieved by referring to this number.
Parameters:
n - breakpoint number.
Returns:
Breakpoint, or null if there was no breakpoint referenced by the n value.

getBreakpointNumber

public int getBreakpointNumber(Breakpoint bp)
Retrieve the number assigned to the given breakpoint. Each and every breakpoint managed by this breakpoint manager has a unique, invariant number assigned to it. The breakpoints can be retrieved by referring to this number.
Parameters:
bp - breakpoint.
Returns:
number assigned to this breakpoint.

getDefaultGroup

public BreakpointGroup getDefaultGroup()
Returns the default breakpoint group.
Returns:
"default" breakpoint group.

groups

public java.util.Iterator groups(boolean recurse)
Returns an iterator over the set of groups under this manager.
Parameters:
recurse - true to iterate over all subgroups.
Returns:
Iterator over the groups.

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.

listenForClassPrepareEvents

protected void listenForClassPrepareEvents()
Listen to all class prepare events.

parseBreakpointSpec

public Breakpoint parseBreakpointSpec(com.bluemarsh.util.StringTokenizer tokenizer)
                               throws java.lang.ClassNotFoundException,
                                      java.lang.IllegalArgumentException,
                                      MalformedMemberNameException,
                                      java.lang.NumberFormatException,
                                      ResolveException
Try to parse the given user breakpoint specification into it's component parts and create a Breakpoint object.
Parameters:
tokenizer - String tokenizer to parse.
Returns:
a new Breakpoint.
Throws:
java.lang.ClassNotFoundException - Thrown if class name is invalid or missing.
java.lang.IllegalArgumentException - Thrown if specification is missing.
MalformedMemberNameException - Thrown if method name is invalid or missing.
java.lang.NumberFormatException - Thrown if line number is invalid or missing.
ResolveException - Thrown if there was a problem resolving the breakpoint.

removeBreakListener

public void removeBreakListener(BreakpointListener listener)
Remove a break listener from the listener list.
Parameters:
listener - listener to remove from notification list

removeBreakpoint

public void removeBreakpoint(Breakpoint bp)
Removes the given breakpoint from this breakpoint manager. This results in the breakpoint being effectively unreachable, as well as disabled. Fires a breakpoint removed event to all the listeners.
Parameters:
bp - breakpoint to remove.

removeBreakpointGroup

public void removeBreakpointGroup(BreakpointGroup group)
Removes the given breakpoint group from this breakpoint manager. This results in all of the child groups and breakpoints contained therein to be removed as well. Fires breakpoint removed events for all affected breakpoints.
Parameters:
group - breakpoint group to remove.
Throws:
java.lang.IllegalArgumentException - Thrown if the group is the default group.

removeGroupListener

public void removeGroupListener(GroupListener listener)
Remove a breakpoint group listener from the listener list.
Parameters:
listener - listener to remove from notification list

resolveBreakpoint

public void resolveBreakpoint(ResolvableBreakpoint bp)
                       throws ResolveException
Try to resolve the given breakpoint.
Parameters:
bp - breakpoint to be resolved.
Throws:
ResolveException - Thrown if error resolving breakpoint.