/**
* A trait implemented for objects handling events from [`EventsProvider`].
+ *
+ * An async variation also exists for implementations of [`EventsProvider`] that support async
+ * event handling. The async event handler should satisfy the generic bounds: `F:
+ * core::future::Future, H: Fn(Event) -> F`.
*/
@SuppressWarnings("unchecked") // We correctly assign various generic arrays
public class EventHandler extends CommonBase {
protected void finalize() throws Throwable {
if (ptr != 0) { bindings.EventHandler_free(ptr); } super.finalize();
}
-
+ /**
+ * Destroys the object, freeing associated resources. After this call, any access
+ * to this object may result in a SEGFAULT or worse.
+ *
+ * You should generally NEVER call this method. You should let the garbage collector
+ * do this for you when it finalizes objects. However, it may be useful for types
+ * which represent locks and should be closed immediately to avoid holding locks
+ * until the GC runs.
+ */
+ public void destroy() {
+ if (ptr != 0) { bindings.EventHandler_free(ptr); }
+ ptr = 0;
+ }
public static interface EventHandlerInterface {
/**
* Handles the given [`Event`].
final LDKEventHandlerHolder impl_holder = new LDKEventHandlerHolder();
impl_holder.held = new EventHandler(new bindings.LDKEventHandler() {
@Override public void handle_event(long event) {
- Event event_hu_conv = Event.constr_from_ptr(event);
+ org.ldk.structs.Event event_hu_conv = org.ldk.structs.Event.constr_from_ptr(event);
+ if (event_hu_conv != null) { event_hu_conv.ptrs_to.add(this); };
arg.handle_event(event_hu_conv);
Reference.reachabilityFence(arg);
}
*
* See [`EventsProvider`] for details that must be considered when implementing this method.
*/
- public void handle_event(Event event) {
- bindings.EventHandler_handle_event(this.ptr, event == null ? 0 : event.ptr);
+ public void handle_event(org.ldk.structs.Event event) {
+ bindings.EventHandler_handle_event(this.ptr, event.ptr);
Reference.reachabilityFence(this);
Reference.reachabilityFence(event);
+ if (this != null) { this.ptrs_to.add(event); };
}
}