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;
12 * Provides references to trait impls which handle different types of messages.
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class MessageHandler extends CommonBase {
16 MessageHandler(Object _dummy, long ptr) { super(ptr); }
17 @Override @SuppressWarnings("deprecation")
18 protected void finalize() throws Throwable {
20 if (ptr != 0) { bindings.MessageHandler_free(ptr); }
24 * A message handler which handles messages specific to channels. Usually this is just a
25 * [`ChannelManager`] object or an [`ErroringMessageHandler`].
27 * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
29 public ChannelMessageHandler get_chan_handler() {
30 long ret = bindings.MessageHandler_get_chan_handler(this.ptr);
31 Reference.reachabilityFence(this);
32 if (ret >= 0 && ret <= 4096) { return null; }
33 ChannelMessageHandler ret_hu_conv = new ChannelMessageHandler(null, ret);
34 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
39 * A message handler which handles messages specific to channels. Usually this is just a
40 * [`ChannelManager`] object or an [`ErroringMessageHandler`].
42 * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
44 public void set_chan_handler(ChannelMessageHandler val) {
45 bindings.MessageHandler_set_chan_handler(this.ptr, val == null ? 0 : val.ptr);
46 Reference.reachabilityFence(this);
47 Reference.reachabilityFence(val);
48 if (this != null) { this.ptrs_to.add(val); };
52 * A message handler which handles messages updating our knowledge of the network channel
53 * graph. Usually this is just a [`P2PGossipSync`] object or an [`IgnoringMessageHandler`].
55 * [`P2PGossipSync`]: crate::routing::gossip::P2PGossipSync
57 public RoutingMessageHandler get_route_handler() {
58 long ret = bindings.MessageHandler_get_route_handler(this.ptr);
59 Reference.reachabilityFence(this);
60 if (ret >= 0 && ret <= 4096) { return null; }
61 RoutingMessageHandler ret_hu_conv = new RoutingMessageHandler(null, ret);
62 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
67 * A message handler which handles messages updating our knowledge of the network channel
68 * graph. Usually this is just a [`P2PGossipSync`] object or an [`IgnoringMessageHandler`].
70 * [`P2PGossipSync`]: crate::routing::gossip::P2PGossipSync
72 public void set_route_handler(RoutingMessageHandler val) {
73 bindings.MessageHandler_set_route_handler(this.ptr, val == null ? 0 : val.ptr);
74 Reference.reachabilityFence(this);
75 Reference.reachabilityFence(val);
76 if (this != null) { this.ptrs_to.add(val); };
80 * Constructs a new MessageHandler given each field
82 public static MessageHandler of(ChannelMessageHandler chan_handler_arg, RoutingMessageHandler route_handler_arg) {
83 long ret = bindings.MessageHandler_new(chan_handler_arg == null ? 0 : chan_handler_arg.ptr, route_handler_arg == null ? 0 : route_handler_arg.ptr);
84 Reference.reachabilityFence(chan_handler_arg);
85 Reference.reachabilityFence(route_handler_arg);
86 if (ret >= 0 && ret <= 4096) { return null; }
87 org.ldk.structs.MessageHandler ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.MessageHandler(null, ret); }
88 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
89 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(chan_handler_arg); };
90 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(route_handler_arg); };