Skip to content

Commit a43f437

Browse files
DariusIMPdiogomatsubaraeclipse-zenoh-bot
authored
Sync with dev/1.0.0 from Zenoh-Kotlin (#93)
* fix: cargo-deb install from +stable and --locked (#83) * build: Sync with eclipse-zenoh/zenoh@25f06bd from 2024-05-21 (#84) Co-authored-by: eclipse-zenoh-bot <[email protected]> * build: Sync with eclipse-zenoh/zenoh@3118d31 from 2024-05-28 (#85) Co-authored-by: eclipse-zenoh-bot <[email protected]> * build: Sync with eclipse-zenoh/zenoh@009f666 from 2024-05-30 (#86) Co-authored-by: eclipse-zenoh-bot <[email protected]> * build: Sync with eclipse-zenoh/zenoh@d574654 from 2024-06-03 (#87) Co-authored-by: eclipse-zenoh-bot <[email protected]> * chore: Update artifacts action to v4 (#88) artifacts actions v3 are deprecated * build: Sync with eclipse-zenoh/zenoh@c279982 from 2024-06-05 (#89) Co-authored-by: eclipse-zenoh-bot <[email protected]> * build: Sync with eclipse-zenoh/zenoh@d8e66de from 2024-06-10 (#90) Co-authored-by: eclipse-zenoh-bot <[email protected]> * issue(1.0.0 upgrade): sync zenoh-jni with zenoh-kotlin repository's dev/1.0.0 branch * issue(1.0.0 upgrade): sync with zenoh-kotlin dev/1.0.0 branch * issue(1.0.0 upgrade): update examples --------- Co-authored-by: Diogo Matsubara <[email protected]> Co-authored-by: eclipse-zenoh-bot <[email protected]> Co-authored-by: eclipse-zenoh-bot <[email protected]>
1 parent d7b2d3b commit a43f437

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2851
-2343
lines changed

.github/workflows/publish-jvm.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
shell: bash
6969
run: |
7070
case ${{ matrix.job.target }} in
71-
*-linux-gnu*) cargo install cargo-deb ;;
71+
*-linux-gnu*) cargo +stable install cargo-deb --locked;;
7272
esac
7373
7474
case ${{ matrix.job.target }} in
@@ -120,7 +120,7 @@ jobs:
120120
esac
121121
122122
- name: "Upload packages"
123-
uses: actions/upload-artifact@v3
123+
uses: actions/upload-artifact@v4
124124
with:
125125
name: ${{ matrix.job.target }}
126126
path: |
@@ -143,7 +143,7 @@ jobs:
143143
run: mkdir ${{env.JNI_LIB_PATHS}}
144144

145145
- name: Download result of previous builds
146-
uses: actions/download-artifact@v3
146+
uses: actions/download-artifact@v4
147147
with:
148148
path: ${{env.JNI_LIB_PATHS}}
149149

examples/src/main/java/io/zenoh/ZPubThr.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616

1717
import io.zenoh.exceptions.ZenohException;
1818
import io.zenoh.keyexpr.KeyExpr;
19+
import io.zenoh.prelude.CongestionControl;
1920
import io.zenoh.prelude.Encoding;
20-
import io.zenoh.prelude.KnownEncoding;
21-
import io.zenoh.publication.CongestionControl;
2221
import io.zenoh.publication.Publisher;
2322
import io.zenoh.value.Value;
2423

