X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FPersister.java;h=3a63215fb06b1e34258b57e1bdf48433914097ec;hb=ca313f2eee377bec222fa82b2939751fa9eab32e;hp=6329303504b14cc05730bba5d85bdde0fc395fd4;hpb=330ca992be304d0eac79bd59b411980dff294b03;p=ldk-java diff --git a/src/main/java/org/ldk/structs/Persister.java b/src/main/java/org/ldk/structs/Persister.java index 63293035..3a63215f 100644 --- a/src/main/java/org/ldk/structs/Persister.java +++ b/src/main/java/org/ldk/structs/Persister.java @@ -23,20 +23,32 @@ public class Persister extends CommonBase { protected void finalize() throws Throwable { if (ptr != 0) { bindings.Persister_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.Persister_free(ptr); } + ptr = 0; + } public static interface PersisterInterface { /** * Persist the given ['ChannelManager'] to disk, returning an error if persistence failed. */ - Result_NoneErrorZ persist_manager(ChannelManager channel_manager); + Result_NoneIOErrorZ persist_manager(ChannelManager channel_manager); /** * Persist the given [`NetworkGraph`] to disk, returning an error if persistence failed. */ - Result_NoneErrorZ persist_graph(NetworkGraph network_graph); + Result_NoneIOErrorZ persist_graph(NetworkGraph network_graph); /** * Persist the given [`WriteableScore`] to disk, returning an error if persistence failed. */ - Result_NoneErrorZ persist_scorer(WriteableScore scorer); + Result_NoneIOErrorZ persist_scorer(WriteableScore scorer); } private static class LDKPersisterHolder { Persister held; } public static Persister new_impl(PersisterInterface arg) { @@ -44,14 +56,14 @@ public class Persister extends CommonBase { impl_holder.held = new Persister(new bindings.LDKPersister() { @Override public long persist_manager(long channel_manager) { 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); } - Result_NoneErrorZ ret = arg.persist_manager(channel_manager_hu_conv); + Result_NoneIOErrorZ ret = arg.persist_manager(channel_manager_hu_conv); Reference.reachabilityFence(arg); long result = ret == null ? 0 : ret.clone_ptr(); return result; } @Override public long persist_graph(long network_graph) { 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); } - Result_NoneErrorZ ret = arg.persist_graph(network_graph_hu_conv); + Result_NoneIOErrorZ ret = arg.persist_graph(network_graph_hu_conv); Reference.reachabilityFence(arg); long result = ret == null ? 0 : ret.clone_ptr(); return result; @@ -59,7 +71,7 @@ public class Persister extends CommonBase { @Override public long persist_scorer(long scorer) { WriteableScore ret_hu_conv = new WriteableScore(null, scorer); if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; - Result_NoneErrorZ ret = arg.persist_scorer(ret_hu_conv); + Result_NoneIOErrorZ ret = arg.persist_scorer(ret_hu_conv); Reference.reachabilityFence(arg); long result = ret == null ? 0 : ret.clone_ptr(); return result; @@ -70,12 +82,12 @@ public class Persister extends CommonBase { /** * Persist the given ['ChannelManager'] to disk, returning an error if persistence failed. */ - public Result_NoneErrorZ persist_manager(org.ldk.structs.ChannelManager channel_manager) { + public Result_NoneIOErrorZ persist_manager(org.ldk.structs.ChannelManager channel_manager) { long ret = bindings.Persister_persist_manager(this.ptr, channel_manager == null ? 0 : channel_manager.ptr); Reference.reachabilityFence(this); Reference.reachabilityFence(channel_manager); if (ret >= 0 && ret <= 4096) { return null; } - Result_NoneErrorZ ret_hu_conv = Result_NoneErrorZ.constr_from_ptr(ret); + Result_NoneIOErrorZ ret_hu_conv = Result_NoneIOErrorZ.constr_from_ptr(ret); if (this != null) { this.ptrs_to.add(channel_manager); }; return ret_hu_conv; } @@ -83,12 +95,12 @@ public class Persister extends CommonBase { /** * Persist the given [`NetworkGraph`] to disk, returning an error if persistence failed. */ - public Result_NoneErrorZ persist_graph(org.ldk.structs.NetworkGraph network_graph) { + public Result_NoneIOErrorZ persist_graph(org.ldk.structs.NetworkGraph network_graph) { long ret = bindings.Persister_persist_graph(this.ptr, network_graph == null ? 0 : network_graph.ptr); Reference.reachabilityFence(this); Reference.reachabilityFence(network_graph); if (ret >= 0 && ret <= 4096) { return null; } - Result_NoneErrorZ ret_hu_conv = Result_NoneErrorZ.constr_from_ptr(ret); + Result_NoneIOErrorZ ret_hu_conv = Result_NoneIOErrorZ.constr_from_ptr(ret); if (this != null) { this.ptrs_to.add(network_graph); }; return ret_hu_conv; } @@ -96,12 +108,12 @@ public class Persister extends CommonBase { /** * Persist the given [`WriteableScore`] to disk, returning an error if persistence failed. */ - public Result_NoneErrorZ persist_scorer(org.ldk.structs.WriteableScore scorer) { - long ret = bindings.Persister_persist_scorer(this.ptr, scorer == null ? 0 : scorer.ptr); + public Result_NoneIOErrorZ persist_scorer(org.ldk.structs.WriteableScore scorer) { + long ret = bindings.Persister_persist_scorer(this.ptr, scorer.ptr); Reference.reachabilityFence(this); Reference.reachabilityFence(scorer); if (ret >= 0 && ret <= 4096) { return null; } - Result_NoneErrorZ ret_hu_conv = Result_NoneErrorZ.constr_from_ptr(ret); + Result_NoneIOErrorZ ret_hu_conv = Result_NoneIOErrorZ.constr_from_ptr(ret); if (this != null) { this.ptrs_to.add(scorer); }; return ret_hu_conv; }