solution: upstream apis as a controller Publisher

This commit is contained in:
Igor Artamonov
2019-09-06 00:15:10 -04:00
parent cdd9e6bf5f
commit 706f472355
17 changed files with 443 additions and 203 deletions

View File

@@ -24,6 +24,7 @@ import io.emeraldpay.grpc.Chain
import org.slf4j.LoggerFactory
import org.springframework.context.Lifecycle
import reactor.core.Disposable
import reactor.core.publisher.Mono
import java.lang.IllegalStateException
import java.time.Duration
@@ -116,16 +117,19 @@ open class ChainUpstreams (
}
}
override fun getApis(matcher: Selector.Matcher): Iterator<DirectEthereumApi> {
override fun getApis(matcher: Selector.Matcher): ApiSource {
val i = seq++
if (seq >= Int.MAX_VALUE / 2) {
seq = 0
}
return FilteringApiIterator(upstreams, i, matcher)
return FilteredApis(upstreams, matcher, i)
}
override fun getApi(matcher: Selector.Matcher): DirectEthereumApi {
return getApis(matcher).next()
override fun getApi(matcher: Selector.Matcher): Mono<DirectEthereumApi> {
val apis = getApis(matcher)
apis.request(1)
return Mono.from(apis)
.switchIfEmpty(Mono.error<DirectEthereumApi>(Exception("No API available")))
}
override fun getHead(): EthereumHead {