Skip to content
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
18 changes: 18 additions & 0 deletions zenoh-java/src/commonMain/kotlin/io/zenoh/config/ZenohId.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package io.zenoh.config

import io.zenoh.jni.JNIZenohId
import kotlin.math.absoluteValue

/**
* The global unique id of a Zenoh peer.
Expand All @@ -38,3 +39,20 @@ data class ZenohId internal constructor(internal val bytes: ByteArray) {
return bytes.contentHashCode()
}
}

/**
* The global unique id of a Zenoh entity.
* Contains two fields:
* - zid: the global unique id of a Zenoh peer.
* - eid: *unsigned* unique identifier of the entity within the Zenoh peer.
*/
data class EntityGlobalId internal constructor(
val zid: ZenohId,
// Rename default getter which is not accessible on Java due to unsigned type
@get:JvmName("getEidUInt") val eid: UInt,
) {

@Suppress("unused")
// Manually defined getter for Java
fun getEid(): Long = eid.toLong().absoluteValue
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package io.zenoh.jni

import io.zenoh.bytes.Encoding
import io.zenoh.bytes.into
import io.zenoh.config.EntityGlobalId
import io.zenoh.config.ZenohId
import io.zenoh.exceptions.ZError
import io.zenoh.handlers.Callback
Expand Down Expand Up @@ -47,7 +48,8 @@ internal object JNILiveliness {
onClose: Runnable
): R {
val getCallback = JNIGetCallback {
replierId: ByteArray?,
replierZid: ByteArray?,
replierEid: Int,
success: Boolean,
keyExpr2: String?,
payload: ByteArray,
Expand All @@ -73,10 +75,10 @@ internal object JNILiveliness {
QoS(CongestionControl.fromInt(congestionControl), Priority.fromInt(priority), express),
attachmentBytes?.into()
)
reply = Reply.Success(replierId?.let { ZenohId(it) }, sample)
reply = Reply.Success(replierZid?.let { EntityGlobalId(ZenohId(it), replierEid.toUInt()) }, sample)
} else {
reply = Reply.Error(
replierId?.let { ZenohId(it) },
replierZid?.let { EntityGlobalId(ZenohId(it), replierEid.toUInt()) },
payload.into(),
Encoding(encodingId, schema = encodingSchema)
)
Expand Down
8 changes: 5 additions & 3 deletions zenoh-java/src/commonMain/kotlin/io/zenoh/jni/JNIQuerier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import io.zenoh.annotations.Unstable
import io.zenoh.bytes.Encoding
import io.zenoh.bytes.IntoZBytes
import io.zenoh.bytes.into
import io.zenoh.config.EntityGlobalId
import io.zenoh.config.ZenohId
import io.zenoh.exceptions.ZError
import io.zenoh.handlers.Callback
Expand Down Expand Up @@ -61,7 +62,8 @@ internal class JNIQuerier(val ptr: Long) {
encoding: Encoding?
): R {
val getCallback = JNIGetCallback {
replierId: ByteArray?,
replierZid: ByteArray?,
replierEid: Int,
success: Boolean,
keyExpr2: String?,
payload2: ByteArray,
Expand All @@ -87,10 +89,10 @@ internal class JNIQuerier(val ptr: Long) {
QoS(CongestionControl.fromInt(congestionControl), Priority.fromInt(priority), express),
attachmentBytes?.into()
)
reply = Reply.Success(replierId?.let { ZenohId(it) }, sample)
reply = Reply.Success(replierZid?.let { EntityGlobalId(ZenohId(it), replierEid.toUInt()) }, sample)
} else {
reply = Reply.Error(
replierId?.let { ZenohId(it) },
replierZid?.let { EntityGlobalId(ZenohId(it), replierEid.toUInt()) },
payload2.into(),
Encoding(encodingId, schema = encodingSchema)
)
Expand Down
15 changes: 9 additions & 6 deletions zenoh-java/src/commonMain/kotlin/io/zenoh/jni/JNISession.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import io.zenoh.config.ZenohId
import io.zenoh.bytes.into
import io.zenoh.Config
import io.zenoh.annotations.Unstable
import io.zenoh.config.EntityGlobalId
import io.zenoh.handlers.Handler
import io.zenoh.pubsub.*
import io.zenoh.qos.CongestionControl
Expand Down Expand Up @@ -234,7 +235,8 @@ internal class JNISession(val sessionPtr: Long) {
options: GetOptions
) {
val getCallback = JNIGetCallback {
replierId: ByteArray?,
replierZid: ByteArray?,
replierEid: Int,
success: Boolean,
keyExpr: String?,
payload1: ByteArray,
Expand All @@ -260,10 +262,10 @@ internal class JNISession(val sessionPtr: Long) {
QoS(CongestionControl.fromInt(congestionControl), Priority.fromInt(priority), express),
attachmentBytes?.into()
)
reply = Reply.Success(replierId?.let { ZenohId(it) }, sample)
reply = Reply.Success(replierZid?.let { EntityGlobalId(ZenohId(it), replierEid.toUInt()) }, sample)
} else {
reply = Reply.Error(
replierId?.let { ZenohId(it) },
replierZid?.let { EntityGlobalId(ZenohId(it), replierEid.toUInt()) },
payload1.into(),
Encoding(encodingId, schema = encodingSchema)
)
Expand Down Expand Up @@ -299,7 +301,8 @@ internal class JNISession(val sessionPtr: Long) {
options: GetOptions
): R {
val getCallback = JNIGetCallback {
replierId: ByteArray?,
replierZid: ByteArray?,
replierEid: Int,
success: Boolean,
keyExpr: String?,
payload1: ByteArray,
Expand All @@ -325,10 +328,10 @@ internal class JNISession(val sessionPtr: Long) {
QoS(CongestionControl.fromInt(congestionControl), Priority.fromInt(priority), express),
attachmentBytes?.into()
)
reply = Reply.Success(replierId?.let { ZenohId(it) }, sample)
reply = Reply.Success(replierZid?.let { EntityGlobalId(ZenohId(it), replierEid.toUInt()) }, sample)
} else {
reply = Reply.Error(
replierId?.let { ZenohId(it) },
replierZid?.let { EntityGlobalId(ZenohId(it), replierEid.toUInt()) },
payload1.into(),
Encoding(encodingId, schema = encodingSchema)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ package io.zenoh.jni.callbacks
internal fun interface JNIGetCallback {

fun run(
replierId: ByteArray?,
replierZid: ByteArray?,
replierEid: Int,
success: Boolean,
keyExpr: String?,
payload: ByteArray,
Expand Down
10 changes: 5 additions & 5 deletions zenoh-java/src/commonMain/kotlin/io/zenoh/query/Reply.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import io.zenoh.ZenohType
import io.zenoh.bytes.Encoding
import io.zenoh.bytes.IntoZBytes
import io.zenoh.bytes.ZBytes
import io.zenoh.config.ZenohId
import io.zenoh.config.EntityGlobalId
import io.zenoh.sample.Sample
import io.zenoh.qos.CongestionControl
import io.zenoh.qos.Priority
Expand All @@ -28,16 +28,16 @@ import org.apache.commons.net.ntp.TimeStamp
/**
* Class to represent a Zenoh Reply to a remote query.
*
* @property replierId: unique ID identifying the replier.
* @property replierId: unique global ID identifying the replier.
* @see Success
* @see Error
*/
sealed class Reply private constructor(val replierId: ZenohId?) : ZenohType {
sealed class Reply private constructor(val replierId: EntityGlobalId?) : ZenohType {

/**
* A Success reply.
*/
class Success internal constructor(replierId: ZenohId?, val sample: Sample) : Reply(replierId) {
class Success internal constructor(replierId: EntityGlobalId?, val sample: Sample) : Reply(replierId) {

override fun toString(): String {
return "Success(sample=$sample)"
Expand All @@ -58,7 +58,7 @@ sealed class Reply private constructor(val replierId: ZenohId?) : ZenohType {
/**
* An Error reply.
*/
class Error internal constructor(replierId: ZenohId?, val error: ZBytes, val encoding: Encoding) :
class Error internal constructor(replierId: EntityGlobalId?, val error: ZBytes, val encoding: Encoding) :
Reply(replierId) {

override fun toString(): String {
Expand Down
Loading
Loading