Class JniResponseRegistry


  • public class JniResponseRegistry
    extends java.lang.Object
    Registry for storing Java objects returned from JNI calls. This allows us to pass object IDs through the Response protobuf instead of trying to pass Rust pointers that would become invalid.

    The registry uses weak references to allow garbage collection when objects are no longer needed.

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void clear()
      Clear all stored objects.
      static java.lang.Object retrieveAndRemove​(long id)
      Retrieve and remove a Java object by its ID.
      static int size()
      Get the current number of stored objects.
      static long storeObject​(java.lang.Object object)
      Store a Java object and return its ID.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JniResponseRegistry

        public JniResponseRegistry()
    • Method Detail

      • storeObject

        public static long storeObject​(java.lang.Object object)
        Store a Java object and return its ID. This is used when JNI returns a converted Java object that needs to be passed through the Response protobuf.
        Parameters:
        object - The Java object to store
        Returns:
        The ID that can be used to retrieve the object
      • retrieveAndRemove

        public static java.lang.Object retrieveAndRemove​(long id)
        Retrieve and remove a Java object by its ID. This is called from valueFromPointer to get the actual Java object. The object is removed after retrieval to prevent memory leaks.
        Parameters:
        id - The ID of the object to retrieve
        Returns:
        The Java object, or null if not found
      • clear

        public static void clear()
        Clear all stored objects. Called during client cleanup.
      • size

        public static int size()
        Get the current number of stored objects. Useful for debugging and monitoring.