-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ChainTipPublisher class, be a little lazier
* Add ChainTipPublisher class (to deal with type erasure in DI, etc.) * RxBitcoinClient: don't always wait for connection in initChainTipService(), actively connect if useZmq, lazily wait if not useZmq * TxOutSetService: require ChainTipPublisher in constructor, this allows the service to be passive/lazy depending upon the ChainTipPublisher implementation. * ChainTipPublishers: static method never() returns do-nothing Publisher
- Loading branch information
1 parent
beaf95f
commit 8f61bb0
Showing
8 changed files
with
72 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...-jsonrpc/src/main/java/org/consensusj/bitcoin/rx/jsonrpc/test/TestChainTipPublishers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.consensusj.bitcoin.rx.jsonrpc.test; | ||
|
||
import io.reactivex.rxjava3.core.Flowable; | ||
import org.consensusj.bitcoin.rx.ChainTipPublisher; | ||
|
||
/** | ||
* Useful for testing. | ||
*/ | ||
public class TestChainTipPublishers { | ||
/** | ||
* @return A {@link ChainTipPublisher} that never emits items and never closes. | ||
*/ | ||
public static ChainTipPublisher never() { | ||
return ChainTipPublisher.of(Flowable.never()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 31 additions & 3 deletions
34
cj-btc-rx/src/main/java/org/consensusj/bitcoin/rx/ChainTipPublisher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,33 @@ | ||
package org.consensusj.bitcoin.rx;/** | ||
* | ||
package org.consensusj.bitcoin.rx; | ||
|
||
import org.consensusj.bitcoin.json.pojo.ChainTip; | ||
import org.reactivestreams.Publisher; | ||
import org.reactivestreams.Subscriber; | ||
|
||
/** | ||
* Marker type for {@code Publisher<ChainTip>}. In a future release this may use {@link java.util.concurrent.Flow.Publisher}. | ||
* Because of type erasure in Java generics we need this to strongly type parameters that require a {@code Publisher<ChainTip>}. | ||
*/ | ||
public class ChainTipPublisher { | ||
public interface ChainTipPublisher extends Publisher<ChainTip> { | ||
/** | ||
* Adapt a {@code Publisher<ChainTip} | ||
* @param publisher to wrap | ||
* @return wrapped publisher | ||
*/ | ||
static ChainTipPublisher of(Publisher<ChainTip> publisher) { | ||
return new Wrapper(publisher); | ||
} | ||
|
||
class Wrapper implements ChainTipPublisher { | ||
private final Publisher<ChainTip> publisher; | ||
|
||
Wrapper(Publisher<ChainTip> publisher) { | ||
this.publisher = publisher; | ||
} | ||
|
||
@Override | ||
public void subscribe(Subscriber<? super ChainTip> s) { | ||
publisher.subscribe(s); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters