Class JsonInvocationImpl<T>

java.lang.Object
org.astonbitecode.j4rs.api.invocation.JsonInvocationImpl<T>
All Implemented Interfaces:
Instance<T>, JsonValue, ObjectValue

public class JsonInvocationImpl<T> extends Object implements Instance<T>
  • Constructor Details

    • JsonInvocationImpl

      public JsonInvocationImpl(Class<T> clazz)
    • JsonInvocationImpl

      public JsonInvocationImpl(T instance, Class<T> clazz)
    • JsonInvocationImpl

      public JsonInvocationImpl(T instance, Class<T> clazz, List<Type> classGenTypes)
  • Method Details

    • invoke

      public Instance invoke(String methodName, InvocationArg... args)
      Description copied from interface: Instance
      Invokes a method of the instance of the class that is set for this Instance
      Specified by:
      invoke in interface Instance<T>
      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

      public Instance invokeStatic(String methodName, InvocationArg... args)
      Description copied from interface: Instance
      Invokes a static method of the class that is set for this Instance
      Specified by:
      invokeStatic in interface Instance<T>
      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

      public void invokeAsyncToChannel(long channelAddress, String methodName, InvocationArg... args)
      Description copied from interface: Instance
      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.

      Specified by:
      invokeAsyncToChannel in interface Instance<T>
      Parameters:
      channelAddress - 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

      public void invokeToChannel(long channelAddress, String methodName, InvocationArg... args)
      Description copied from interface: Instance
      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.
      Specified by:
      invokeToChannel in interface Instance<T>
      Parameters:
      channelAddress - The memory address of the channel
      methodName - The method name
      args - The arguments
    • initializeCallbackChannel

      public void initializeCallbackChannel(long channelAddress)
      Description copied from interface: Instance
      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.
      Specified by:
      initializeCallbackChannel in interface Instance<T>
      Parameters:
      channelAddress - The memory address of the channel
    • field

      public Instance field(String fieldName)
      Description copied from interface: Instance
      Retrieves the instance held under the Field fieldName
      Specified by:
      field in interface Instance<T>
      Parameters:
      fieldName - The name of the field to retrieve
      Returns:
      A Instance instance containing the defined field.
    • getObject

      public T getObject()
      Description copied from interface: ObjectValue
      Returns the Object
      Specified by:
      getObject in interface ObjectValue
      Returns:
      An object instance
    • getObjectClass

      public Class<T> getObjectClass()
      Description copied from interface: ObjectValue
      Returns the Class of the Object
      Specified by:
      getObjectClass in interface ObjectValue
      Returns:
      A Class
    • getObjectClassName

      public String getObjectClassName()
      Description copied from interface: ObjectValue
      Returns the name of the Object Class
      Specified by:
      getObjectClassName in interface ObjectValue
      Returns:
      A String representing the name of the Object Class
    • getJson

      public String getJson()
      Description copied from interface: JsonValue
      Returns the json representation
      Specified by:
      getJson in interface JsonValue
      Returns:
      The json representation