NatJ¶
-
public class
NatJ
¶ The entry class of the NatJ library.
Methods¶
buildJavaObjectConstructionInfo¶
-
public static JavaObjectConstructionInfo
buildJavaObjectConstructionInfo
(NativeRuntime defaultRuntime, Class<?> type, Class<?> mapperClass, Annotation callback, Object typeInfo, boolean owned, boolean byvalue, boolean arg)¶ Constructs a
JavaObjectConstructionInfo
instance.The responsible runtime determined by the following simplified formula: runtime = (mapperClass != null ? getRuntime(mapperClass) : getRuntime(type)); runtime = runtime != null ? runtime : defaultRuntime;
Parameters: - defaultRuntime – Runtime used when the runtime can not be determined
- type – The type to convert
- mapperClass – Specifies the mapper class to use
- callback – Extra information for callbacks
- typeInfo – Type information for reference types
- owned – Specifies the ownership
- byvalue – Specifies whether it is for a by-value value
- arg – Specifies whether it is for an argument
Returns: The constructed
JavaObjectConstructionInfo
instance
buildNativeObjectConstructionInfo¶
-
public static NativeObjectConstructionInfo
buildNativeObjectConstructionInfo
(NativeRuntime defaultRuntime, Class<?> type, Class<?> mapperClass, Annotation callback, boolean owned, boolean byvalue, boolean arg)¶ Constructs a
NativeObjectConstructionInfo
instance.Parameters: - defaultRuntime – Runtime used when the runtime can not be determined by the
type
- type – The type to convert
- mapperClass – Specifies the mapper class to use
- callback – Extra information for callbacks
- owned – Specifies the ownership
- byvalue – Specifies whether it is for a by-value value
- arg – Specifies whether it is for an argument
Returns: The constructed
NativeObjectConstructionInfo
instance- defaultRuntime – Runtime used when the runtime can not be determined by the
disposeFunctionPtr¶
getAndRemoveObjectCacheForRuntime¶
-
public static Object
getAndRemoveObjectCacheForRuntime
(Class<? extends NativeRuntime> runtimeClass, Object instance)¶ Returns and deletes cache for
runtime
of theinstance
.Parameters: - runtimeClass – The runtime we want to get and delete cache for
- instance – The instance we want to get and delete cache of
Returns: The cache
getMethod¶
-
public static Method
getMethod
(Class<?> cls, String name, java.lang.Class<?>[] argTypes, int[] idxRef, int[] countRef)¶ Lookups a method in a class by its given name and argument types, and computes the method’s index and the method count.
Parameters: - cls – The class in we want to do the lookup
- name – The method name to lookup
- argTypes – The method argument types
- idxRef – Out argument to return the computed index
- countRef – Out argument to return the method count
Returns: The method
getMethodIndex¶
getObjectCacheForRuntime¶
-
public static Object
getObjectCacheForRuntime
(Class<? extends NativeRuntime> runtimeClass, Object instance)¶ Returns cache for the given instance.
If a cache found for the
runtime
, then it will return it, otherwise null will be returned.Parameters: - runtimeClass – For which runtime we want to get the cache
- instance – Of which object we want to get the cache
Returns: The cache, nil if creation was not possible
getOrCreateInstanceOfRuntimeClass¶
-
public static NativeRuntime
getOrCreateInstanceOfRuntimeClass
(Class<? extends NativeRuntime> runtimeClass)¶ Returns an instance for a runtime class with using a cache.
Parameters: - runtimeClass – The runtime class we want to get instance for.
Returns: The instance of the runtime class.
getOrCreateObjectCacheForRuntime¶
-
public static Object
getOrCreateObjectCacheForRuntime
(Class<? extends NativeRuntime> runtimeClass, Object instance, CacheConstructor constructor)¶ Optionally creates a cache for a given instance then returns it.
If the
instance
has a__natjCache
field and it’s not initialized, then it will save a hash map in it to be able to store cache for every runtime. If a cache found for theruntime
, then it will return it, otherwise, it will create one by the givenconstructor
and store it in the cache for theruntimeClass
and return it. If there are no__natjCache
fields to use, then this will returnnull
to tell the caller there are no caching capabilities of theinstance
.Parameters: - runtimeClass – For which runtime we want to get the cache
- instance – Of which object we want to get the cache
- constructor – Cache factory implementation
Returns: The cache, nil if creation was not possible
getPlatformName¶
getReferenceMapper¶
isBoxedPrimitiveType¶
loadFramework¶
lookUpLibrary¶
-
protected static String
lookUpLibrary
(String name, boolean load)¶ Looks up a library by its name in the file system.
Uses
resolvedLibraries
for caching to avoid looking up the same library for multiple times.Parameters: - name – The library name we want to resolve a path for
- load – If this is true and the lookup resulted in a success, then it will load the library
Returns: The resolved path of the library
register¶
-
public static void
register
()¶ Registers a class with its determined runtime.
- Usable from static initializers: class MyClass {
- static {
- NatJ.register();
} // …
}
At first use it initializes NatJ. Loads the library specified by a
Library
annotation, if found any. Determines the responsible runtime withgetRuntime(Class,boolean)
and uses it for registering the class.
registerRuntime¶
-
public static void
registerRuntime
(Class<? extends NativeRuntime> runtimeClass)¶ Registers a runtime.
Parameters: - runtimeClass – The runtime we want to register.
toJava¶
-
public static Object
toJava
(long peer, JavaObjectConstructionInfo info)¶ Forwards to
info.mapper
.Parameters: - peer – The native pointer pointing to the object we want to convert.
- info – The conversion info.
Returns: The Java peer.
toNative¶
-
public static long
toNative
(Object instance, NativeObjectConstructionInfo info)¶ Forwards to
info.mapper
.Parameters: - instance – The Java object we want to convert.
- info – The conversion info.
Returns: The native pointer pointing to the native peer.