7 namespace org { namespace ldk { namespace structs {
11 /** An implementation of EventsProvider */
12 public interface EventsProviderInterface {
13 /**Processes any events generated since the last call using the given event handler.
15 * See the trait-level documentation for requirements.
17 void process_pending_events(EventHandler handler);
21 * A trait indicating an object may generate events.
23 * Events are processed by passing an [`EventHandler`] to [`process_pending_events`].
25 * Implementations of this trait may also feature an async version of event handling, as shown with
26 * [`ChannelManager::process_pending_events_async`] and
27 * [`ChainMonitor::process_pending_events_async`].
31 * When using this trait, [`process_pending_events`] will call [`handle_event`] for each pending
32 * event since the last invocation.
34 * In order to ensure no [`Event`]s are lost, implementors of this trait will persist [`Event`]s
35 * and replay any unhandled events on startup. An [`Event`] is considered handled when
36 * [`process_pending_events`] returns, thus handlers MUST fully handle [`Event`]s and persist any
37 * relevant changes to disk *before* returning.
39 * Further, because an application may crash between an [`Event`] being handled and the
40 * implementor of this trait being re-serialized, [`Event`] handling must be idempotent - in
41 * effect, [`Event`]s may be replayed.
43 * Note, handlers may call back into the provider and thus deadlocking must be avoided. Be sure to
44 * consult the provider's documentation on the implication of processing events and how a handler
45 * may safely use the provider (e.g., see [`ChannelManager::process_pending_events`] and
46 * [`ChainMonitor::process_pending_events`]).
48 * (C-not implementable) As there is likely no reason for a user to implement this trait on their
51 * [`process_pending_events`]: Self::process_pending_events
52 * [`handle_event`]: EventHandler::handle_event
53 * [`ChannelManager::process_pending_events`]: crate::ln::channelmanager::ChannelManager#method.process_pending_events
54 * [`ChainMonitor::process_pending_events`]: crate::chain::chainmonitor::ChainMonitor#method.process_pending_events
55 * [`ChannelManager::process_pending_events_async`]: crate::ln::channelmanager::ChannelManager::process_pending_events_async
56 * [`ChainMonitor::process_pending_events_async`]: crate::chain::chainmonitor::ChainMonitor::process_pending_events_async
58 public class EventsProvider : CommonBase {
59 internal bindings.LDKEventsProvider bindings_instance;
60 internal long instance_idx;
62 internal EventsProvider(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
64 if (ptr != 0) { bindings.EventsProvider_free(ptr); }
67 private class LDKEventsProviderHolder { internal EventsProvider held; }
68 private class LDKEventsProviderImpl : bindings.LDKEventsProvider {
69 internal LDKEventsProviderImpl(EventsProviderInterface arg, LDKEventsProviderHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
70 private EventsProviderInterface arg;
71 private LDKEventsProviderHolder impl_holder;
72 public void process_pending_events(long _handler) {
73 EventHandler ret_hu_conv = new EventHandler(null, _handler);
74 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
75 arg.process_pending_events(ret_hu_conv);
80 /** Creates a new instance of EventsProvider from a given implementation */
81 public static EventsProvider new_impl(EventsProviderInterface arg) {
82 LDKEventsProviderHolder impl_holder = new LDKEventsProviderHolder();
83 LDKEventsProviderImpl impl = new LDKEventsProviderImpl(arg, impl_holder);
84 long[] ptr_idx = bindings.LDKEventsProvider_new(impl);
86 impl_holder.held = new EventsProvider(null, ptr_idx[0]);
87 impl_holder.held.instance_idx = ptr_idx[1];
88 impl_holder.held.bindings_instance = impl;
89 return impl_holder.held;
93 * Processes any events generated since the last call using the given event handler.
95 * See the trait-level documentation for requirements.
97 public void process_pending_events(org.ldk.structs.EventHandler handler) {
98 bindings.EventsProvider_process_pending_events(this.ptr, handler.ptr);
100 GC.KeepAlive(handler);
101 if (this != null) { this.ptrs_to.AddLast(handler); };