Qorus Integration Engine®
4.0.3.p2_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.
The main Qorus Java APIs are:
Java code is defined in class objects, and classpath entries for each object can be specified using the classpath
class object tag; see Class Definition File and 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
Source files should have the same naming convention as other Qorus objects, however the following additions to the standard Qorus naming convention can help properly-configured editors to perform source highlighting for Qorus Java sources properly as in the following table.
Object | Pattern | Example |
Qorus classes | name-v version.qclass.java | MyJavaClass-v1.0.qclass.java |
Qorus services | name-v version.qsd.java | MyJavaService-v1.0.qsd.java |
Qorus jobs | name-v version.qjob.java | MyJavaJob-v1.0.qjob.java |
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 as in the following example.
classpath
tag can also be set in Java jobs and services as wellQorus workflows can be defined in Java by implementing a class-based step and subclassing one of the following step classes for the step:
In order to compile byte code for Qorus workflows, the following jar files need to be in the classpath at a minimum:
$OMQ_DIR/jar/qore-jni.jar
: provides the low-level API connecting Qore and Java$OMQ_DIR/jar/qorus-common.jar
: the base Qorus API common to all interfaces$OMQ_DIR/jar/qorus-workflow.jar
: the Qorus workflow APIex:
javac -cp $OMQ_DIR/jar/qore-jni.jar:$OMQ_DIR/jar/qorus-common.jar:$OMQ_DIR/jar/qorus-workflow.jar MyClass.java
Qorus services can be defined in Java by implementing a class-based service and subclassing the QorusService class and providing metadata for service methods using annotations as in the following example (note the use of the classpath
tag to provide the classpath for services).
In order to compile byte code for Qorus services, the following jar files need to be in the classpath at a minimum:
$OMQ_DIR/jar/qore-jni.jar
: provides the low-level API connecting Qore and Java$OMQ_DIR/jar/qorus-common.jar
: the base Qorus API common to all interfaces$OMQ_DIR/jar/qorus-service.jar
: the Qorus service APIex:
javac -cp $OMQ_DIR/jar/qore-jni.jar:$OMQ_DIR/jar/qorus-common.jar:$OMQ_DIR/jar/qorus-service.jar MyClass.java
Qorus jobs can be defined in Java by implementing a class-based job and subclassing the QorusJob class as in the following example (note the use of the classpath
tag to provide the classpath for jobs).
In order to compile byte code for Qorus jobs, the following jar files need to be in the classpath at a minimum:
$OMQ_DIR/jar/qore-jni.jar
: provides the low-level API connecting Qore and Java$OMQ_DIR/jar/qorus-common.jar
: the base Qorus API common to all interfaces$OMQ_DIR/jar/qorus-job.jar
: the Qorus job APIex:
javac -cp $OMQ_DIR/jar/qore-jni.jar:$OMQ_DIR/jar/qorus-common.jar:$OMQ_DIR/jar/qorus-job.jar MyClass.java
Java 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 QoreObject class, normally by wrapping the object 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:. MyTest
The 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:. MyQorusClient
See 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.