Skip to content

__java_event_drain__

builtin · libnexusinterp/nexus-value/ov-java-proprietary.cc

: n = __java_event_drain__ ()
: n = __java_event_drain__ (timeout)
: __java_event_drain__ ("sleep", secs)

Run the Nexus callbacks of Java events that have been queued.

A Java listener (ActionListener, ChangeListener, PropertyChangeListener, …) installed with

set (jobj, "ActionPerformedCallback", @(src, evt) disp (evt.getActionCommand ()))
jobj.ActionPerformedCallback = @cb;
addlistener (jobj, "ActionPerformed", @cb);

may be fired from any Java thread, but the interpreter is not thread safe, so the event is only queued there. The callbacks run here, on the interpreter thread, at safe points: when a Java method call returns, drawnow, pause, and an explicit call to __java_event_drain__. Each callback is called as cb (src, evt) with the Java source object and the Java event object; a cell array {@cb, a, b} is called as cb (src, evt, a, b), and a string is evaluated. An error in a callback is reported as a warning and does not stop the others.

With a timeout (seconds) the call first waits up to that long for the first event. __java_event_drain__ ("sleep", secs) services events for the whole of secs seconds. The return value is the number of callbacks that ran.