18988df07c1bcc7f08b115cc0a5c325274bddfef
[ldk-java] / src / main / java / org / ldk / structs / Retry.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 /**
12  * Strategies available to retry payment path failures for an [`Invoice`].
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class Retry extends CommonBase {
16         private Retry(Object _dummy, long ptr) { super(ptr); }
17         @Override @SuppressWarnings("deprecation")
18         protected void finalize() throws Throwable {
19                 super.finalize();
20                 if (ptr != 0) { bindings.Retry_free(ptr); }
21         }
22         static Retry constr_from_ptr(long ptr) {
23                 bindings.LDKRetry raw_val = bindings.LDKRetry_ref_from_ptr(ptr);
24                 if (raw_val.getClass() == bindings.LDKRetry.Attempts.class) {
25                         return new Attempts(ptr, (bindings.LDKRetry.Attempts)raw_val);
26                 }
27                 if (raw_val.getClass() == bindings.LDKRetry.Timeout.class) {
28                         return new Timeout(ptr, (bindings.LDKRetry.Timeout)raw_val);
29                 }
30                 assert false; return null; // Unreachable without extending the (internal) bindings interface
31         }
32
33         /**
34          * Max number of attempts to retry payment.
35          * 
36          * Note that this is the number of *path* failures, not full payment retries. For multi-path
37          * payments, if this is less than the total number of paths, we will never even retry all of the
38          * payment's paths.
39          */
40         public final static class Attempts extends Retry {
41                 public final long attempts;
42                 private Attempts(long ptr, bindings.LDKRetry.Attempts obj) {
43                         super(null, ptr);
44                         this.attempts = obj.attempts;
45                 }
46         }
47         /**
48          * Time elapsed before abandoning retries for a payment.
49          */
50         public final static class Timeout extends Retry {
51                 public final long timeout;
52                 private Timeout(long ptr, bindings.LDKRetry.Timeout obj) {
53                         super(null, ptr);
54                         this.timeout = obj.timeout;
55                 }
56         }
57         long clone_ptr() {
58                 long ret = bindings.Retry_clone_ptr(this.ptr);
59                 Reference.reachabilityFence(this);
60                 return ret;
61         }
62
63         /**
64          * Creates a copy of the Retry
65          */
66         public Retry clone() {
67                 long ret = bindings.Retry_clone(this.ptr);
68                 Reference.reachabilityFence(this);
69                 if (ret >= 0 && ret <= 4096) { return null; }
70                 org.ldk.structs.Retry ret_hu_conv = org.ldk.structs.Retry.constr_from_ptr(ret);
71                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
72                 return ret_hu_conv;
73         }
74
75         /**
76          * Utility method to constructs a new Attempts-variant Retry
77          */
78         public static Retry attempts(long a) {
79                 long ret = bindings.Retry_attempts(a);
80                 Reference.reachabilityFence(a);
81                 if (ret >= 0 && ret <= 4096) { return null; }
82                 org.ldk.structs.Retry ret_hu_conv = org.ldk.structs.Retry.constr_from_ptr(ret);
83                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
84                 return ret_hu_conv;
85         }
86
87         /**
88          * Utility method to constructs a new Timeout-variant Retry
89          */
90         public static Retry timeout(long a) {
91                 long ret = bindings.Retry_timeout(a);
92                 Reference.reachabilityFence(a);
93                 if (ret >= 0 && ret <= 4096) { return null; }
94                 org.ldk.structs.Retry ret_hu_conv = org.ldk.structs.Retry.constr_from_ptr(ret);
95                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
96                 return ret_hu_conv;
97         }
98
99         /**
100          * Checks if two Retrys contain equal inner contents.
101          * This ignores pointers and is_owned flags and looks at the values in fields.
102          */
103         public boolean eq(org.ldk.structs.Retry b) {
104                 boolean ret = bindings.Retry_eq(this.ptr, b == null ? 0 : b.ptr);
105                 Reference.reachabilityFence(this);
106                 Reference.reachabilityFence(b);
107                 return ret;
108         }
109
110         @Override public boolean equals(Object o) {
111                 if (!(o instanceof Retry)) return false;
112                 return this.eq((Retry)o);
113         }
114         /**
115          * Checks if two Retrys contain equal inner contents.
116          */
117         public long hash() {
118                 long ret = bindings.Retry_hash(this.ptr);
119                 Reference.reachabilityFence(this);
120                 return ret;
121         }
122
123         @Override public int hashCode() {
124                 return (int)this.hash();
125         }
126 }