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 * A trait encapsulating the operations required of a logger.
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;
22 @Override @SuppressWarnings("deprecation")
23 protected void finalize() throws Throwable {
24 if (ptr != 0) { bindings.Logger_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.Logger_free(ptr); }
39 public static interface LoggerInterface {
41 * Logs the [`Record`].
43 void log(Record record);
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 if (record_hu_conv != null) { record_hu_conv.ptrs_to.add(this); };
52 arg.log(record_hu_conv);
53 Reference.reachabilityFence(arg);
56 return impl_holder.held;