001package org.consensusj.bitcoin.rx; 002 003import org.consensusj.bitcoin.json.pojo.ChainTip; 004import org.reactivestreams.Publisher; 005import org.reactivestreams.Subscriber; 006 007/** 008 * Marker type for {@code Publisher<ChainTip>}. In a future release this may use {@link java.util.concurrent.Flow.Publisher}. 009 * Because of type erasure in Java generics we need this to strongly type parameters that require a {@code Publisher<ChainTip>}. 010 */ 011public interface ChainTipPublisher extends Publisher<ChainTip> { 012 /** 013 * Adapt a {@code Publisher<ChainTip} 014 * @param publisher to wrap 015 * @return wrapped publisher 016 */ 017 static ChainTipPublisher of(Publisher<ChainTip> publisher) { 018 return new Wrapper(publisher); 019 } 020 021 class Wrapper implements ChainTipPublisher { 022 private final Publisher<ChainTip> publisher; 023 024 Wrapper(Publisher<ChainTip> publisher) { 025 this.publisher = publisher; 026 } 027 028 @Override 029 public void subscribe(Subscriber<? super ChainTip> s) { 030 publisher.subscribe(s); 031 } 032 } 033}