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

Merge dev/1.0.0 into main #139

Merged
merged 28 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a43f437
Sync with `dev/1.0.0` from Zenoh-Kotlin (#93)
DariusIMP Jun 13, 2024
cf3d0d8
chore: Sync Rust toolchain
eclipse-zenoh-bot Jun 13, 2024
4208ad1
Merge pull request #94 from eclipse-zenoh/eclipse-zenoh-bot/sync-tool…
eclipse-zenoh-bot Jun 13, 2024
4750298
chore: Sync Rust toolchain
eclipse-zenoh-bot Jul 16, 2024
d8aafee
Merge pull request #104 from eclipse-zenoh/eclipse-zenoh-bot/sync-too…
eclipse-zenoh-bot Jul 16, 2024
daf450b
chore: Sync Rust toolchain
eclipse-zenoh-bot Jul 16, 2024
9c1f09d
Merge pull request #105 from eclipse-zenoh/eclipse-zenoh-bot/sync-too…
eclipse-zenoh-bot Jul 16, 2024
5b43ccd
Update gradle action (#103)
diogomatsubara Jul 16, 2024
9eff9c4
Update main release workflow (#106) (#107)
diogomatsubara Jul 17, 2024
2725f8f
refactor(jni): refactoring JNI + adapting to new changes from dev/1.0…
DariusIMP Jul 18, 2024
761388a
Update deprecated actions (#109) (#110)
diogomatsubara Jul 19, 2024
2f98132
build: Sync with eclipse-zenoh/zenoh@5d09cf7 from 2024-08-01 (#117)
eclipse-zenoh-bot Aug 1, 2024
09260f3
Merge 'main' into 'dev/1.0.0' (#118)
DariusIMP Aug 5, 2024
a80760a
build: Sync with eclipse-zenoh/zenoh@b1e4dba from 2024-08-05 (#121)
eclipse-zenoh-bot Aug 6, 2024
57f0c95
build: Sync with eclipse-zenoh/zenoh@b7d42ef from 2024-08-06 (#122)
eclipse-zenoh-bot Aug 6, 2024
b87cb71
build: Sync with eclipse-zenoh/zenoh@2d5ab7c from 2024-08-06 (#123)
eclipse-zenoh-bot Aug 6, 2024
2a25de1
Add Consolidation::Auto to JNI and Java API (#124)
oteffahi Aug 6, 2024
a5adc24
Change default consolidation mode to AUTO (#125)
oteffahi Aug 7, 2024
73e0baf
build: Sync with eclipse-zenoh/zenoh@0e2f78a from 2024-08-14 (#130)
eclipse-zenoh-bot Aug 14, 2024
e32abaf
Bump dev version to `1.0.0-dev` (#129)
zettascale-bot Aug 20, 2024
658d33b
build: Sync with eclipse-zenoh/zenoh@8b027e9 from 2024-08-22 (#131)
eclipse-zenoh-bot Aug 26, 2024
b38c596
build: Sync with eclipse-zenoh/zenoh@7f7d648 from 2024-08-28 (#133)
eclipse-zenoh-bot Aug 29, 2024
6bded94
Merge branch 'main' of github.com:eclipse-zenoh/zenoh-java into dev/1…
DariusIMP Aug 29, 2024
336417b
build: Sync with eclipse-zenoh/zenoh@3579f12 from 2024-08-29 (#136)
eclipse-zenoh-bot Aug 29, 2024
65d67cb
build: Sync with eclipse-zenoh/zenoh@926208c from 2024-08-29 (#137)
eclipse-zenoh-bot Aug 30, 2024
7d4566e
Merge pull request #135 from ZettaScaleLabs/main_sync
Mallets Aug 30, 2024
302947e
Point to eclipse-zenoh/zenoh branch=main
Mallets Aug 30, 2024
41500f9
Merge branch 'dev/1.0.0' of github.com:eclipse-zenoh/zenoh-java into …
Mallets Aug 30, 2024
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
5 changes: 2 additions & 3 deletions examples/src/main/java/io/zenoh/ZPubThr.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@

import io.zenoh.exceptions.ZenohException;
import io.zenoh.keyexpr.KeyExpr;
import io.zenoh.prelude.CongestionControl;
import io.zenoh.prelude.Encoding;
import io.zenoh.prelude.KnownEncoding;
import io.zenoh.publication.CongestionControl;
import io.zenoh.publication.Publisher;
import io.zenoh.value.Value;

Expand All @@ -30,7 +29,7 @@ public static void main(String[] args) throws ZenohException {
for (int i = 0; i < size; i++) {
data[i] = (byte) (i % 10);
}
Value value = new Value(data, new Encoding(KnownEncoding.EMPTY));
Value value = new Value(data, new Encoding(Encoding.ID.ZENOH_BYTES, null));
try (Session session = Session.open()) {
try (KeyExpr keyExpr = KeyExpr.tryFrom("test/thr")) {
try (Publisher publisher = session.declarePublisher(keyExpr).congestionControl(CongestionControl.BLOCK).res()) {
Expand Down
5 changes: 2 additions & 3 deletions examples/src/main/java/io/zenoh/ZPut.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import io.zenoh.exceptions.ZenohException;
import io.zenoh.keyexpr.KeyExpr;
import io.zenoh.prelude.SampleKind;
import io.zenoh.publication.CongestionControl;
import io.zenoh.publication.Priority;
import io.zenoh.prelude.CongestionControl;
import io.zenoh.prelude.Priority;

public class ZPut {
public static void main(String[] args) throws ZenohException {
Expand All @@ -29,7 +29,6 @@ public static void main(String[] args) throws ZenohException {
session.put(keyExpr, value)
.congestionControl(CongestionControl.BLOCK)
.priority(Priority.REALTIME)
.kind(SampleKind.PUT)
.res();
System.out.println("Putting Data ('" + keyExpr + "': '" + value + "')...");
}
Expand Down
2 changes: 1 addition & 1 deletion examples/src/main/java/io/zenoh/ZQueryable.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private static void handleRequests(BlockingQueue<Optional<Query>> receiver, KeyE
String valueInfo = query.getValue() != null ? " with value '" + query.getValue() + "'" : "";
System.out.println(">> [Queryable] Received Query '" + query.getSelector() + "'" + valueInfo);
try {
query.reply(keyExpr).success("Queryable from Java!").withKind(SampleKind.PUT).withTimeStamp(TimeStamp.getCurrentTime()).res();
query.reply(keyExpr).success("Queryable from Java!").timestamp(TimeStamp.getCurrentTime()).res();
} catch (Exception e) {
System.out.println(">> [Queryable] Error sending reply: " + e);
}
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "1.72.0"
channel = "1.75.0"
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.11.0-dev
1.0.0-dev
13 changes: 7 additions & 6 deletions zenoh-java/src/commonMain/kotlin/io/zenoh/Session.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import io.zenoh.exceptions.ZenohException
import io.zenoh.handlers.Callback
import io.zenoh.jni.JNISession
import io.zenoh.keyexpr.KeyExpr
import io.zenoh.prelude.QoS
import io.zenoh.publication.Delete
import io.zenoh.publication.Publisher
import io.zenoh.publication.Put
import io.zenoh.query.*
import io.zenoh.queryable.Query
import io.zenoh.queryable.Queryable
import io.zenoh.sample.Attachment
import io.zenoh.sample.Sample
import io.zenoh.selector.Selector
import io.zenoh.subscriber.Reliability
Expand Down Expand Up @@ -104,6 +104,7 @@ class Session private constructor(private val config: Config) : AutoCloseable {
jniSession = null
}

@Suppress("removal")
protected fun finalize() {
jniSession?.close()
}
Expand Down Expand Up @@ -355,10 +356,10 @@ class Session private constructor(private val config: Config) : AutoCloseable {
}

@Throws(SessionException::class)
internal fun resolvePublisher(builder: Publisher.Builder): Publisher {
internal fun resolvePublisher(keyExpr: KeyExpr, qos: QoS): Publisher {
return jniSession?.run {
declarePublisher(builder)
} ?: throw (sessionClosedException)
declarePublisher(keyExpr, qos)
} ?: throw(sessionClosedException)
}

@Throws(ZenohException::class)
Expand Down Expand Up @@ -389,7 +390,7 @@ class Session private constructor(private val config: Config) : AutoCloseable {
target: QueryTarget,
consolidation: ConsolidationMode,
value: Value?,
attachment: Attachment?,
attachment: ByteArray?,
): R? {
if (jniSession == null) {
throw sessionClosedException
Expand All @@ -404,7 +405,7 @@ class Session private constructor(private val config: Config) : AutoCloseable {

@Throws(ZenohException::class)
internal fun resolveDelete(keyExpr: KeyExpr, delete: Delete) {
jniSession?.run { performPut(keyExpr, delete) }
jniSession?.run { performDelete(keyExpr, delete) }
}

/** Launches the session through the jni session, returning the [Session] on success. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ package io.zenoh.exceptions
* This type of exception is thrown from the native code when something goes wrong regarding the
* communication between the Java/Kotlin layer and the native layer through the JNI.
*/
class JNIException : ZenohException()
class JNIException(msg: String?) : ZenohException(msg)
68 changes: 23 additions & 45 deletions zenoh-java/src/commonMain/kotlin/io/zenoh/jni/JNIKeyExpr.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,68 +24,46 @@ internal class JNIKeyExpr(internal val ptr: Long) {
@Throws(ZenohException::class)
fun tryFrom(keyExpr: String): KeyExpr {
Zenoh.load() // It may happen the zenoh library is not yet loaded when creating a key expression.
val keyExprPtr = tryFromViaJNI(keyExpr)
return KeyExpr(JNIKeyExpr(keyExprPtr))
return KeyExpr(tryFromViaJNI(keyExpr))
}

@Throws(ZenohException::class)
fun autocanonize(keyExpr: String): KeyExpr {
Zenoh.load()
val keyExprPtr = autocanonizeViaJNI(keyExpr)
return KeyExpr(JNIKeyExpr(keyExprPtr))
return KeyExpr(autocanonizeViaJNI(keyExpr))
}

@Throws(ZenohException::class)
private external fun tryFromViaJNI(keyExpr: String): Long
fun intersects(keyExprA: KeyExpr, keyExprB: KeyExpr): Boolean = intersectsViaJNI(
keyExprA.jniKeyExpr?.ptr ?: 0,
keyExprA.keyExpr,
keyExprB.jniKeyExpr?.ptr ?: 0,
keyExprB.keyExpr
)

@Throws(ZenohException::class)
private external fun autocanonizeViaJNI(keyExpr: String): Long
}
fun includes(keyExprA: KeyExpr, keyExprB: KeyExpr): Boolean = includesViaJNI(
keyExprA.jniKeyExpr?.ptr ?: 0,
keyExprA.keyExpr,
keyExprB.jniKeyExpr?.ptr ?: 0,
keyExprB.keyExpr
)

override fun toString(): String {
return getStringValueViaJNI(ptr)
}
@Throws(Exception::class)
private external fun tryFromViaJNI(keyExpr: String): String

fun intersects(other: KeyExpr): Boolean {
if (other.jniKeyExpr == null) {
return false
}
return intersectsViaJNI(ptr, other.jniKeyExpr!!.ptr)
}
@Throws(Exception::class)
private external fun autocanonizeViaJNI(keyExpr: String): String

fun includes(other: KeyExpr): Boolean {
if (other.jniKeyExpr == null) {
return false
}
return includesViaJNI(ptr, other.jniKeyExpr!!.ptr)
@Throws(Exception::class)
private external fun intersectsViaJNI(ptrA: Long, keyExprA: String, ptrB: Long, keyExprB: String): Boolean

@Throws(Exception::class)
private external fun includesViaJNI(ptrA: Long, keyExprA: String, ptrB: Long, keyExprB: String): Boolean
}

fun close() {
freePtrViaJNI(ptr)
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as JNIKeyExpr

return equalsViaJNI(ptr, other.ptr)
}

override fun hashCode(): Int {
return ptr.hashCode()
}

private external fun equalsViaJNI(ptrA: Long, ptrB: Long): Boolean

private external fun intersectsViaJNI(ptrA: Long, ptrB: Long): Boolean

private external fun includesViaJNI(ptrA: Long, ptrB: Long): Boolean

@Throws(ZenohException::class)
private external fun getStringValueViaJNI(ptr: Long): String

/** Frees the underlying native KeyExpr. */
private external fun freePtrViaJNI(ptr: Long)
}
73 changes: 10 additions & 63 deletions zenoh-java/src/commonMain/kotlin/io/zenoh/jni/JNIPublisher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,35 @@

package io.zenoh.jni

import io.zenoh.*
import io.zenoh.exceptions.ZenohException
import io.zenoh.publication.CongestionControl
import io.zenoh.publication.Priority
import io.zenoh.sample.Attachment
import io.zenoh.value.Value

/**
* Adapter class to handle the interactions with Zenoh through JNI for a [Publisher].
* Adapter class to handle the interactions with Zenoh through JNI for a [io.zenoh.publication.Publisher].
*
* @property ptr: raw pointer to the underlying native Publisher.
*/
internal class JNIPublisher(private val ptr: Long) {

/**
* Put value through the publisher.
* Put operation.
*
* @param value The [Value] to be put.
* @param attachment Optional [Attachment].
* @param attachment Optional attachment.
*/
@Throws(ZenohException::class)
fun put(value: Value, attachment: Attachment?) {
putViaJNI(value.payload, value.encoding.knownEncoding.ordinal, attachment?.let { encodeAttachment(it) }, ptr)
fun put(value: Value, attachment: ByteArray?) {
putViaJNI(value.payload, value.encoding.id.ordinal, value.encoding.schema, attachment, ptr)
}

/**
* Delete operation.
*
* @param attachment Optional [Attachment].
* @param attachment Optional attachment.
*/
@Throws(ZenohException::class)
fun delete(attachment: Attachment?) {
deleteViaJNI(attachment?.let { encodeAttachment(it) }, ptr)
fun delete(attachment: ByteArray?) {
deleteViaJNI(attachment, ptr)
}

/**
Expand All @@ -58,63 +54,14 @@ internal class JNIPublisher(private val ptr: Long) {
freePtrViaJNI(ptr)
}

/**
* Set the congestion control policy of the publisher.
*
* This function is not thread safe.
*
* @param congestionControl: The [CongestionControl] policy.
*/
@Throws(ZenohException::class)
fun setCongestionControl(congestionControl: CongestionControl) {
setCongestionControlViaJNI(congestionControl.ordinal, ptr)
}

/**
* Set the priority policy of the publisher.
*
* This function is not thread safe.
*
* @param priority: The [Priority] policy.
*/
@Throws(ZenohException::class)
fun setPriority(priority: Priority) {
setPriorityViaJNI(priority.value, ptr)
}

/**
* Set the congestion control policy of the publisher through JNI.
*
* This function is NOT thread safe.
*
* @param congestionControl The congestion control policy.
* @param ptr Pointer to the publisher.
*/
@Throws(ZenohException::class)
private external fun setCongestionControlViaJNI(congestionControl: Int, ptr: Long)

/**
* Set the priority policy of the publisher through JNI.
*
* This function is NOT thread safe.
*
* @param priority The priority policy.
* @param ptr Pointer to the publisher.
*/
@Throws(ZenohException::class)
private external fun setPriorityViaJNI(priority: Int, ptr: Long)


/** Puts through the native Publisher. */
@Throws(ZenohException::class)
private external fun putViaJNI(
valuePayload: ByteArray, valueEncoding: Int, encodedAttachment: ByteArray?, ptr: Long
valuePayload: ByteArray, encodingId: Int, encodingSchema: String?, attachment: ByteArray?, ptr: Long
)

@Throws(ZenohException::class)
private external fun deleteViaJNI(encodedAttachment: ByteArray?, ptr: Long)
private external fun deleteViaJNI(attachment: ByteArray?, ptr: Long)

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

}
Loading