![]() |
Qorus Integration Engine®
5.1.31_git
|
Qorus supports native Java development where code attributes of objects can be defined with code in Java in addition to Qore.
Java integration with Qore is implemented using the jni module, which provides tight integration with both languages, including dynamic imports into Java using bytecode generation of wrapper classes for deep language integration based on introspection / reflection of the inported language and runtime data conversions.
All Qore APIs are available in Java using dynamic imports using the special "qore" package.
The main Qorus APIs are:
qore.OMQ.UserApi.UserApi qore.OMQ.UserApi.Workflow.WorkflowApi qore.OMQ.UserApi.Service.ServiceApi qore.OMQ.UserApi.Job.JobApi Java code is defined in class objects, and classpath entries for each object can be specified using the classpath tag in a class object; see Java Classpath Handling in Qorus for more information and examples.
To use Java with Qore, a compatible JDK must be installed on the Qorus server machine; see Java Requirements
Generally, the Java classpath is set with the object tag classpath when defining Java code in Qorus. Furthermore, the recommended storage location for jar or class files is in $OMQ_DIR/user/jar.
The classpath tag accepts environment variables, and each element in the classpath should be separated by a colon (":"); see the following examples for more information.
In class definitions, the Java classpath is set with the tag classpath as in the following example:
classpath: $OMQ_DIR/user/jar/my-jar-1.jar:$OMQ_DIR/user/jar/my-jar-2.jar
Either oload or the QoreJavaCompiler must be used to compile Java source using dymamic imports to bytecode.
Both oload and QoreJavaCompiler require the Qore jni JAR file to be available as well:
$OMQ_DIR/jar/qore-jni.jar: provides the low-level API connecting Qore and JavaThe standard Java compiler cannot be used if your Qorus code uses dynamic API imports.
Qorus workflows can be defined in Java by implementing a step class by subclassing one of the following step classes for the step:
qore.OMQ.UserApi.Workflow.QorusAsyncStep qore.OMQ.UserApi.Workflow.QorusEventStep qore.OMQ.UserApi.Workflow.QorusNormalStep qore.OMQ.UserApi.Workflow.QorusSubworkflowStep qore.OMQ.UserApi.Workflow.QorusAsyncArrayStep qore.OMQ.UserApi.Workflow.QorusEventArrayStep qore.OMQ.UserApi.Workflow.QorusNormalArrayStep qore.OMQ.UserApi.Workflow.QorusSubworkflowArrayStep $OMQ_DIR/jar/qore-jni.jar: provides the low-level API connecting Qore and Java$OMQ_DIR/jar/qorus-common.jar: (deprecated) the base Qorus API common to all interfaces$OMQ_DIR/jar/qorus-workflow.jar: (deprecated) the Qorus workflow APIQorus services can be defined in Java by subclassing the QorusService class, available as qore.OMQ.UserApi.Service.QorusService in Java
$OMQ_DIR/jar/qore-jni.jar: provides the low-level API connecting Qore and Java$OMQ_DIR/jar/qorus-common.jar: (deprecated) the base Qorus API common to all interfaces$OMQ_DIR/jar/qorus-service.jar: (deprecated) the Qorus service APIService method annotations, meant to support the development of Qorus service code in JAR or class files without YAML metadata are deprecated, as the hardcoded JAR files are no longer necessary with the dynamic Java API support introduced in Qorus 5.1, and YAML-metadata-based services are the primary recommended and supported way to implement Qorus services.
When developing service classes or base classes to be delivered in binary format (jar or class files), Qorus service methods must be declared with the QoreMethod annotation as in the following example:
Qorus jobs can be defined in Java by implementing a job class and subclassing the QorusJob class (available as qore.OMQ.UserApi.Job.QorusJob in Java) as in the following example (note the use of the classpath tag to provide the classpath for jobs).
classpath: $OMQ_DIR/user/jar/my-jar-1.jar:$OMQ_DIR/user/jar/my-jar-2.jar
$OMQ_DIR/jar/qore-jni.jar: provides the low-level API connecting Qore and Java$OMQ_DIR/jar/qorus-common.jar: (deprecated) the base Qorus API common to all interfaces$OMQ_DIR/jar/qorus-job.jar: (deprecated) the Qorus job APIJava is not subject to sandboxing controls like Qore code, so it's easier to do dangerous things with Java.
All normal Java programming best practices should be followed when programming in Java; make sure all resources are freed in finally blocks and so forth; Qorus can only manage Qore resources, the Java JVM manages all Java resources normally.
Do not do any of the following:
System.exit(), Runtime.exit() or Runtime.halt() and similar)Java classes that wrap Qore classes manage a weak reference to the Qore object using the QoreObjectBase class (in manually-generated wrapper classes also with the QoreObjectWrapper class. Strong references to the Qore objects are always managed in Qorus, which means that when creating or acquiring a Qore object in Qorus with Java, the object will normally go out of scope after control returns to Qorus, meaning that the Qore destructor is then run, so that Qore's deterministic garbage collector can also be used in Java code.
For example, locks are released when DynamicDataHelper objects are collected after created from Java step code. The same applies to TempDataHelper or SensitiveDataHelper objects.
The following classes can help to write tests written in Java:
The Qorus test APIs are found in the qorus-test.jar file; ex:
# compile:
javac -cp ${OMQ_DIR}/jar/qorus-client.jar:${OMQ_DIR}/jar/qorus-test.jar:${OMQ_DIR}/jar/qore-jni.jar MyTest.java
# run:
java -Djava.library.path=$OMQ_DIR/lib/libqore.so -cp ${OMQ_DIR}/jar/qorus-client.jar:${OMQ_DIR}/jar/qorus-test.jar:${OMQ_DIR}/jar/qore-jni.jar:. MyTestThe Java Qorus client API can be found in the com.qoretechnologies.qorus.client package which is delivered in the qorus-client.jar file; ex:
# compile:
javac -cp ${OMQ_DIR}/jar/qorus-client.jar:${OMQ_DIR}/jar/qore-jni.jar MyQorusClient.java
# run:
java -Djava.library.path=$OMQ_DIR/lib/libqore.so -cp ${OMQ_DIR}/jar/qorus-client.jar:${OMQ_DIR}/jar/qore-jni.jar:. MyQorusClientSee the following section for runtime dependency information for the Qore library when using the Java Qorus client.
Java libraries for Qorus that depend on the native Qore library and the jni module to provide a wrapper for underlying Qore functionality such as the Java client or test APIs must be run with either the Java runtime option java.library.path or the QORE_LIBRARY environment variable set to the location of the native Qore library.