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

Remove "Custom Wildcard Subscription"-Logic for Specifications #61

Merged
merged 8 commits into from
Feb 1, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ internal class DataBrokerTransporter(
val entry = entryUpdate.entry

subscription.listeners.forEach { observer ->
Chrylo marked this conversation as resolved.
Show resolved Hide resolved
observer.onPropertyChanged(vssPath, field, entry)
observer.onPropertyChanged(entry.path, field, entry)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import org.eclipse.kuksa.DataBrokerTransporter
import org.eclipse.kuksa.PropertyListener
import org.eclipse.kuksa.VssSpecificationListener
import org.eclipse.kuksa.extension.TAG
import org.eclipse.kuksa.extension.createProperties
import org.eclipse.kuksa.proto.v1.Types
import org.eclipse.kuksa.proto.v1.Types.Field
import org.eclipse.kuksa.vsscore.model.VssProperty
import org.eclipse.kuksa.vsscore.model.VssSpecification
import org.eclipse.kuksa.vsscore.model.vssProperties

/**
* Creates [Subscription]s to the DataBroker to get notified about changes on the underlying vssPaths and fields.
Expand Down Expand Up @@ -91,13 +91,13 @@ internal class DataBrokerSubscriber(private val dataBrokerTransporter: DataBroke
field: Field = Field.FIELD_VALUE,
listener: VssSpecificationListener<T>,
) {
val leafProperties = specification.createProperties(field)
val vssPaths = leafProperties.map { it.vssPath }
val vssPath = specification.vssPath

val specificationPropertyListener = SpecificationPropertyListener(specification, vssPaths, listener)
vssPaths.forEach { vssPath ->
subscribe(vssPath, field, specificationPropertyListener)
}
val leafProperties = specification.vssProperties
val childPropertiesPaths = leafProperties.map { it.vssPath }

val specificationPropertyListener = SpecificationPropertyListener(specification, childPropertiesPaths, listener)
subscribe(vssPath, field, specificationPropertyListener)
}

/**
Expand All @@ -111,13 +111,13 @@ internal class DataBrokerSubscriber(private val dataBrokerTransporter: DataBroke
field: Field = Field.FIELD_VALUE,
listener: VssSpecificationListener<T>,
) {
val leafProperties = specification.createProperties(field)
val vssPaths = leafProperties.map { it.vssPath }
val vssPath = specification.vssPath

val specificationPropertyListener = SpecificationPropertyListener(specification, vssPaths, listener)
vssPaths.forEach { vssPath ->
unsubscribe(vssPath, field, specificationPropertyListener)
}
val leafProperties = specification.vssProperties
val childPropertiesPaths = leafProperties.map { it.vssPath }

val specificationPropertyListener = SpecificationPropertyListener(specification, childPropertiesPaths, listener)
unsubscribe(vssPath, field, specificationPropertyListener)
}

private companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ internal class SpecificationPropertyListener<T : VssSpecification>(
vssPaths: Collection<String>,
private val listener: VssSpecificationListener<T>,
) : PropertyListener {
// TODO: Remove as soon as the server supports subscribing to vssPaths which are not VssProperties
// Reduces the load on the observer for big VssSpecifications. We wait for the initial update
// of all VssProperties before notifying the observer about the first batch
private val initialSubscriptionUpdates = vssPaths.associateWith { false }.toMutableMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal class Subscription(

for (entryUpdate in lastSubscribeResponse.updatesList) {
val entry = entryUpdate.entry
observer.onPropertyChanged(vssPath, field, entry)
observer.onPropertyChanged(entry.path, field, entry)
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ class DataBrokerConnectionTest : BehaviorSpec({
dataBrokerConnection.subscribe(specification, listener = specificationListener)

then("The #onSpecificationChanged method is triggered") {
verify(
timeout = 100L,
exactly = 1,
) { specificationListener.onSpecificationChanged(any()) }
val capturingList = mutableListOf<VssDriver>()
verify(timeout = 100L, exactly = 1) {
specificationListener.onSpecificationChanged(capture(capturingList))
}
}

and("The initial value is different from the default for a child") {
Expand Down
Loading