1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
11 * Trait that handles persisting a [`ChannelManager`], [`NetworkGraph`], and [`WriteableScore`] to disk.
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;
22 @Override @SuppressWarnings("deprecation")
23 protected void finalize() throws Throwable {
24 if (ptr != 0) { bindings.Persister_free(ptr); } super.finalize();
27 * Destroys the object, freeing associated resources. After this call, any access
28 * to this object may result in a SEGFAULT or worse.
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
35 public void destroy() {
36 if (ptr != 0) { bindings.Persister_free(ptr); }
39 public static interface PersisterInterface {
41 * Persist the given ['ChannelManager'] to disk, returning an error if persistence failed.
43 Result_NoneErrorZ persist_manager(ChannelManager channel_manager);
45 * Persist the given [`NetworkGraph`] to disk, returning an error if persistence failed.
47 Result_NoneErrorZ persist_graph(NetworkGraph network_graph);
49 * Persist the given [`WriteableScore`] to disk, returning an error if persistence failed.
51 Result_NoneErrorZ persist_scorer(WriteableScore scorer);
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_NoneErrorZ ret = arg.persist_manager(channel_manager_hu_conv);
60 Reference.reachabilityFence(arg);
61 long result = ret == null ? 0 : ret.clone_ptr();
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_NoneErrorZ ret = arg.persist_graph(network_graph_hu_conv);
67 Reference.reachabilityFence(arg);
68 long result = ret == null ? 0 : ret.clone_ptr();
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_NoneErrorZ ret = arg.persist_scorer(ret_hu_conv);
75 Reference.reachabilityFence(arg);
76 long result = ret == null ? 0 : ret.clone_ptr();
80 return impl_holder.held;
83 * Persist the given ['ChannelManager'] to disk, returning an error if persistence failed.
85 public Result_NoneErrorZ 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_NoneErrorZ ret_hu_conv = Result_NoneErrorZ.constr_from_ptr(ret);
91 if (this != null) { this.ptrs_to.add(channel_manager); };
96 * Persist the given [`NetworkGraph`] to disk, returning an error if persistence failed.
98 public Result_NoneErrorZ 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_NoneErrorZ ret_hu_conv = Result_NoneErrorZ.constr_from_ptr(ret);
104 if (this != null) { this.ptrs_to.add(network_graph); };
109 * Persist the given [`WriteableScore`] to disk, returning an error if persistence failed.
111 public Result_NoneErrorZ persist_scorer(org.ldk.structs.WriteableScore scorer) {
112 long ret = bindings.Persister_persist_scorer(this.ptr, scorer == null ? 0 : scorer.ptr);
113 Reference.reachabilityFence(this);
114 Reference.reachabilityFence(scorer);
115 if (ret >= 0 && ret <= 4096) { return null; }
116 Result_NoneErrorZ ret_hu_conv = Result_NoneErrorZ.constr_from_ptr(ret);
117 if (this != null) { this.ptrs_to.add(scorer); };