JDIDebugTarget target) {
ClassType classType = ( ClassType ) ((ClassPrepareEvent) event).referenceType();
String name = classType.name();
// change this to create a breakpoint, as the method enter was too slow
BreakpointRequest req = null;
List list = classType.methodsByName( "onBreak" );
if ( list.size() == 0 ) {
throw new IllegalStateException( "MVELDebugHandler.onBreak cannot be found by JDI" );
}
Method method = ( Method ) list.get( 0 );
if (method != null && !method.isNative()) {
Location location = method.location();
if (location != null && location.codeIndex() != -1) {
req = getEventRequestManager().createBreakpointRequest(location);
req.addThreadFilter( ((ClassPrepareEvent) event).thread() );
req.setSuspendPolicy( EventRequest.SUSPEND_ALL );
} else {
throw new IllegalStateException( "MVELDebugHandler.onBreak location cannot be found by JDI" );
}
} else {
throw new IllegalStateException( "MVELDebugHandler.onBreak cannot be found by JDI" );
}
//breakpointCatched
/*field= type.fieldByName(getFieldName());
Field field;
EventRequest req= manager.createModificationWatchpointRequest(field);
*/
//req.setSuspendPolicy( EventRequest.SUSPEND_EVENT_THREAD );
addJDIEventListener(new IJDIEventListener() {
public boolean handleEvent(Event event, JDIDebugTarget target) {
BreakpointEvent entryEvent = (BreakpointEvent) event;
//System.out.println( entryEvent + ":" + entryEvent.location() );
try {
IThread[] tharr = getThreads();
ThreadReference t = null;
DroolsThread t2 = null;
for (int i = 0; i < tharr.length; i++) {
DroolsThread th2 = (DroolsThread) tharr[i];
ThreadReference th2real = ((DroolsThread) tharr[i]).getUnderlyingThread();
if (th2real.suspendCount() == 1 && th2.getName().equals("main")) {
t = th2real;
t2 = (DroolsThread) th2;
th2real.suspend();
th2.setRunning(false);
th2.fireSuspendEvent(DebugEvent.CLIENT_REQUEST);
return true;
}
}
} catch (Exception t) {
logError(t);
}
return true;
}
public void wonSuspendVote(Event event, JDIDebugTarget target) {
// do nothing
}
public void eventSetComplete(Event event, JDIDebugTarget target, boolean suspend, EventSet eventSet) {
wonSuspendVote(event, target);
}
public boolean handleEvent(Event event, JDIDebugTarget target, boolean suspendVote, EventSet eventSet) {
return handleEvent(event, target);
}
}, req);
req.enable();
// now remove the ClassPrepareEvent
removeJDIEventListener(MVELTraceHandler.this, ((ClassPrepareEvent) event).request() );
return true;