Class JsiiEngine

java.lang.Object
software.amazon.jsii.JsiiEngine
All Implemented Interfaces:
JsiiCallbackHandler

@Internal public final class JsiiEngine extends Object implements JsiiCallbackHandler
The javascript engine which supports jsii objects.
  • Method Details

    • getInstance

      public static JsiiEngine getInstance()
      Returns:
      The singleton instance.
    • setQuietMode

      public static void setQuietMode(boolean value)
      Silences any error and warning logging from the Engine. Useful when testing.
      Parameters:
      value - whether to silence the logs or not.
    • getClient

      public JsiiClient getClient()
      Returns:
      The jsii-server HTTP client.
    • loadModule

      public void loadModule(Class<? extends JsiiModule> moduleClass)
      Loads a JavaScript module into the remote jsii-server. No-op if the module is already loaded.
      Parameters:
      moduleClass - The jsii module class.
    • nativeFromObjRef

      public Object nativeFromObjRef(JsiiObjectRef objRef)
      Returns the native java object for a given jsii object reference. If it already exists in our native objects cache, we return it. If we can't find the object in the cache, it means it was created in javascript-land, so we need to create a native wrapper with the correct type and add it to cache.
      Parameters:
      objRef - The object reference.
      Returns:
      The jsii object the represents this remote object.
    • nativeToObjRef

      public JsiiObjectRef nativeToObjRef(Object nativeObject)
      Returns the jsii object reference given a native object. If the object does not have one yet, a new object reference is requested from the jsii kernel, and gets assigned to the instance before being returned.
      Parameters:
      nativeObject - The native object to obtain the reference for
      Returns:
      A jsii object reference
    • getObject

      public Object getObject(JsiiObjectRef objRef)
      Gets an object by reference. Throws if the object cannot be found.
      Parameters:
      objRef - The object reference
      Returns:
      a JsiiObject
      Throws:
      JsiiError - If the object is not found.
    • getObject

      public Object getObject(com.fasterxml.jackson.databind.JsonNode objRefNode)
      Given an obj ref, returns a Java object that represents it. A new object proxy object will be allocated if needed.
      Parameters:
      objRefNode - The objref
      Returns:
      A Java object
    • findEnumValue

      public Enum<?> findEnumValue(String enumRef)
      Given a jsii enum ref in the form "fqn/member" returns the Java enum value for it.
      Parameters:
      enumRef - The jsii enum ref.
      Returns:
      The java enum value.
    • processAllPendingCallbacks

      public void processAllPendingCallbacks()
      Dequeues and processes pending jsii callbacks until there are no more callbacks to process.
    • handleCallback

      public com.fasterxml.jackson.databind.JsonNode handleCallback(Callback callback)
      Invokes a local callback and returns the result/error.
      Specified by:
      handleCallback in interface JsiiCallbackHandler
      Parameters:
      callback - The callback to invoke.
      Returns:
      The return value
      Throws:
      JsiiError - if the callback failed.
    • createNewObject

      public JsiiObjectRef createNewObject(Object uninitializedNativeObject, Object... args)
      Given an uninitialized native object instance, reads the @Jsii annotations to determine the jsii module and FQN, and creates a JS object. Any methods implemented on the native object are passed in as "overrides", which are overridden in the javascript side to call-back to the native method.
      Parameters:
      uninitializedNativeObject - An uninitialized native object
      args - Initializer arguments
      Returns:
      An object reference for the new object.