Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

report only available subscription in generic case #352

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import reactor.core.scheduler.Scheduler
class GenericEgressSubscription(
val multistream: Multistream,
val scheduler: Scheduler,
val methods: List<String>,
) : EgressSubscription {
override fun getAvailableTopics(): List<String> {
return methods
return multistream.getUpstreams()
.flatMap { (it as GenericUpstream).getIngressSubscription().getAvailableTopics() }
.distinct()
}

override fun subscribe(topic: String, params: Any?, matcher: Matcher): Flux<ByteArray> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@ import reactor.core.publisher.Mono
import java.time.Duration
import java.util.concurrent.ConcurrentHashMap

class GenericIngressSubscription(val conn: WsSubscriptions) : IngressSubscription {
class GenericIngressSubscription(val conn: WsSubscriptions, val methods: List<String>) : IngressSubscription {
override fun getAvailableTopics(): List<String> {
return emptyList() // not used now
return methods
}

private val holders = ConcurrentHashMap<Pair<String, Any?>, SubscriptionConnect<out Any>>()

@Suppress("UNCHECKED_CAST")
override fun <T> get(topic: String, params: Any?): SubscriptionConnect<T> {
return holders.computeIfAbsent(topic to params, { key -> GenericSubscriptionConnect(conn, key.first, key.second) }) as SubscriptionConnect<T>
return holders.computeIfAbsent(topic to params) { key ->
GenericSubscriptionConnect(
conn,
key.first,
key.second,
)
} as SubscriptionConnect<T>
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ object PolkadotChainSpecific : AbstractPollChainSpecific() {
}

override fun subscriptionBuilder(headScheduler: Scheduler): (Multistream) -> EgressSubscription {
return { ms -> GenericEgressSubscription(ms, headScheduler, DefaultPolkadotMethods.subs.map { it.first }) }
return { ms -> GenericEgressSubscription(ms, headScheduler) }
}

override fun validator(
Expand Down Expand Up @@ -118,7 +118,7 @@ object PolkadotChainSpecific : AbstractPollChainSpecific() {
}

override fun makeIngressSubscription(ws: WsSubscriptions): IngressSubscription {
return GenericIngressSubscription(ws)
return GenericIngressSubscription(ws, DefaultPolkadotMethods.subs.map { it.first })
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ object SolanaChainSpecific : AbstractChainSpecific() {
}

override fun makeIngressSubscription(ws: WsSubscriptions): IngressSubscription {
return GenericIngressSubscription(ws)
return GenericIngressSubscription(ws, DefaultSolanaMethods.subs.map { it.first })
}

override fun subscriptionBuilder(headScheduler: Scheduler): (Multistream) -> EgressSubscription {
return { ms -> GenericEgressSubscription(ms, headScheduler, DefaultSolanaMethods.subs.map { it.first }) }
return { ms -> GenericEgressSubscription(ms, headScheduler) }
}
}

Expand Down
Loading