229a047756d9b76fa641663d65f2e1f8a4d4bbe0
[ldk-java] / src / main / java / org / ldk / structs / Logger.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 trait encapsulating the operations required of a logger
12  */
13 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
14 public class Logger extends CommonBase {
15         final bindings.LDKLogger bindings_instance;
16         Logger(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
17         private Logger(bindings.LDKLogger arg) {
18                 super(bindings.LDKLogger_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.Logger_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.Logger_free(ptr); }
37                 ptr = 0;
38         }
39         public static interface LoggerInterface {
40                 /**
41                  * Logs the `Record`
42                  */
43                 void log(Record record);
44         }
45         private static class LDKLoggerHolder { Logger held; }
46         public static Logger new_impl(LoggerInterface arg) {
47                 final LDKLoggerHolder impl_holder = new LDKLoggerHolder();
48                 impl_holder.held = new Logger(new bindings.LDKLogger() {
49                         @Override public void log(long record) {
50                                 org.ldk.structs.Record record_hu_conv = null; if (record < 0 || record > 4096) { record_hu_conv = new org.ldk.structs.Record(null, record); }
51                                 arg.log(record_hu_conv);
52                                 Reference.reachabilityFence(arg);
53                         }
54                 });
55                 return impl_holder.held;
56         }
57 }