diff --git a/java/src/processing/mode/java/Debugger.java b/java/src/processing/mode/java/Debugger.java index ae146f20c..496cbb96c 100644 --- a/java/src/processing/mode/java/Debugger.java +++ b/java/src/processing/mode/java/Debugger.java @@ -42,12 +42,10 @@ import javax.swing.tree.DefaultMutableTreeNode; import processing.app.Sketch; import processing.app.SketchCode; import processing.mode.java.debug.*; -import processing.mode.java.pdex.VMEventListener; -import processing.mode.java.pdex.VMEventReader; import processing.mode.java.runner.Runner; -public class Debugger implements VMEventListener { +public class Debugger { /// editor window, acting as main view protected JavaEditor editor; @@ -91,6 +89,9 @@ public class Debugger implements VMEventListener { /// tab filenames which already have been tracked for runtime changes protected Set runtimeTabsTracked = new HashSet<>(); + /// VM event listener + protected VMEventListener vmEventListener = this::vmEvent; + public Debugger(JavaEditor editor) { this.editor = editor; @@ -219,7 +220,7 @@ public class Debugger implements VMEventListener { } // start receiving vm events - VMEventReader eventThread = new VMEventReader(vm.eventQueue(), this); + VMEventReader eventThread = new VMEventReader(vm.eventQueue(), vmEventListener); eventThread.start(); startTrackingLineChanges(); @@ -532,7 +533,6 @@ public class Debugger implements VMEventListener { * ({@link VMEventReader}) * @param es Incoming set of events from VM */ - @Override public synchronized void vmEvent(EventSet es) { for (Event e : es) { log(Level.INFO, "*** VM Event: {0}", e.toString()); @@ -1392,4 +1392,66 @@ public class Debugger implements VMEventListener { static private void log(Level level, String msg, Object obj) { Logger.getLogger(Debugger.class.getName()).log(level, msg, obj); } + + + /** + * Interface for VM callbacks. + * + * @author Martin Leopold + */ + protected interface VMEventListener { + + /** + * Receive an event from the VM. Events are sent in batches. See + * documentation of EventSet for more information. + * + * @param es Set of events + */ + void vmEvent(EventSet es); + } + + + /** + * Reader Thread for VM Events. Constantly monitors a VMs EventQueue for new + * events and forwards them to an VMEventListener. + * + * @author Martin Leopold + */ + protected static class VMEventReader extends Thread { + + EventQueue eventQueue; + VMEventListener listener; + + /** + * Construct a VMEventReader. Needs to be kicked off with start() once + * constructed. + * + * @param eventQueue The queue to read events from. Can be obtained from a + * VirtualMachine via eventQueue(). + * @param listener the listener to forward events to. + */ + public VMEventReader(EventQueue eventQueue, VMEventListener listener) { + super("VM Event Thread"); + this.eventQueue = eventQueue; + this.listener = listener; + } + + @Override + public void run() { + try { + while (true) { + EventSet eventSet = eventQueue.remove(); + listener.vmEvent(eventSet); + /* + * for (Event e : eventSet) { System.out.println("VM Event: " + + * e.toString()); } + */ + } + } catch (VMDisconnectedException e) { + Logger.getLogger(VMEventReader.class.getName()).log(Level.INFO, "VMEventReader quit on VM disconnect"); + } catch (Exception e) { + Logger.getLogger(VMEventReader.class.getName()).log(Level.SEVERE, "VMEventReader quit", e); + } + } + } } diff --git a/java/src/processing/mode/java/pdex/VMEventListener.java b/java/src/processing/mode/java/pdex/VMEventListener.java deleted file mode 100644 index 14c6652c5..000000000 --- a/java/src/processing/mode/java/pdex/VMEventListener.java +++ /dev/null @@ -1,39 +0,0 @@ -/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ - -/* -Part of the Processing project - http://processing.org -Copyright (c) 2012-15 The Processing Foundation - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License version 2 -as published by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software Foundation, Inc. -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -package processing.mode.java.pdex; - -import com.sun.jdi.event.EventSet; - -/** - * Interface for VM callbacks. - * - * @author Martin Leopold - */ -public interface VMEventListener { - - /** - * Receive an event from the VM. Events are sent in batches. See - * documentation of EventSet for more information. - * - * @param es Set of events - */ - void vmEvent(EventSet es); -} diff --git a/java/src/processing/mode/java/pdex/VMEventReader.java b/java/src/processing/mode/java/pdex/VMEventReader.java deleted file mode 100644 index 39322fdc2..000000000 --- a/java/src/processing/mode/java/pdex/VMEventReader.java +++ /dev/null @@ -1,71 +0,0 @@ -/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ - -/* -Part of the Processing project - http://processing.org -Copyright (c) 2012-15 The Processing Foundation - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License version 2 -as published by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software Foundation, Inc. -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -package processing.mode.java.pdex; - -import com.sun.jdi.VMDisconnectedException; -import com.sun.jdi.event.EventQueue; -import com.sun.jdi.event.EventSet; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Reader Thread for VM Events. Constantly monitors a VMs EventQueue for new - * events and forwards them to an VMEventListener. - * - * @author Martin Leopold - */ -public class VMEventReader extends Thread { - - EventQueue eventQueue; - VMEventListener listener; - - /** - * Construct a VMEventReader. Needs to be kicked off with start() once - * constructed. - * - * @param eventQueue The queue to read events from. Can be obtained from a - * VirtualMachine via eventQueue(). - * @param listener the listener to forward events to. - */ - public VMEventReader(EventQueue eventQueue, VMEventListener listener) { - super("VM Event Thread"); - this.eventQueue = eventQueue; - this.listener = listener; - } - - @Override - public void run() { - try { - while (true) { - EventSet eventSet = eventQueue.remove(); - listener.vmEvent(eventSet); - /* - * for (Event e : eventSet) { System.out.println("VM Event: " + - * e.toString()); } - */ - } - } catch (VMDisconnectedException e) { - Logger.getLogger(VMEventReader.class.getName()).log(Level.INFO, "VMEventReader quit on VM disconnect"); - } catch (Exception e) { - Logger.getLogger(VMEventReader.class.getName()).log(Level.SEVERE, "VMEventReader quit", e); - } - } -}