Rework holds_ref and clone logic somewhat
[ldk-java] / src / main / java / org / ldk / structs / ChannelMessageHandler.java
index d920f2d49697fd70003c19d85d13cc88c1280e80..d286901e7fb8399994beab0349b38468044a4fbc 100644 (file)
@@ -12,6 +12,7 @@ public class ChannelMessageHandler extends CommonBase {
        private ChannelMessageHandler(bindings.LDKChannelMessageHandler arg, bindings.LDKMessageSendEventsProvider MessageSendEventsProvider) {
                super(bindings.LDKChannelMessageHandler_new(arg, MessageSendEventsProvider));
                this.ptrs_to.add(arg);
+               this.ptrs_to.add(MessageSendEventsProvider);
                this.bindings_instance = arg;
        }
        @Override @SuppressWarnings("deprecation")
@@ -40,8 +41,10 @@ public class ChannelMessageHandler extends CommonBase {
                void handle_channel_reestablish(byte[] their_node_id, ChannelReestablish msg);
                void handle_error(byte[] their_node_id, ErrorMessage msg);
        }
-       public ChannelMessageHandler(ChannelMessageHandlerInterface arg, MessageSendEventsProvider.MessageSendEventsProviderInterface MessageSendEventsProvider) {
-               this(new bindings.LDKChannelMessageHandler() {
+       private static class LDKChannelMessageHandlerHolder { ChannelMessageHandler held; }
+       public static ChannelMessageHandler new_impl(ChannelMessageHandlerInterface arg, MessageSendEventsProvider.MessageSendEventsProviderInterface MessageSendEventsProvider_impl) {
+               final LDKChannelMessageHandlerHolder impl_holder = new LDKChannelMessageHandlerHolder();
+               impl_holder.held = new ChannelMessageHandler(new bindings.LDKChannelMessageHandler() {
                        @Override public void handle_open_channel(byte[] their_node_id, long their_features, long msg) {
                                InitFeatures their_features_hu_conv = new InitFeatures(null, their_features);
                                OpenChannel msg_hu_conv = new OpenChannel(null, msg);
@@ -119,7 +122,8 @@ public class ChannelMessageHandler extends CommonBase {
                                ErrorMessage msg_hu_conv = new ErrorMessage(null, msg);
                                arg.handle_error(their_node_id, msg_hu_conv);
                        }
-               }, new MessageSendEventsProvider(MessageSendEventsProvider).bindings_instance);
+               }, MessageSendEventsProvider.new_impl(MessageSendEventsProvider_impl).bindings_instance);
+               return impl_holder.held;
        }
        // Skipped ChannelMessageHandler_handle_open_channel
        // Skipped ChannelMessageHandler_handle_accept_channel