@@ -21,7 +21,8 @@ import io.zenoh.bytes.ZBytes
2121import io.zenoh.bytes.into
2222import io.zenoh.config.ZenohId
2323import io.zenoh.exceptions.ZError
24- import io.zenoh.exceptions.wrapJNIExceptionAsZError
24+ import io.zenoh.exceptions.throwZError
25+ import io.zenoh.exceptions.throwZError0
2526import io.zenoh.handlers.BlockingQueueHandler
2627import io.zenoh.handlers.Callback
2728import io.zenoh.handlers.Handler
@@ -387,8 +388,8 @@ class Session private constructor(private val config: Config) : AutoCloseable {
387388 @Throws(ZError ::class )
388389 fun declareKeyExpr (keyExpr : String ): KeyExpr {
389390 val zSession = zSession ? : throw sessionClosedException
390- val keyexpr = wrapJNIExceptionAsZError {
391- KeyExpr (io.zenoh.jni.session.zSessionDeclareKeyexpr(zSession, keyExpr))
391+ val keyexpr = run {
392+ KeyExpr (io.zenoh.jni.session.zSessionDeclareKeyexpr(zSession, keyExpr, throwZError ))
392393 }
393394 strongDeclarations.add(keyexpr)
394395 return keyexpr
@@ -410,8 +411,8 @@ class Session private constructor(private val config: Config) : AutoCloseable {
410411 if (handle.isClosed()) {
411412 throw ZError (" Attempting to undeclare a non declared key expression." )
412413 }
413- wrapJNIExceptionAsZError {
414- io.zenoh.jni.session.zSessionUndeclareKeyexpr(zSession, handle)
414+ run {
415+ io.zenoh.jni.session.zSessionUndeclareKeyexpr(zSession, handle, throwZError )
415416 }
416417 }
417418
@@ -586,14 +587,15 @@ class Session private constructor(private val config: Config) : AutoCloseable {
586587 @Throws(ZError ::class )
587588 internal fun resolvePublisher (keyExpr : KeyExpr , options : PublisherOptions ): Publisher {
588589 val zSession = zSession ? : throw sessionClosedException
589- val publisher = wrapJNIExceptionAsZError {
590+ val publisher = run {
590591 val zPublisher = io.zenoh.jni.session.zSessionDeclarePublisher(
591592 zSession,
592593 keyExpr.exprSel, keyExpr.exprStr, keyExpr.exprHandleOwned(),
593594 options.congestionControl.jni,
594595 options.priority.jni,
595596 options.express,
596- options.reliability.jni
597+ options.reliability.jni,
598+ throwZError
597599 )
598600 Publisher (
599601 keyExpr,
@@ -612,12 +614,13 @@ class Session private constructor(private val config: Config) : AutoCloseable {
612614 keyExpr : KeyExpr , handler : Handler <Sample , R >
613615 ): HandlerSubscriber <R > {
614616 val zSession = zSession ? : throw sessionClosedException
615- val subscriber = wrapJNIExceptionAsZError {
617+ val subscriber = run {
616618 val zSubscriber = io.zenoh.jni.session.zSessionDeclareSubscriber(
617619 zSession,
618620 keyExpr.exprSel, keyExpr.exprStr, keyExpr.exprHandleOwned(),
619621 sampleCallbackOf { handler.handle(it) },
620- io.zenoh.jni.callbacks.Callback { handler.onClose() }
622+ io.zenoh.jni.callbacks.Callback { handler.onClose() },
623+ throwZError
621624 )
622625 HandlerSubscriber (keyExpr, zSubscriber, handler.receiver())
623626 }
@@ -630,12 +633,13 @@ class Session private constructor(private val config: Config) : AutoCloseable {
630633 keyExpr : KeyExpr , callback : Callback <Sample >
631634 ): CallbackSubscriber {
632635 val zSession = zSession ? : throw sessionClosedException
633- val subscriber = wrapJNIExceptionAsZError {
636+ val subscriber = run {
634637 val zSubscriber = io.zenoh.jni.session.zSessionDeclareSubscriber(
635638 zSession,
636639 keyExpr.exprSel, keyExpr.exprStr, keyExpr.exprHandleOwned(),
637640 sampleCallbackOf { callback.run (it) },
638- io.zenoh.jni.callbacks.Callback { }
641+ io.zenoh.jni.callbacks.Callback { },
642+ throwZError
639643 )
640644 CallbackSubscriber (keyExpr, zSubscriber)
641645 }
@@ -648,13 +652,14 @@ class Session private constructor(private val config: Config) : AutoCloseable {
648652 keyExpr : KeyExpr , handler : Handler <Query , R >, options : QueryableOptions
649653 ): HandlerQueryable <R > {
650654 val zSession = zSession ? : throw sessionClosedException
651- val queryable = wrapJNIExceptionAsZError {
655+ val queryable = run {
652656 val zQueryable = io.zenoh.jni.session.zSessionDeclareQueryable(
653657 zSession,
654658 keyExpr.exprSel, keyExpr.exprStr, keyExpr.exprHandleOwned(),
655659 options.complete,
656660 queryCallbackOf { handler.handle(it) },
657- io.zenoh.jni.callbacks.Callback { handler.onClose() }
661+ io.zenoh.jni.callbacks.Callback { handler.onClose() },
662+ throwZError
658663 )
659664 HandlerQueryable (keyExpr, zQueryable, handler.receiver())
660665 }
@@ -667,13 +672,14 @@ class Session private constructor(private val config: Config) : AutoCloseable {
667672 keyExpr : KeyExpr , callback : Callback <Query >, options : QueryableOptions
668673 ): CallbackQueryable {
669674 val zSession = zSession ? : throw sessionClosedException
670- val queryable = wrapJNIExceptionAsZError {
675+ val queryable = run {
671676 val zQueryable = io.zenoh.jni.session.zSessionDeclareQueryable(
672677 zSession,
673678 keyExpr.exprSel, keyExpr.exprStr, keyExpr.exprHandleOwned(),
674679 options.complete,
675680 queryCallbackOf { callback.run (it) },
676- io.zenoh.jni.callbacks.Callback { }
681+ io.zenoh.jni.callbacks.Callback { },
682+ throwZError
677683 )
678684 CallbackQueryable (keyExpr, zQueryable)
679685 }
@@ -687,7 +693,7 @@ class Session private constructor(private val config: Config) : AutoCloseable {
687693 options : QuerierOptions
688694 ): Querier {
689695 val zSession = zSession ? : throw sessionClosedException
690- val querier = wrapJNIExceptionAsZError {
696+ val querier = run {
691697 val zQuerier = io.zenoh.jni.session.zSessionDeclareQuerier(
692698 zSession,
693699 keyExpr.exprSel, keyExpr.exprStr, keyExpr.exprHandleOwned(),
@@ -697,7 +703,8 @@ class Session private constructor(private val config: Config) : AutoCloseable {
697703 options.priority.jni,
698704 options.express,
699705 options.timeout.toMillis(),
700- options.acceptReplies.toFlat()
706+ options.acceptReplies.toFlat(),
707+ throwZError
701708 )
702709 Querier (
703710 keyExpr,
@@ -720,7 +727,7 @@ class Session private constructor(private val config: Config) : AutoCloseable {
720727 options : GetOptions
721728 ): R {
722729 val zSession = zSession ? : throw sessionClosedException
723- return wrapJNIExceptionAsZError {
730+ return run {
724731 val sel = selector.into()
725732 io.zenoh.jni.session.zSessionGet(
726733 zSession,
@@ -739,7 +746,8 @@ class Session private constructor(private val config: Config) : AutoCloseable {
739746 (options.encoding ? : Encoding .defaultEncoding()).repr,
740747 options.attachment?.into()?.bytes,
741748 replyCallbackOf { handler.handle(it) },
742- io.zenoh.jni.callbacks.Callback { handler.onClose() }
749+ io.zenoh.jni.callbacks.Callback { handler.onClose() },
750+ throwZError
743751 )
744752 handler.receiver()
745753 }
@@ -752,7 +760,7 @@ class Session private constructor(private val config: Config) : AutoCloseable {
752760 options : GetOptions
753761 ) {
754762 val zSession = zSession ? : throw sessionClosedException
755- wrapJNIExceptionAsZError {
763+ run {
756764 val sel = selector.into()
757765 io.zenoh.jni.session.zSessionGet(
758766 zSession,
@@ -771,15 +779,16 @@ class Session private constructor(private val config: Config) : AutoCloseable {
771779 (options.encoding ? : Encoding .defaultEncoding()).repr,
772780 options.attachment?.into()?.bytes,
773781 replyCallbackOf { callback.run (it) },
774- io.zenoh.jni.callbacks.Callback { }
782+ io.zenoh.jni.callbacks.Callback { },
783+ throwZError
775784 )
776785 }
777786 }
778787
779788 @Throws(ZError ::class )
780789 internal fun resolvePut (keyExpr : KeyExpr , payload : IntoZBytes , putOptions : PutOptions ) {
781790 val zSession = zSession ? : return
782- wrapJNIExceptionAsZError {
791+ run {
783792 io.zenoh.jni.session.zSessionPut(
784793 zSession,
785794 keyExpr.exprSel,
@@ -791,15 +800,16 @@ class Session private constructor(private val config: Config) : AutoCloseable {
791800 putOptions.priority.jni,
792801 putOptions.express,
793802 putOptions.attachment?.into()?.bytes,
794- putOptions.reliability.jni
803+ putOptions.reliability.jni,
804+ throwZError
795805 )
796806 }
797807 }
798808
799809 @Throws(ZError ::class )
800810 internal fun resolveDelete (keyExpr : KeyExpr , deleteOptions : DeleteOptions ) {
801811 val zSession = zSession ? : return
802- wrapJNIExceptionAsZError {
812+ run {
803813 io.zenoh.jni.session.zSessionDelete(
804814 zSession,
805815 keyExpr.exprSel,
@@ -809,38 +819,30 @@ class Session private constructor(private val config: Config) : AutoCloseable {
809819 deleteOptions.priority.jni,
810820 deleteOptions.express,
811821 deleteOptions.attachment?.into()?.bytes,
812- deleteOptions.reliability.jni
822+ deleteOptions.reliability.jni,
823+ throwZError
813824 )
814825 }
815826 }
816827
817828 @Throws(ZError ::class )
818829 internal fun zid (): ZenohId {
819830 val zSession = zSession ? : throw sessionClosedException
820- return wrapJNIExceptionAsZError { ZenohId (io.zenoh.jni.session.zSessionZid(zSession)) }
831+ return ZenohId (io.zenoh.jni.session.zSessionZid(zSession, throwZError0))
821832 }
822833
823834 @Throws(ZError ::class )
824835 internal fun getPeersId (): List <ZenohId > {
825836 val zSession = zSession ? : throw sessionClosedException
826- // Output expansion (M4): the native side folds each ZZenohId into this
827- // accumulator in one pass — the caller owns the list (no intermediate
828- // List<ZZenohId>). `zid` is the typed ZZenohId value class.
829- return wrapJNIExceptionAsZError {
830- io.zenoh.jni.session.zSessionPeersZid(zSession, ArrayList <ZenohId >()) { list, zid ->
831- list.add(ZenohId (zid)); list
832- }
833- }
837+ // Canonical model: `ZZenohId` is a value_blob (no canonical output), so
838+ // the native fn returns `List<ZZenohId>` directly; wrap each as ZenohId.
839+ return io.zenoh.jni.session.zSessionPeersZid(zSession, throwZError0).map { ZenohId (it) }
834840 }
835841
836842 @Throws(ZError ::class )
837843 internal fun getRoutersId (): List <ZenohId > {
838844 val zSession = zSession ? : throw sessionClosedException
839- return wrapJNIExceptionAsZError {
840- io.zenoh.jni.session.zSessionRoutersZid(zSession, ArrayList <ZenohId >()) { list, zid ->
841- list.add(ZenohId (zid)); list
842- }
843- }
845+ return io.zenoh.jni.session.zSessionRoutersZid(zSession, throwZError0).map { ZenohId (it) }
844846 }
845847
846848 /* * Launches the session, returning the [Session] on success. */
@@ -849,9 +851,8 @@ class Session private constructor(private val config: Config) : AutoCloseable {
849851 ZenohLoad
850852 // `z_open` consumes the config by value; clone so the SDK [Config] stays
851853 // reusable for the caller (e.g. opening more than one session).
852- this .zSession = wrapJNIExceptionAsZError {
853- io.zenoh.jni.session.zOpen(io.zenoh.jni.config.zConfigClone(config.zConfig))
854- }
854+ this .zSession =
855+ io.zenoh.jni.session.zOpen(io.zenoh.jni.config.zConfigClone(config.zConfig, throwZError0), throwZError)
855856 return this
856857 }
857858}
0 commit comments