@@ -30,7 +29,7 @@ public static void main(String[] args) throws ZenohException {
3029
for (int i = 0; i < size; i++) {
3130
data[i] = (byte) (i % 10);
3231
}
33-
Value value = new Value(data, new Encoding(KnownEncoding.EMPTY));
32+
Value value = new Value(data, new Encoding(Encoding.ID.ZENOH_BYTES, null));
3433
try (Session session = Session.open()) {
3534
try (KeyExpr keyExpr = KeyExpr.tryFrom("test/thr")) {
3635
try (Publisher publisher = session.declarePublisher(keyExpr).congestionControl(CongestionControl.BLOCK).res()) {

examples/src/main/java/io/zenoh/ZPut.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import io.zenoh.exceptions.ZenohException;
1818
import io.zenoh.keyexpr.KeyExpr;
1919
import io.zenoh.prelude.SampleKind;
20-
import io.zenoh.publication.CongestionControl;
21-
import io.zenoh.publication.Priority;
20+
import io.zenoh.prelude.CongestionControl;
21+
import io.zenoh.prelude.Priority;
2222

2323
public class ZPut {
2424
public static void main(String[] args) throws ZenohException {
@@ -29,7 +29,6 @@ public static void main(String[] args) throws ZenohException {
2929
session.put(keyExpr, value)
3030
.congestionControl(CongestionControl.BLOCK)
3131
.priority(Priority.REALTIME)
32-
.kind(SampleKind.PUT)
3332
.res();
3433
System.out.println("Putting Data ('" + keyExpr + "': '" + value + "')...");
3534
}

examples/src/main/java/io/zenoh/ZQueryable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private static void handleRequests(BlockingQueue<Optional<Query>> receiver, KeyE
5151
String valueInfo = query.getValue() != null ? " with value '" + query.getValue() + "'" : "";
5252
System.out.println(">> [Queryable] Received Query '" + query.getSelector() + "'" + valueInfo);
5353
try {
54-
query.reply(keyExpr).success("Queryable from Java!").withKind(SampleKind.PUT).withTimeStamp(TimeStamp.getCurrentTime()).res();
54+
query.reply(keyExpr).success("Queryable from Java!").timestamp(TimeStamp.getCurrentTime()).res();
5555
} catch (Exception e) {
5656
System.out.println(">> [Queryable] Error sending reply: " + e);
5757
}

zenoh-java/src/commonMain/kotlin/io/zenoh/Session.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ import io.zenoh.exceptions.ZenohException
1919
import io.zenoh.handlers.Callback
2020
import io.zenoh.jni.JNISession
2121
import io.zenoh.keyexpr.KeyExpr
22+
import io.zenoh.prelude.QoS
2223
import io.zenoh.publication.Delete
2324
import io.zenoh.publication.Publisher
2425
import io.zenoh.publication.Put
2526
import io.zenoh.query.*
2627
import io.zenoh.queryable.Query
2728
import io.zenoh.queryable.Queryable
28-
import io.zenoh.sample.Attachment
2929
import io.zenoh.sample.Sample
3030
import io.zenoh.selector.Selector
3131
import io.zenoh.subscriber.Reliability
@@ -104,6 +104,7 @@ class Session private constructor(private val config: Config) : AutoCloseable {
104104
jniSession = null
105105
}
106106

107+
@Suppress("removal")
107108
protected fun finalize() {
108109
jniSession?.close()
109110
}
@@ -355,10 +356,10 @@ class Session private constructor(private val config: Config) : AutoCloseable {
355356
}
356357

357358
@Throws(SessionException::class)
358-
internal fun resolvePublisher(builder: Publisher.Builder): Publisher {
359+
internal fun resolvePublisher(keyExpr: KeyExpr, qos: QoS): Publisher {
359360
return jniSession?.run {
360-
declarePublisher(builder)
361-
} ?: throw (sessionClosedException)
361+
declarePublisher(keyExpr, qos)
362+
} ?: throw(sessionClosedException)
362363
}
363364

364365
@Throws(ZenohException::class)
@@ -389,7 +390,7 @@ class Session private constructor(private val config: Config) : AutoCloseable {
389390
target: QueryTarget,
390391
consolidation: ConsolidationMode,
391392
value: Value?,
392-
attachment: Attachment?,
393+
attachment: ByteArray?,
393394
): R? {
394395
if (jniSession == null) {
395396
throw sessionClosedException
@@ -404,7 +405,7 @@ class Session private constructor(private val config: Config) : AutoCloseable {
404405

405406
@Throws(ZenohException::class)
406407
internal fun resolveDelete(keyExpr: KeyExpr, delete: Delete) {
407-
jniSession?.run { performPut(keyExpr, delete) }
408+
jniSession?.run { performDelete(keyExpr, delete) }
408409
}
409410

410411
/** Launches the session through the jni session, returning the [Session] on success. */

zenoh-java/src/commonMain/kotlin/io/zenoh/exceptions/JNIException.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ package io.zenoh.exceptions
2020
* This type of exception is thrown from the native code when something goes wrong regarding the
2121
* communication between the Java/Kotlin layer and the native layer through the JNI.
2222
*/
23-
class JNIException : ZenohException()
23+
class JNIException(msg: String?) : ZenohException(msg)

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

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -24,68 +24,46 @@ internal class JNIKeyExpr(internal val ptr: Long) {
2424
@Throws(ZenohException::class)
2525
fun tryFrom(keyExpr: String): KeyExpr {
2626
Zenoh.load() // It may happen the zenoh library is not yet loaded when creating a key expression.
27-
val keyExprPtr = tryFromViaJNI(keyExpr)
28-
return KeyExpr(JNIKeyExpr(keyExprPtr))
27+
return KeyExpr(tryFromViaJNI(keyExpr))
2928
}
3029

3130
@Throws(ZenohException::class)
3231
fun autocanonize(keyExpr: String): KeyExpr {
3332
Zenoh.load()
34-
val keyExprPtr = autocanonizeViaJNI(keyExpr)
35-
return KeyExpr(JNIKeyExpr(keyExprPtr))
33+
return KeyExpr(autocanonizeViaJNI(keyExpr))
3634
}
3735

38-
@Throws(ZenohException::class)
39-
private external fun tryFromViaJNI(keyExpr: String): Long
36+
fun intersects(keyExprA: KeyExpr, keyExprB: KeyExpr): Boolean = intersectsViaJNI(
37+
keyExprA.jniKeyExpr?.ptr ?: 0,
38+
keyExprA.keyExpr,
39+
keyExprB.jniKeyExpr?.ptr ?: 0,
40+
keyExprB.keyExpr
41+
)
4042

41-
@Throws(ZenohException::class)
42-
private external fun autocanonizeViaJNI(keyExpr: String): Long
43-
}
43+
fun includes(keyExprA: KeyExpr, keyExprB: KeyExpr): Boolean = includesViaJNI(
44+
keyExprA.jniKeyExpr?.ptr ?: 0,
45+
keyExprA.keyExpr,
46+
keyExprB.jniKeyExpr?.ptr ?: 0,
47+
keyExprB.keyExpr
48+
)
4449

45-
override fun toString(): String {
46-
return getStringValueViaJNI(ptr)
47-
}
50+
@Throws(Exception::class)
51+
private external fun tryFromViaJNI(keyExpr: String): String
4852

49-
fun intersects(other: KeyExpr): Boolean {
50-
if (other.jniKeyExpr == null) {
51-
return false
52-
}
53-
return intersectsViaJNI(ptr, other.jniKeyExpr!!.ptr)
54-
}
53+
@Throws(Exception::class)
54+
private external fun autocanonizeViaJNI(keyExpr: String): String
5555

56-
fun includes(other: KeyExpr): Boolean {
57-
if (other.jniKeyExpr == null) {
58-
return false
59-
}
60-
return includesViaJNI(ptr, other.jniKeyExpr!!.ptr)
56+
@Throws(Exception::class)
57+
private external fun intersectsViaJNI(ptrA: Long, keyExprA: String, ptrB: Long, keyExprB: String): Boolean
58+
59+
@Throws(Exception::class)
60+
private external fun includesViaJNI(ptrA: Long, keyExprA: String, ptrB: Long, keyExprB: String): Boolean
6161
}
6262

6363
fun close() {
6464
freePtrViaJNI(ptr)
6565
}
6666

67-
override fun equals(other: Any?): Boolean {
68-
if (this === other) return true
69-
if (javaClass != other?.javaClass) return false
70-
71-
other as JNIKeyExpr
72-
73-
return equalsViaJNI(ptr, other.ptr)
74-
}
75-
76-
override fun hashCode(): Int {
77-
return ptr.hashCode()
78-
}
79-
80-
private external fun equalsViaJNI(ptrA: Long, ptrB: Long): Boolean
81-
82-
private external fun intersectsViaJNI(ptrA: Long, ptrB: Long): Boolean
83-
84-
private external fun includesViaJNI(ptrA: Long, ptrB: Long): Boolean
85-
86-
@Throws(ZenohException::class)
87-
private external fun getStringValueViaJNI(ptr: Long): String
88-
8967
/** Frees the underlying native KeyExpr. */
9068
private external fun freePtrViaJNI(ptr: Long)
9169
}

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

Lines changed: 10 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,35 @@
1414

1515
package io.zenoh.jni
1616

17-
import io.zenoh.*
1817
import io.zenoh.exceptions.ZenohException
19-
import io.zenoh.publication.CongestionControl
20-
import io.zenoh.publication.Priority
21-
import io.zenoh.sample.Attachment
2218
import io.zenoh.value.Value
2319

2420
/**
25-
* Adapter class to handle the interactions with Zenoh through JNI for a [Publisher].
21+
* Adapter class to handle the interactions with Zenoh through JNI for a [io.zenoh.publication.Publisher].
2622
*
2723
* @property ptr: raw pointer to the underlying native Publisher.
2824
*/
2925
internal class JNIPublisher(private val ptr: Long) {
3026

3127
/**
32-
* Put value through the publisher.
28+
* Put operation.
3329
*
3430
* @param value The [Value] to be put.
35-
* @param attachment Optional [Attachment].
31+
* @param attachment Optional attachment.
3632
*/
3733
@Throws(ZenohException::class)
38-
fun put(value: Value, attachment: Attachment?) {
39-
putViaJNI(value.payload, value.encoding.knownEncoding.ordinal, attachment?.let { encodeAttachment(it) }, ptr)
34+
fun put(value: Value, attachment: ByteArray?) {
35+
putViaJNI(value.payload, value.encoding.id.ordinal, value.encoding.schema, attachment, ptr)
4036
}
4137

4238
/**
4339
* Delete operation.
4440
*
45-
* @param attachment Optional [Attachment].
41+
* @param attachment Optional attachment.
4642
*/
4743
@Throws(ZenohException::class)
48-
fun delete(attachment: Attachment?) {
49-
deleteViaJNI(attachment?.let { encodeAttachment(it) }, ptr)
44+
fun delete(attachment: ByteArray?) {
45+
deleteViaJNI(attachment, ptr)
5046
}
5147

5248
/**
@@ -58,63 +54,14 @@ internal class JNIPublisher(private val ptr: Long) {
5854
freePtrViaJNI(ptr)
5955
}
6056

61-
/**
62-
* Set the congestion control policy of the publisher.
63-
*
64-
* This function is not thread safe.
65-
*
66-
* @param congestionControl: The [CongestionControl] policy.
67-
*/
68-
@Throws(ZenohException::class)
69-
fun setCongestionControl(congestionControl: CongestionControl) {
70-
setCongestionControlViaJNI(congestionControl.ordinal, ptr)
71-
}
72-
73-
/**
74-
* Set the priority policy of the publisher.
75-
*
76-
* This function is not thread safe.
77-
*
78-
* @param priority: The [Priority] policy.
79-
*/
80-
@Throws(ZenohException::class)
81-
fun setPriority(priority: Priority) {
82-
setPriorityViaJNI(priority.value, ptr)
83-
}
84-
85-
/**
86-
* Set the congestion control policy of the publisher through JNI.
87-
*
88-
* This function is NOT thread safe.
89-
*
90-
* @param congestionControl The congestion control policy.
91-
* @param ptr Pointer to the publisher.
92-
*/
93-
@Throws(ZenohException::class)
94-
private external fun setCongestionControlViaJNI(congestionControl: Int, ptr: Long)
95-
96-
/**
97-
* Set the priority policy of the publisher through JNI.
98-
*
99-
* This function is NOT thread safe.
100-
*
101-
* @param priority The priority policy.
102-
* @param ptr Pointer to the publisher.
103-
*/
104-
@Throws(ZenohException::class)
105-
private external fun setPriorityViaJNI(priority: Int, ptr: Long)
106-
107-
108-
/** Puts through the native Publisher. */
10957
@Throws(ZenohException::class)
11058
private external fun putViaJNI(
111-
valuePayload: ByteArray, valueEncoding: Int, encodedAttachment: ByteArray?, ptr: Long
59+
valuePayload: ByteArray, encodingId: Int, encodingSchema: String?, attachment: ByteArray?, ptr: Long
11260
)
11361

11462
@Throws(ZenohException::class)
115-
private external fun deleteViaJNI(encodedAttachment: ByteArray?, ptr: Long)
63+
private external fun deleteViaJNI(attachment: ByteArray?, ptr: Long)
11664

117-
/** Frees the underlying native Publisher. */
11865
private external fun freePtrViaJNI(ptr: Long)
11966

12067
}

0 commit comments

Comments
 (0)