Skip to content

Commit

Permalink
Align examples and remove reading from stdin (#47)
Browse files Browse the repository at this point in the history
* Remove reading from stdin

* Add queryable keyexpr to stdout

* Add index to ZPub payload
  • Loading branch information
oteffahi authored Apr 18, 2024
1 parent ffd6072 commit 6ba9cf6
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
12 changes: 7 additions & 5 deletions examples/src/main/kotlin/io.zenoh/ZPub.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,20 @@ class ZPub(private val emptyArgs: Boolean) : CliktCommand(
println("Declaring publisher on '$keyExpr'...")
session.declarePublisher(keyExpr).res().onSuccess { pub ->
pub.use {
println("Press CTRL-C to quit...")
val attachment = attachment?.let { decodeAttachment(it) }
var idx = 0
while (true) {
Thread.sleep(1000)
println(
"Putting Data ('$keyExpr': '[${
val payload = "[${
idx.toString().padStart(4, ' ')
}] $value')..."
}] $value"
println(
"Putting Data ('$keyExpr': '$payload')..."
)
attachment?.let {
pub.put(value).withAttachment(attachment).res()
} ?: let { pub.put(value).res() }
pub.put(payload).withAttachment(attachment).res()
} ?: let { pub.put(payload).res() }
idx++
}
}
Expand Down
3 changes: 1 addition & 2 deletions examples/src/main/kotlin/io.zenoh/ZPubThr.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ class ZPubThr(private val emptyArgs: Boolean) : CliktCommand(
var count: Long = 0
var start = System.currentTimeMillis()
val number = number.toLong()
println("Press CTRL-C to quit...")
while (true) {
pub.put(value).res().getOrThrow()

if (statsPrint) {
if (count < number) {
count++
Expand All @@ -100,7 +100,6 @@ class ZPubThr(private val emptyArgs: Boolean) : CliktCommand(
start = System.currentTimeMillis()
}
}

}
}
}
Expand Down
3 changes: 2 additions & 1 deletion examples/src/main/kotlin/io.zenoh/ZQueryable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ class ZQueryable(private val emptyArgs: Boolean) : CliktCommand(
session.use {
key.intoKeyExpr().onSuccess { keyExpr ->
keyExpr.use {
println("Declaring Queryable")
println("Declaring Queryable on " + key + "...")
session.declareQueryable(keyExpr).res().onSuccess { queryable ->
queryable.use {
println("Press CTRL-C to quit...")
queryable.receiver?.let { receiverChannel -> // The default receiver is a Channel we can process on a coroutine.
runBlocking {
handleRequests(receiverChannel, keyExpr)
Expand Down
1 change: 1 addition & 0 deletions examples/src/main/kotlin/io.zenoh/ZSub.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class ZSub(private val emptyArgs: Boolean) : CliktCommand(
println("Declaring Subscriber on '$keyExpr'...")
session.declareSubscriber(keyExpr).bestEffort().res().onSuccess { subscriber ->
subscriber.use {
println("Press CTRL-C to quit...")
runBlocking {
val receiver = subscriber.receiver!!
val iterator = receiver.iterator()
Expand Down
2 changes: 2 additions & 0 deletions examples/src/main/kotlin/io.zenoh/ZSubThr.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@ class ZSubThr(private val emptyArgs: Boolean) : CliktCommand(
println("Opening Session")
Session.open(config).onSuccess {
it.use { session ->
println("Press CTRL-C to quit...")
subscriber =
session.declareSubscriber(keyExpr).reliable().with { listener(number) }.res().getOrThrow()
while (subscriber.isValid()) {/* Keep alive the subscriber until the test is done. */
Thread.sleep(1000)
}
}
}
Expand Down

0 comments on commit 6ba9cf6

Please sign in to comment.