e2a068448ea8bf3da8d174788ff168551ad547cf
[ldk-java] / src / main / java / org / ldk / structs / WriteableScore.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  * Refers to a scorer that is accessible under lock and also writeable to disk
12  * 
13  * We need this trait to be able to pass in a scorer to `lightning-background-processor` that will enable us to
14  * use the Persister to persist it.
15  */
16 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
17 public class WriteableScore extends CommonBase {
18         final bindings.LDKWriteableScore bindings_instance;
19         WriteableScore(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
20         private WriteableScore(bindings.LDKWriteableScore arg, bindings.LDKLockableScore LockableScore) {
21                 super(bindings.LDKWriteableScore_new(arg, LockableScore));
22                 this.ptrs_to.add(arg);
23                 this.ptrs_to.add(LockableScore);
24                 this.bindings_instance = arg;
25         }
26         @Override @SuppressWarnings("deprecation")
27         protected void finalize() throws Throwable {
28                 if (ptr != 0) { bindings.WriteableScore_free(ptr); } super.finalize();
29         }
30         /**
31          * Destroys the object, freeing associated resources. After this call, any access
32          * to this object may result in a SEGFAULT or worse.
33          *
34          * You should generally NEVER call this method. You should let the garbage collector
35          * do this for you when it finalizes objects. However, it may be useful for types
36          * which represent locks and should be closed immediately to avoid holding locks
37          * until the GC runs.
38          */
39         public void destroy() {
40                 if (ptr != 0) { bindings.WriteableScore_free(ptr); }
41                 ptr = 0;
42         }
43         public static interface WriteableScoreInterface {
44                 /**
45                  * Serialize the object into a byte array
46                  */
47                 byte[] write();
48         }
49         private static class LDKWriteableScoreHolder { WriteableScore held; }
50         public static WriteableScore new_impl(WriteableScoreInterface arg, LockableScore.LockableScoreInterface LockableScore_impl) {
51                 final LDKWriteableScoreHolder impl_holder = new LDKWriteableScoreHolder();
52                 impl_holder.held = new WriteableScore(new bindings.LDKWriteableScore() {
53                         @Override public byte[] write() {
54                                 byte[] ret = arg.write();
55                                 Reference.reachabilityFence(arg);
56                                 return ret;
57                         }
58                 }, LockableScore.new_impl(LockableScore_impl).bindings_instance);
59                 return impl_holder.held;
60         }
61
62         /**
63          * Gets the underlying LockableScore.
64          */
65         public LockableScore get_lockable_score() {
66                 LockableScore res = new LockableScore(null, bindings.LDKWriteableScore_get_LockableScore(this.ptr));
67                 res.ptrs_to.add(this);
68                 return res;
69         }
70
71         /**
72          * Serialize the object into a byte array
73          */
74         public byte[] write() {
75                 byte[] ret = bindings.WriteableScore_write(this.ptr);
76                 Reference.reachabilityFence(this);
77                 return ret;
78         }
79
80 }