Update auto-generated bindings
[ldk-java] / src / main / java / org / ldk / structs / EventsProvider.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7
8 /**
9  * A trait indicating an object may generate events.
10  * 
11  * Events are processed by passing an [`EventHandler`] to [`process_pending_events`].
12  * 
13  * # Requirements
14  * 
15  * See [`process_pending_events`] for requirements around event processing.
16  * 
17  * When using this trait, [`process_pending_events`] will call [`handle_event`] for each pending
18  * event since the last invocation. The handler must either act upon the event immediately
19  * or preserve it for later handling.
20  * 
21  * Note, handlers may call back into the provider and thus deadlocking must be avoided. Be sure to
22  * consult the provider's documentation on the implication of processing events and how a handler
23  * may safely use the provider (e.g., see [`ChannelManager::process_pending_events`] and
24  * [`ChainMonitor::process_pending_events`]).
25  * 
26  * (C-not implementable) As there is likely no reason for a user to implement this trait on their
27  * own type(s).
28  * 
29  * [`process_pending_events`]: Self::process_pending_events
30  * [`handle_event`]: EventHandler::handle_event
31  * [`ChannelManager::process_pending_events`]: crate::ln::channelmanager::ChannelManager#method.process_pending_events
32  * [`ChainMonitor::process_pending_events`]: crate::chain::chainmonitor::ChainMonitor#method.process_pending_events
33  */
34 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
35 public class EventsProvider extends CommonBase {
36         final bindings.LDKEventsProvider bindings_instance;
37         EventsProvider(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
38         private EventsProvider(bindings.LDKEventsProvider arg) {
39                 super(bindings.LDKEventsProvider_new(arg));
40                 this.ptrs_to.add(arg);
41                 this.bindings_instance = arg;
42         }
43         @Override @SuppressWarnings("deprecation")
44         protected void finalize() throws Throwable {
45                 if (ptr != 0) { bindings.EventsProvider_free(ptr); } super.finalize();
46         }
47
48         public static interface EventsProviderInterface {
49                 /**
50                  * Processes any events generated since the last call using the given event handler.
51                  * 
52                  * Subsequent calls must only process new events. However, handlers must be capable of handling
53                  * duplicate events across process restarts. This may occur if the provider was recovered from
54                  * an old state (i.e., it hadn't been successfully persisted after processing pending events).
55                  */
56                 void process_pending_events(EventHandler handler);
57         }
58         private static class LDKEventsProviderHolder { EventsProvider held; }
59         public static EventsProvider new_impl(EventsProviderInterface arg) {
60                 final LDKEventsProviderHolder impl_holder = new LDKEventsProviderHolder();
61                 impl_holder.held = new EventsProvider(new bindings.LDKEventsProvider() {
62                         @Override public void process_pending_events(long handler) {
63                                 EventHandler ret_hu_conv = new EventHandler(null, handler);
64                                 ret_hu_conv.ptrs_to.add(this);
65                                 arg.process_pending_events(ret_hu_conv);
66                         }
67                 });
68                 return impl_holder.held;
69         }
70         /**
71          * Processes any events generated since the last call using the given event handler.
72          * 
73          * Subsequent calls must only process new events. However, handlers must be capable of handling
74          * duplicate events across process restarts. This may occur if the provider was recovered from
75          * an old state (i.e., it hadn't been successfully persisted after processing pending events).
76          */
77         public void process_pending_events(EventHandler handler) {
78                 bindings.EventsProvider_process_pending_events(this.ptr, handler == null ? 0 : handler.ptr);
79                 this.ptrs_to.add(handler);
80         }
81
82 }