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

Adding onClose behaviour for Get, Queryable and Subscribers. #9

Merged
merged 19 commits into from
Oct 16, 2023

Conversation

DariusIMP
Copy link
Member

@DariusIMP DariusIMP commented Oct 11, 2023

In this PR we add the possibility of adding an onClose callback for Get requests, Subscribers and Queryables.
This is added to their respective builders, for instance:

...
val samples = ArrayList()
session.declareSubscriber(keyExpr).with { sample ->
   samples.add(sample)
}
.onClose {
  samples.forEach(sample -> println(sample))
}
.res()
...

Also the Handler interface is expanded with an "onClose" callback.
In the case of the default handler, which is ChannelHandler, the implementation consists of closing the channel upon finishing:

class ChannelHandler<T: ZenohType>(private val channel: Channel<T>) : Handler<T, Channel<T>> {

    override fun handle(t: T) {
        runBlocking { channel.send(t) }
    }

    override fun receiver(): Channel<T> {
        return channel
    }

    override fun onClose() {
        channel.close()
    }
}

If implementations of both mechanisms (on finish through the handler and on finish through the builders) are provided, they are stacked and both will be executed.

When does it happen that the onClose callbacks are invoked:

  • Get: the callbacks are executed when the querier is notified by Zenoh that it will not receive any more replies.
  • Queryable & Subscriber: then they are undeclared.

Kudos to @p-avital for his contribution to this PR by providing the low level utilities (like the CallOnDrop functionality).

Also:
 - fix Examples build
 - tidy up build.gradle.kts files
 - triggering compile zenoh-jni if needed when running gradle tasks.
 The possibility of adding an onFinish callback for Get requests, Subscribers and Queryables is added to their respective builders.
 Also the Handler interface is expanded with an "onFinish" callback (in the case of the default handler, which is ChannelHandler, the implementation consists of closing the channel upon finishing).
@p-avital
Copy link
Contributor

@Mallets @OlivierHecart wanna chime in on the name of the event? I had onClose in mind, just checking if anyone has a better idea and which one gets more votes :)

@DariusIMP DariusIMP changed the title Adding OnFinish behaviour for Get, Queryable and Subscribers. Adding onClose behaviour for Get, Queryable and Subscribers. Oct 16, 2023
@OlivierHecart OlivierHecart merged commit 3e0d300 into eclipse-zenoh:main Oct 16, 2023
2 checks passed
@OlivierHecart OlivierHecart deleted the queryables_end branch October 16, 2023 15:57
DariusIMP added a commit to ZettaScaleLabs/zenoh-kotlin that referenced this pull request Oct 17, 2023
…-zenoh#9)

* Restructuring packages aiming for Android compatibility, using Kotlin multiplatform plugin

* Edit cargo task in build.gradle.kts

* Reenabling examples.

* Making jvmTest commonTest

* [WIP] Target building Zenoh JNI

* Editing workflows after multiplatforming project.

* Editing README and build.gradle.kts

* Publish to JVM.

* Publish to JVM.

Also:
 - fix Examples build
 - tidy up build.gradle.kts files
 - triggering compile zenoh-jni if needed when running gradle tasks.

* Fix CI + edit README

* Fix CI + edit README

* OnFinish callback feature.

 The possibility of adding an onFinish callback for Get requests, Subscribers and Queryables is added to their respective builders.
 Also the Handler interface is expanded with an "onFinish" callback (in the case of the default handler, which is ChannelHandler, the implementation consists of closing the channel upon finishing).

* Fix doc comment.

* Fix formatting of Zenoh-JNI

* Renaming 'onFinish' with 'onClose'.

* Fix cargo fmt

* Fix CI workflow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants