Skip to content

Commit ff9b395

Browse files
authored
Merge pull request #299 from ZettaScaleLabs/api/make-replier-id-global
[ZEN-587] Change `replier_id` type to `EntityGlobalId`
2 parents b50354f + a8a1b4c commit ff9b395

File tree

8 files changed

+81
-51
lines changed

8 files changed

+81
-51
lines changed

zenoh-java/src/commonMain/kotlin/io/zenoh/config/ZenohId.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package io.zenoh.config
1616

1717
import io.zenoh.jni.JNIZenohId
18+
import kotlin.math.absoluteValue
1819

1920
/**
2021
* The global unique id of a Zenoh peer.
@@ -38,3 +39,20 @@ data class ZenohId internal constructor(internal val bytes: ByteArray) {
3839
return bytes.contentHashCode()
3940
}
4041
}
42+
43+
/**
44+
* The global unique id of a Zenoh entity.
45+
* Contains two fields:
46+
* - zid: the global unique id of a Zenoh peer.
47+
* - eid: *unsigned* unique identifier of the entity within the Zenoh peer.
48+
*/
49+
data class EntityGlobalId internal constructor(
50+
val zid: ZenohId,
51+
// Rename default getter which is not accessible on Java due to unsigned type
52+
@get:JvmName("getEidUInt") val eid: UInt,
53+
) {
54+
55+
@Suppress("unused")
56+
// Manually defined getter for Java
57+
fun getEid(): Long = eid.toLong().absoluteValue
58+
}

zenoh-java/src/commonMain/kotlin/io/zenoh/jni/JNILiveliness.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package io.zenoh.jni
1616

