[Java] Update auto-generated bindings to 0.0.117
[ldk-java] / src / main / java / org / ldk / structs / LockableScore.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  * A scorer that is accessed under a lock.
12  * 
13  * Needed so that calls to [`ScoreLookUp::channel_penalty_msat`] in [`find_route`] can be made while
14  * having shared ownership of a scorer but without requiring internal locking in [`ScoreUpdate`]
15  * implementations. Internal locking would be detrimental to route finding performance and could
16  * result in [`ScoreLookUp::channel_penalty_msat`] returning a different value for the same channel.
17  * 
18  * [`find_route`]: crate::routing::router::find_route
19  */
20 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
21 public class LockableScore extends CommonBase {
22         final bindings.LDKLockableScore bindings_instance;
23         LockableScore(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
24         private LockableScore(bindings.LDKLockableScore arg) {
25                 super(bindings.LDKLockableScore_new(arg));
26                 this.ptrs_to.add(arg);
27                 this.bindings_instance = arg;
28         }
29         @Override @SuppressWarnings("deprecation")
30         protected void finalize() throws Throwable {
31                 if (ptr != 0) { bindings.LockableScore_free(ptr); } super.finalize();
32         }
33         /**
34          * Destroys the object, freeing associated resources. After this call, any access
35          * to this object may result in a SEGFAULT or worse.
36          *
37          * You should generally NEVER call this method. You should let the garbage collector
38          * do this for you when it finalizes objects. However, it may be useful for types
39          * which represent locks and should be closed immediately to avoid holding locks
40          * until the GC runs.
41          */
42         public void destroy() {
43                 if (ptr != 0) { bindings.LockableScore_free(ptr); }
44                 ptr = 0;
45         }
46         public static interface LockableScoreInterface {
47                 /**
48                  * Returns read locked scorer.
49                  */
50                 ScoreLookUp read_lock();
51                 /**
52                  * Returns write locked scorer.
53                  */
54                 ScoreUpdate write_lock();
55         }
56         private static class LDKLockableScoreHolder { LockableScore held; }
57         public static LockableScore new_impl(LockableScoreInterface arg) {
58                 final LDKLockableScoreHolder impl_holder = new LDKLockableScoreHolder();
59                 impl_holder.held = new LockableScore(new bindings.LDKLockableScore() {
60                         @Override public long read_lock() {
61                                 ScoreLookUp ret = arg.read_lock();
62                                 Reference.reachabilityFence(arg);
63                                 long result = ret.ptr;
64                                 if (impl_holder.held != null) { impl_holder.held.ptrs_to.add(ret); };
65                                 return result;
66                         }
67                         @Override public long write_lock() {
68                                 ScoreUpdate ret = arg.write_lock();
69                                 Reference.reachabilityFence(arg);
70                                 long result = ret.ptr;
71                                 if (impl_holder.held != null) { impl_holder.held.ptrs_to.add(ret); };
72                                 return result;
73                         }
74                 });
75                 return impl_holder.held;
76         }
77         /**
78          * Returns read locked scorer.
79          */
80         public ScoreLookUp read_lock() {
81                 long ret = bindings.LockableScore_read_lock(this.ptr);
82                 Reference.reachabilityFence(this);
83                 if (ret >= 0 && ret <= 4096) { return null; }
84                 ScoreLookUp ret_hu_conv = new ScoreLookUp(null, ret);
85                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
86                 return ret_hu_conv;
87         }
88
89         /**
90          * Returns write locked scorer.
91          */
92         public ScoreUpdate write_lock() {
93                 long ret = bindings.LockableScore_write_lock(this.ptr);
94                 Reference.reachabilityFence(this);
95                 if (ret >= 0 && ret <= 4096) { return null; }
96                 ScoreUpdate ret_hu_conv = new ScoreUpdate(null, ret);
97                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
98                 return ret_hu_conv;
99         }
100
101 }