edu.rice.cs.drjava.model.debug.jpda
Class EventHandlerThread

java.lang.Object
  extended by java.lang.Thread
      extended by edu.rice.cs.drjava.model.debug.jpda.EventHandlerThread
All Implemented Interfaces:
Runnable

public class EventHandlerThread
extends Thread

A thread that listens and responds to events from JPDA when the debugger has attached to another JVM.

Version:
$Id: EventHandlerThread.java 5442 2011-08-16 09:11:12Z rcartwright $

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
private  boolean _connected
          Whether this event handler is currently connected to the JPDA VirtualMachine.
private  JPDADebugger _debugger
          Debugger to which this class reports events.
private static Log _log
          A log for recording messages in a file.
private  com.sun.jdi.VirtualMachine _vm
          JPDA reference to the VirtualMachine generating the events.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
EventHandlerThread(JPDADebugger debugger, com.sun.jdi.VirtualMachine vm)
          Creates a new EventHandlerThread to listen to events from the given debugger and virtual machine.
 
Method Summary
private  void _cleanUp(com.sun.jdi.event.Event e)
          Cleans up the state after the virtual machine being debugged dies or disconnects.
private  void _handleBreakpointEvent(com.sun.jdi.event.BreakpointEvent e)
          Responds to a breakpoint event.
private  void _handleClassPrepareEvent(com.sun.jdi.event.ClassPrepareEvent e)
          Responds when a class of interest has been prepared.
private  void _handleStepEvent(com.sun.jdi.event.StepEvent e)
          Responds to a step event.
private  void _handleThreadDeathEvent(com.sun.jdi.event.ThreadDeathEvent e)
          Reponds to a thread death event.
private  void _handleThreadStartEvent(com.sun.jdi.event.ThreadStartEvent e)
          Responds to a thread start event.
private  void _handleVMDeathEvent(com.sun.jdi.event.VMDeathEvent e)
          Responds if the virtual machine being debugged dies.
private  void _handleVMDisconnectEvent(com.sun.jdi.event.VMDisconnectEvent e)
          Responds if the virtual machine being debugged disconnects.
private  boolean _isSuspendedWithFrames(com.sun.jdi.ThreadReference thread)
          Returns whether the given thread is both suspended and has stack frames.
private  void _log(String message)
          Logs any unexpected behavior that occurs (but which should not cause DrJava to abort).
private  void _log(String message, Throwable t)
          Logs any unexpected behavior that occurs (but which should not cause DrJava to abort).
private  void handleDisconnectedException()
          Responds when a VMDisconnectedException occurs while dealing with another event.
private  void handleEvent(com.sun.jdi.event.Event e)
          Processes a given event from JPDA.
 void run()
          Continually consumes events from the VM's event queue until it is disconnected.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_debugger

private final JPDADebugger _debugger
Debugger to which this class reports events.


_vm

private final com.sun.jdi.VirtualMachine _vm
JPDA reference to the VirtualMachine generating the events.


_connected

private volatile boolean _connected
Whether this event handler is currently connected to the JPDA VirtualMachine.


_log

private static final Log _log
A log for recording messages in a file.

Constructor Detail

EventHandlerThread

EventHandlerThread(JPDADebugger debugger,
                   com.sun.jdi.VirtualMachine vm)
Creates a new EventHandlerThread to listen to events from the given debugger and virtual machine. Calling this Thread's start() method causes it to begin listenting.

Parameters:
debugger - Debugger to which to report events
vm - JPDA reference to the VirtualMachine generating the events
Method Detail

_log

private void _log(String message)
Logs any unexpected behavior that occurs (but which should not cause DrJava to abort).

Parameters:
message - message to print to the log

_log

private void _log(String message,
                  Throwable t)
Logs any unexpected behavior that occurs (but which should not cause DrJava to abort).

Parameters:
message - message to print to the log
t - Exception or Error being logged

run

public void run()
Continually consumes events from the VM's event queue until it is disconnected.

Specified by:
run in interface Runnable
Overrides:
run in class Thread

handleEvent

private void handleEvent(com.sun.jdi.event.Event e)
                  throws DebugException
Processes a given event from JPDA. A visitor approach would be much better for this, but Sun's Event class doesn't have an appropriate visit() method.

Throws:
DebugException

_isSuspendedWithFrames

private boolean _isSuspendedWithFrames(com.sun.jdi.ThreadReference thread)
                                throws DebugException
Returns whether the given thread is both suspended and has stack frames.

Throws:
DebugException

_handleBreakpointEvent

private void _handleBreakpointEvent(com.sun.jdi.event.BreakpointEvent e)
Responds to a breakpoint event.

Parameters:
e - breakpoint event from JPDA

_handleStepEvent

private void _handleStepEvent(com.sun.jdi.event.StepEvent e)
Responds to a step event.

Parameters:
e - step event from JPDA

_handleClassPrepareEvent

private void _handleClassPrepareEvent(com.sun.jdi.event.ClassPrepareEvent e)
Responds when a class of interest has been prepared. Allows the debugger to set a pending breakpoint before any code in the class is executed.

Parameters:
e - class prepare event from JPDA

_handleThreadStartEvent

private void _handleThreadStartEvent(com.sun.jdi.event.ThreadStartEvent e)
Responds to a thread start event. Not run in event thread because threadStarted forces event thread execution.

Parameters:
e - thread start event from JPDA

_handleThreadDeathEvent

private void _handleThreadDeathEvent(com.sun.jdi.event.ThreadDeathEvent e)
Reponds to a thread death event.

Parameters:
e - thread death event from JPDA

_handleVMDeathEvent

private void _handleVMDeathEvent(com.sun.jdi.event.VMDeathEvent e)
                          throws DebugException
Responds if the virtual machine being debugged dies.

Parameters:
e - virtual machine death event from JPDA
Throws:
DebugException

_handleVMDisconnectEvent

private void _handleVMDisconnectEvent(com.sun.jdi.event.VMDisconnectEvent e)
                               throws DebugException
Responds if the virtual machine being debugged disconnects.

Parameters:
e - virtual machine disconnect event from JPDA
Throws:
DebugException

_cleanUp

private void _cleanUp(com.sun.jdi.event.Event e)
               throws DebugException
Cleans up the state after the virtual machine being debugged dies or disconnects.

Parameters:
e - JPDA event indicating the debugging session has ended
Throws:
DebugException

handleDisconnectedException

private void handleDisconnectedException()
                                  throws DebugException
Responds when a VMDisconnectedException occurs while dealing with another event. We need to flush the event queue, dealing only with exit events (VMDeath, VMDisconnect) so that we terminate correctly.

Throws:
DebugException