1717
import io.zenoh.bytes.Encoding
1818
import io.zenoh.bytes.into
19+
import io.zenoh.config.EntityGlobalId
1920
import io.zenoh.config.ZenohId
2021
import io.zenoh.exceptions.ZError
2122
import io.zenoh.handlers.Callback
@@ -47,7 +48,8 @@ internal object JNILiveliness {
4748
onClose: Runnable
4849
): R {
4950
val getCallback = JNIGetCallback {
50-
replierId: ByteArray?,
51+
replierZid: ByteArray?,
52+
replierEid: Int,
5153
success: Boolean,
5254
keyExpr2: String?,
5355
payload: ByteArray,
@@ -73,10 +75,10 @@ internal object JNILiveliness {
7375
QoS(CongestionControl.fromInt(congestionControl), Priority.fromInt(priority), express),
7476
attachmentBytes?.into()
7577
)
76-
reply = Reply.Success(replierId?.let { ZenohId(it) }, sample)
78+
reply = Reply.Success(replierZid?.let { EntityGlobalId(ZenohId(it), replierEid.toUInt()) }, sample)
7779
} else {
7880
reply = Reply.Error(
79-
replierId?.let { ZenohId(it) },
81+
replierZid?.let { EntityGlobalId(ZenohId(it), replierEid.toUInt()) },
8082
payload.into(),
8183
Encoding(encodingId, schema = encodingSchema)
8284
)

zenoh-java/src/commonMain/kotlin/io/zenoh/jni/JNIQuerier.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import io.zenoh.annotations.Unstable
1818
import io.zenoh.bytes.Encoding
1919
import io.zenoh.bytes.IntoZBytes
2020
import io.zenoh.bytes.into
21+
import io.zenoh.config.EntityGlobalId
2122
import io.zenoh.config.ZenohId
2223
import io.zenoh.exceptions.ZError
2324
import io.zenoh.handlers.Callback
@@ -61,7 +62,8 @@ internal class JNIQuerier(val ptr: Long) {
6162
encoding: Encoding?
6263
): R {
6364
val getCallback = JNIGetCallback {
64-
replierId: ByteArray?,
65+
replierZid: ByteArray?,
66+
replierEid: Int,
6567
success: Boolean,
6668
keyExpr2: String?,
6769
payload2: ByteArray,
@@ -87,10 +89,10 @@ internal class JNIQuerier(val ptr: Long) {
8789
QoS(CongestionControl.fromInt(congestionControl), Priority.fromInt(priority), express),
8890
attachmentBytes?.into()
8991
)
90-
reply = Reply.Success(replierId?.let { ZenohId(it) }, sample)
92+
reply = Reply.Success(replierZid?.let { EntityGlobalId(ZenohId(it), replierEid.toUInt()) }, sample)
9193
} else {
9294
reply = Reply.Error(
93-
replierId?.let { ZenohId(it) },
95+
replierZid?.let { EntityGlobalId(ZenohId(it), replierEid.toUInt()) },
9496
payload2.into(),
9597
Encoding(encodingId, schema = encodingSchema)
9698
)

zenoh-java/src/commonMain/kotlin/io/zenoh/jni/JNISession.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import io.zenoh.config.ZenohId
2828
import io.zenoh.bytes.into
2929
import io.zenoh.Config
3030
import io.zenoh.annotations.Unstable
31+
import io.zenoh.config.EntityGlobalId
3132
import io.zenoh.handlers.Handler
3233
import io.zenoh.pubsub.*
3334
import io.zenoh.qos.CongestionControl
@@ -234,7 +235,8 @@ internal class JNISession(val sessionPtr: Long) {
234235
options: GetOptions
235236
) {
236237
val getCallback = JNIGetCallback {
237-
replierId: ByteArray?,
238+
replierZid: ByteArray?,
239+
replierEid: Int,
238240
success: Boolean,
239241
keyExpr: String?,
240242
payload1: ByteArray,
@@ -260,10 +262,10 @@ internal class JNISession(val sessionPtr: Long) {
260262
QoS(CongestionControl.fromInt(congestionControl), Priority.fromInt(priority), express),
261263
attachmentBytes?.into()
262264
)
263-
reply = Reply.Success(replierId?.let { ZenohId(it) }, sample)
265+
reply = Reply.Success(replierZid?.let { EntityGlobalId(ZenohId(it), replierEid.toUInt()) }, sample)
264266
} else {
265267
reply = Reply.Error(
266-
replierId?.let { ZenohId(it) },
268+
replierZid?.let { EntityGlobalId(ZenohId(it), replierEid.toUInt()) },
267269
payload1.into(),
268270
Encoding(encodingId, schema = encodingSchema)
269271
)
@@ -299,7 +301,8 @@ internal class JNISession(val sessionPtr: Long) {
299301
options: GetOptions
300302
): R {
301303
val getCallback = JNIGetCallback {
302-
replierId: ByteArray?,
304+
replierZid: ByteArray?,
305+
replierEid: Int,
303306
success: Boolean,
304307
keyExpr: String?,
305308
payload1: ByteArray,
@@ -325,10 +328,10 @@ internal class JNISession(val sessionPtr: Long) {
325328
QoS(CongestionControl.fromInt(congestionControl), Priority.fromInt(priority), express),
326329
attachmentBytes?.into()
327330
)
328-
reply = Reply.Success(replierId?.let { ZenohId(it) }, sample)
331+
reply = Reply.Success(replierZid?.let { EntityGlobalId(ZenohId(it), replierEid.toUInt()) }, sample)
329332
} else {
330333
reply = Reply.Error(
331-
replierId?.let { ZenohId(it) },
334+
replierZid?.let { EntityGlobalId(ZenohId(it), replierEid.toUInt()) },
332335
payload1.into(),
333336
Encoding(encodingId, schema = encodingSchema)
334337
)

zenoh-java/src/commonMain/kotlin/io/zenoh/jni/callbacks/JNIGetCallback.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ package io.zenoh.jni.callbacks
1717
internal fun interface JNIGetCallback {
1818

1919
fun run(
20-
replierId: ByteArray?,
20+
replierZid: ByteArray?,
21+
replierEid: Int,
2122
success: Boolean,
2223
keyExpr: String?,
2324
payload: ByteArray,

zenoh-java/src/commonMain/kotlin/io/zenoh/query/Reply.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import io.zenoh.ZenohType
1818
import io.zenoh.bytes.Encoding
1919
import io.zenoh.bytes.IntoZBytes
2020
import io.zenoh.bytes.ZBytes
21-
import io.zenoh.config.ZenohId
21+
import io.zenoh.config.EntityGlobalId
2222
import io.zenoh.sample.Sample
2323
import io.zenoh.qos.CongestionControl
2424
import io.zenoh.qos.Priority
@@ -28,16 +28,16 @@ import org.apache.commons.net.ntp.TimeStamp
2828
/**
2929
* Class to represent a Zenoh Reply to a remote query.
3030
*
31-
* @property replierId: unique ID identifying the replier.
31+
* @property replierId: unique global ID identifying the replier.
3232
* @see Success
3333
* @see Error
3434
*/
35-
sealed class Reply private constructor(val replierId: ZenohId?) : ZenohType {
35+
sealed class Reply private constructor(val replierId: EntityGlobalId?) : ZenohType {
3636

3737
/**
3838
* A Success reply.
3939
*/
40-
class Success internal constructor(replierId: ZenohId?, val sample: Sample) : Reply(replierId) {
40+
class Success internal constructor(replierId: EntityGlobalId?, val sample: Sample) : Reply(replierId) {
4141

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

6464
override fun toString(): String {

0 commit comments

Comments
 (0)