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

Revert "Api alignment" #168

Merged
merged 1 commit into from
Aug 19, 2024
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
1 change: 0 additions & 1 deletion examples/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ dependencies {

tasks {
val examples = listOf(
"ZBytes",
"ZDelete",
"ZGet",
"ZPub",
Expand Down
237 changes: 0 additions & 237 deletions examples/src/main/kotlin/io.zenoh/ZBytes.kt

This file was deleted.

6 changes: 4 additions & 2 deletions examples/src/main/kotlin/io.zenoh/ZDelete.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ class ZDelete(private val emptyArgs: Boolean) : CliktCommand(
Session.open(config).onSuccess { session ->
session.use {
key.intoKeyExpr().onSuccess { keyExpr ->
println("Deleting resources matching '$keyExpr'...")
session.delete(keyExpr)
keyExpr.use {
println("Deleting resources matching '$keyExpr'...")
session.delete(keyExpr).res()
}
}
}
}
Expand Down
48 changes: 28 additions & 20 deletions examples/src/main/kotlin/io.zenoh/ZGet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ package io.zenoh
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.options.*
import com.github.ajalt.clikt.parameters.types.long
import io.zenoh.protocol.into
import io.zenoh.query.ConsolidationMode
import io.zenoh.query.QueryTarget
import io.zenoh.query.Reply
import io.zenoh.selector.intoSelector
import io.zenoh.value.Value
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.runBlocking
import java.time.Duration

Expand All @@ -31,28 +29,38 @@ class ZGet(private val emptyArgs: Boolean) : CliktCommand(
) {

override fun run() {
val config = loadConfig(emptyArgs, configFile, connect, listen, noMulticastScouting, mode)
val config = loadConfig(emptyArgs, configFile, connect, listen, noMulticastScouting,mode)

Session.open(config).onSuccess { session ->
session.use {
selector.intoSelector().onSuccess { selector ->
session.get(selector,
channel = Channel(),
value = payload?.let { Value(it) },
target = target?.let { QueryTarget.valueOf(it.uppercase()) } ?: QueryTarget.BEST_MATCHING,
attachment = attachment?.into(),
timeout = Duration.ofMillis(timeout))
.onSuccess { channelReceiver ->
runBlocking {
for (reply in channelReceiver) {
when (reply) {
is Reply.Success -> println("Received ('${reply.sample.keyExpr}': '${reply.sample.value}')")
is Reply.Error -> println("Received (ERROR: '${reply.error}')")
is Reply.Delete -> println("Received (DELETE '${reply.keyExpr}')")
}
selector.use {
session.get(selector)
.timeout(Duration.ofMillis(timeout))
.apply {
target?.let {
target(QueryTarget.valueOf(it.uppercase()))
}
attachment?.let {
withAttachment(it.toByteArray())
}
value?.let {
withValue(it)
}
}
.res()
.onSuccess { receiver ->
runBlocking {
for (reply in receiver!!) {
when (reply) {
is Reply.Success -> println("Received ('${reply.sample.keyExpr}': '${reply.sample.value}')")
is Reply.Error -> println("Received (ERROR: '${reply.error}')")
is Reply.Delete -> println("Received (DELETE '${reply.keyExpr}')")
}
}
}
}
}
}
}
}
Expand All @@ -64,8 +72,8 @@ class ZGet(private val emptyArgs: Boolean) : CliktCommand(
help = "The selection of resources to query [default: demo/example/**]",
metavar = "selector"
).default("demo/example/**")
private val payload by option(
"-p", "--payload", help = "An optional payload to put in the query.", metavar = "payload"
private val value by option(
"-v", "--value", help = "An optional value to put in the query.", metavar = "value"
)
private val target by option(
"-t",
Expand Down
39 changes: 21 additions & 18 deletions examples/src/main/kotlin/io.zenoh/ZPub.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package io.zenoh
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.options.*
import io.zenoh.keyexpr.intoKeyExpr
import io.zenoh.protocol.into

class ZPub(private val emptyArgs: Boolean) : CliktCommand(
help = "Zenoh Pub example"
Expand All @@ -29,23 +28,27 @@ class ZPub(private val emptyArgs: Boolean) : CliktCommand(
Session.open(config).onSuccess { session ->
session.use {
key.intoKeyExpr().onSuccess { keyExpr ->
println("Declaring publisher on '$keyExpr'...")
session.declarePublisher(keyExpr).onSuccess { pub ->
println("Press CTRL-C to quit...")
val attachment = attachment?.toByteArray()
var idx = 0
while (true) {
Thread.sleep(1000)
val payload = "[${
idx.toString().padStart(4, ' ')
}] $value"
println(
"Putting Data ('$keyExpr': '$payload')..."
)
attachment?.let {
pub.put(payload, attachment = it.into())
} ?: let { pub.put(payload) }
idx++
keyExpr.use {
println("Declaring publisher on '$keyExpr'...")
session.declarePublisher(keyExpr).res().onSuccess { pub ->
pub.use {
println("Press CTRL-C to quit...")
val attachment = attachment?.toByteArray()
var idx = 0
while (true) {
Thread.sleep(1000)
val payload = "[${
idx.toString().padStart(4, ' ')
}] $value"
println(
"Putting Data ('$keyExpr': '$payload')..."
)
attachment?.let {
pub.put(payload).withAttachment(attachment).res()
} ?: let { pub.put(payload).res() }
idx++
}
}
}
}
}
Expand Down
Loading