[Java] Update auto-generated bindings to 0.0.117
[ldk-java] / src / main / java / org / ldk / structs / Persister.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 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10 /**
11  * Trait that handles persisting a [`ChannelManager`], [`NetworkGraph`], and [`WriteableScore`] to disk.
12  */
13 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
14 public class Persister extends CommonBase {
15         final bindings.LDKPersister bindings_instance;
16         Persister(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
17         private Persister(bindings.LDKPersister arg) {
18                 super(bindings.LDKPersister_new(arg));
19                 this.ptrs_to.add(arg);
20                 this.bindings_instance = arg;
21         }
22         @Override @SuppressWarnings("deprecation")
23         protected void finalize() throws Throwable {
24                 if (ptr != 0) { bindings.Persister_free(ptr); } super.finalize();
25         }
26         /**
27          * Destroys the object, freeing associated resources. After this call, any access
28          * to this object may result in a SEGFAULT or worse.
29          *
30          * You should generally NEVER call this method. You should let the garbage collector
31          * do this for you when it finalizes objects. However, it may be useful for types
32          * which represent locks and should be closed immediately to avoid holding locks
33          * until the GC runs.
34          */
35         public void destroy() {
36                 if (ptr != 0) { bindings.Persister_free(ptr); }
37                 ptr = 0;
38         }
39         public static interface PersisterInterface {
40                 /**
41                  * Persist the given ['ChannelManager'] to disk, returning an error if persistence failed.
42                  */
43                 Result_NoneIOErrorZ persist_manager(ChannelManager channel_manager);
44                 /**
45                  * Persist the given [`NetworkGraph`] to disk, returning an error if persistence failed.
46                  */
47                 Result_NoneIOErrorZ persist_graph(NetworkGraph network_graph);
48                 /**
49                  * Persist the given [`WriteableScore`] to disk, returning an error if persistence failed.
50                  */
51                 Result_NoneIOErrorZ persist_scorer(WriteableScore scorer);
52         }
53         private static class LDKPersisterHolder { Persister held; }
54         public static Persister new_impl(PersisterInterface arg) {
55                 final LDKPersisterHolder impl_holder = new LDKPersisterHolder();
56                 impl_holder.held = new Persister(new bindings.LDKPersister() {
57                         @Override public long persist_manager(long channel_manager) {
58                                 org.ldk.structs.ChannelManager channel_manager_hu_conv = null; if (channel_manager < 0 || channel_manager > 4096) { channel_manager_hu_conv = new org.ldk.structs.ChannelManager(null, channel_manager); }
59                                 Result_NoneIOErrorZ ret = arg.persist_manager(channel_manager_hu_conv);
60                                 Reference.reachabilityFence(arg);
61                                 long result = ret == null ? 0 : ret.clone_ptr();
62                                 return result;
63                         }
64                         @Override public long persist_graph(long network_graph) {
65                                 org.ldk.structs.NetworkGraph network_graph_hu_conv = null; if (network_graph < 0 || network_graph > 4096) { network_graph_hu_conv = new org.ldk.structs.NetworkGraph(null, network_graph); }
66                                 Result_NoneIOErrorZ ret = arg.persist_graph(network_graph_hu_conv);
67                                 Reference.reachabilityFence(arg);
68                                 long result = ret == null ? 0 : ret.clone_ptr();
69                                 return result;
70                         }
71                         @Override public long persist_scorer(long scorer) {
72                                 WriteableScore ret_hu_conv = new WriteableScore(null, scorer);
73                                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
74                                 Result_NoneIOErrorZ ret = arg.persist_scorer(ret_hu_conv);
75                                 Reference.reachabilityFence(arg);
76                                 long result = ret == null ? 0 : ret.clone_ptr();
77                                 return result;
78                         }
79                 });
80                 return impl_holder.held;
81         }
82         /**
83          * Persist the given ['ChannelManager'] to disk, returning an error if persistence failed.
84          */
85         public Result_NoneIOErrorZ persist_manager(org.ldk.structs.ChannelManager channel_manager) {
86                 long ret = bindings.Persister_persist_manager(this.ptr, channel_manager == null ? 0 : channel_manager.ptr);
87                 Reference.reachabilityFence(this);
88                 Reference.reachabilityFence(channel_manager);
89                 if (ret >= 0 && ret <= 4096) { return null; }
90                 Result_NoneIOErrorZ ret_hu_conv = Result_NoneIOErrorZ.constr_from_ptr(ret);
91                 if (this != null) { this.ptrs_to.add(channel_manager); };
92                 return ret_hu_conv;
93         }
94
95         /**
96          * Persist the given [`NetworkGraph`] to disk, returning an error if persistence failed.
97          */
98         public Result_NoneIOErrorZ persist_graph(org.ldk.structs.NetworkGraph network_graph) {
99                 long ret = bindings.Persister_persist_graph(this.ptr, network_graph == null ? 0 : network_graph.ptr);
100                 Reference.reachabilityFence(this);
101                 Reference.reachabilityFence(network_graph);
102                 if (ret >= 0 && ret <= 4096) { return null; }
103                 Result_NoneIOErrorZ ret_hu_conv = Result_NoneIOErrorZ.constr_from_ptr(ret);
104                 if (this != null) { this.ptrs_to.add(network_graph); };
105                 return ret_hu_conv;
106         }
107
108         /**
109          * Persist the given [`WriteableScore`] to disk, returning an error if persistence failed.
110          */
111         public Result_NoneIOErrorZ persist_scorer(org.ldk.structs.WriteableScore scorer) {
112                 long ret = bindings.Persister_persist_scorer(this.ptr, scorer.ptr);
113                 Reference.reachabilityFence(this);
114                 Reference.reachabilityFence(scorer);
115                 if (ret >= 0 && ret <= 4096) { return null; }
116                 Result_NoneIOErrorZ ret_hu_conv = Result_NoneIOErrorZ.constr_from_ptr(ret);
117                 if (this != null) { this.ptrs_to.add(scorer); };
118                 return ret_hu_conv;
119         }
120
121 }