X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fbatteries%2FChannelManagerConstructor.java;h=db37118dfd71cb10f43dda02d21789d6facad658;hb=b479a721c55c876e716319c5074c7d150a59aa5c;hp=029fac792e0b407be50b8eeeb7ffe625ec4be2d0;hpb=a2d6728708f5a6de9f8ce28713fe49f2c5d9259b;p=ldk-java diff --git a/src/main/java/org/ldk/batteries/ChannelManagerConstructor.java b/src/main/java/org/ldk/batteries/ChannelManagerConstructor.java index 029fac79..db37118d 100644 --- a/src/main/java/org/ldk/batteries/ChannelManagerConstructor.java +++ b/src/main/java/org/ldk/batteries/ChannelManagerConstructor.java @@ -76,10 +76,32 @@ public class ChannelManagerConstructor { * we want to expose underlying details of the scorer itself. Thus, we expose a safe version that takes the lock * then returns a reference to this scorer. */ - @Nullable private final ProbabilisticScorer prob_scorer; + private final ProbabilisticScorer prob_scorer; private final Logger logger; private final KeysManager keys_manager; + /** + * Exposes the `ProbabilisticScorer` wrapped inside a lock. Don't forget to `close` this lock when you're done with + * it so normal scoring operation can continue. + */ + public class ScorerWrapper implements AutoCloseable { + private final Score lock; + public final ProbabilisticScorer prob_scorer; + private ScorerWrapper(Score lock, ProbabilisticScorer prob_scorer) { + this.lock = lock; this.prob_scorer = prob_scorer; + } + @Override public void close() throws Exception { + lock.destroy(); + } + } + /** + * Gets the `ProbabilisticScorer` which backs the public lockable `scorer`. Don't forget to `close` the lock when + * you're done with it. + */ + public ScorerWrapper get_locked_scorer() { + return new ScorerWrapper(this.scorer.as_LockableScore().lock(), this.prob_scorer); + } + /** * Deserializes a channel manager and a set of channel monitors from the given serialized copies and interface implementations *