Interface Instance<T>

    • Method Detail

      • invoke

        Instance invoke​(String methodName,
                        InvocationArg... args)
        Invokes a method of the instance of the class that is set for this Instance
        Parameters:
        methodName - The method name
        args - The arguments to use for invoking the method
        Returns:
        A Instance instance containing the result of the invocation
      • invokeStatic

        Instance invokeStatic​(String methodName,
                              InvocationArg... args)
        Invokes a static method of the class that is set for this Instance
        Parameters:
        methodName - The static method name
        args - The arguments to use for invoking the static method
        Returns:
        A Instance instance containing the result of the invocation
      • invokeAsyncToChannel

        void invokeAsyncToChannel​(long functionPointerAddress,
                                  String methodName,
                                  InvocationArg... args)
        Invokes asynchronously a method of the instance of the class that is set for this Instance. The result of the invocation must be a Future. When the Future returned from the invocation completes, j4rs will invoke native Rust code to either send a success value or a failure.

        Please note that it is best that this function returns a CompletableFuture, as this improves performance. j4rs handles simple Futures with polling using an internal ScheduledExecutorService with one thread and this has apparent performance issues. You may have a look at J4rsPolledFuture for more details.

        Parameters:
        functionPointerAddress - The address of the function pointer that will be used when the Future completes, in the native side, in order to actually perform the callback and complete a Future that is created in Rust and awaits for the Java Future to complete.
        methodName - The method name
        args - The arguments to use when invoking the callback method (the functionPointer)
      • invokeToChannel

        void invokeToChannel​(long channelAddress,
                             String methodName,
                             InvocationArg... args)
        Invokes a method of the instance of the class that is set for this Instance. The result of the invocation should be provided later using the doCallback method of a NativeCallbackToRustChannelSupport class. Any possible returned objects from the actual synchronous invocation of the defined method will be dropped.
        Parameters:
        channelAddress - The memory address of the channel
        methodName - The method name
        args - The arguments
      • initializeCallbackChannel

        void initializeCallbackChannel​(long channelAddress)
        Initialize a callback channel for this Instance. The channel can be used by Java to send values to Rust using the doCallback method of a NativeCallbackToRustChannelSupport class.
        Parameters:
        channelAddress - The memory address of the channel
      • field

        Instance field​(String fieldName)
        Retrieves the instance held under the Field fieldName
        Parameters:
        fieldName - The name of the field to retrieve
        Returns:
        A Instance instance containing the defined field.
      • cast

        static <T> Instance cast​(Instance from,
                                 String toClass)
        Casts a the object that is contained in a Instance to an object of class clazz.
        Type Parameters:
        T - Generically defined return type
        Parameters:
        from - The Instance to cast.
        toClass - The class that the provided Instance should be casted to
        Returns:
        A Instance instance containing the result of the cast.
      • cloneInstance

        static <T> Instance cloneInstance​(Instance from)
        Clones a Instance
        Type Parameters:
        T - Generically defined return type
        Parameters:
        from - The object to clone.
        Returns:
        a Instance instance.
      • getOrDeserializeJavaObject

        default T getOrDeserializeJavaObject()