Skip to content

Commit

Permalink
Merge pull request #1716 from arunans23/graaljs
Browse files Browse the repository at this point in the history
Integrate graaljs for datamapper engine
  • Loading branch information
arunans23 authored Jun 14, 2024
2 parents 6f873ca + dc4bcc3 commit cf124b9
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,34 @@
<groupId>org.openjdk.nashorn</groupId>
<artifactId>nashorn-core</artifactId>
</dependency>
<!-- GraalVM related dependencies-->
<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
</dependency>
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js</artifactId>
</dependency>
<dependency>
<groupId>org.graalvm.truffle</groupId>
<artifactId>truffle-api</artifactId>
</dependency>
<dependency>
<groupId>org.graalvm.regex</groupId>
<artifactId>regex</artifactId>
</dependency>
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
</dependency>
<dependency>
<groupId>org.apache.bsf.wso2</groupId>
<artifactId>bsf-all</artifactId>
</dependency>
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js-scriptengine</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.wso2.carbon.mediator.datamapper.engine.core.models.Model;
import org.wso2.carbon.mediator.datamapper.engine.core.models.StringModel;
import org.wso2.carbon.mediator.datamapper.engine.output.formatters.MapOutputFormatter;
import org.wso2.carbon.mediator.datamapper.engine.utils.DataMapperEngineConstants;
import org.wso2.carbon.mediator.datamapper.engine.utils.DataMapperEngineUtils;
import org.wso2.carbon.mediator.datamapper.engine.utils.OpenJDKNashornFactoryWrapper;

Expand Down Expand Up @@ -88,6 +89,20 @@ public ScriptExecutor(ScriptExecutorType scriptExecutorType) {
log.debug("Setting Nashorn as Script Engine");
break;
}
case GRAALJS:
try {
scriptEngine = new ScriptEngineManager().getEngineByName(DataMapperEngineConstants.GRAALJS_ENGINE_NAME);
bindings = scriptEngine.createBindings();
log.debug("Setting Graal.js as Script Engine");
} catch (Exception e) {
log.warn("Could not find Graal.js jar in the lib, switching to rhino js. This may cause performance issue ");
log.debug(e);
scriptEngineManager.registerEngineName(DEFAULT_ENGINE_NAME, new RhinoScriptEngineFactory());
scriptEngine = scriptEngineManager.getEngineByName(DEFAULT_ENGINE_NAME);
bindings = scriptEngine.createBindings();
log.debug("Setting Rhino as Script Engine");
}
break;
case RHINO:
scriptEngineManager.registerEngineName(DEFAULT_ENGINE_NAME, new RhinoScriptEngineFactory());
scriptEngine = scriptEngineManager.getEngineByName(DEFAULT_ENGINE_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public class ScriptExecutorFactory {

private static ScriptExecutorPool executorPool = null;
private static ScriptExecutorType scriptExecutorType = ScriptExecutorType.NASHORN;
private static ScriptExecutorType scriptExecutorType = ScriptExecutorType.GRAALJS;
private static final Log log = LogFactory.getLog(ScriptExecutorFactory.class);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
* This enum type represent the types of executors support in data mapper
*/
public enum ScriptExecutorType {
RHINO, NASHORN
RHINO, NASHORN, GRAALJS
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class DataMapperEngineConstants {
public static final String NULL_ELEMENT_TYPE = "null";
public static final String ARRAY_ELEMENT_FIRST_NAME = "0";
public static final String NASHORN_ENGINE_NAME = "nashorn";
public static final String GRAALJS_ENGINE_NAME = "graal.js";
public static final String DEFAULT_ENGINE_NAME = "js"; //rhino
public static final int DEFAULT_DATAMAPPER_ENGINE_POOL_SIZE = 20;
public static final String ORG_APACHE_SYNAPSE_DATAMAPPER_EXECUTOR_POOL_SIZE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,9 @@
<groupId>org.wso2.carbon.mediation</groupId>
<artifactId>org.wso2.carbon.mediator.datamapper.engine</artifactId>
</dependency>
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,6 @@ private ScriptEngine getScriptExecutor() {
if (javaVersion.startsWith("1.7") || javaVersion.startsWith("1.6")) {
return new ScriptEngineManager().getEngineByName(DataMapperEngineConstants.DEFAULT_ENGINE_NAME);
}
return new ScriptEngineManager().getEngineByName(DataMapperEngineConstants.NASHORN_ENGINE_NAME);
return new ScriptEngineManager().getEngineByName(DataMapperEngineConstants.GRAALJS_ENGINE_NAME);
}
}
32 changes: 32 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2473,6 +2473,36 @@
<artifactId>bsf-all</artifactId>
<version>${bsf.version}</version>
</dependency>
<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
<version>${graalvm.version}</version>
</dependency>
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js-scriptengine</artifactId>
<version>${graalvm.version}</version>
</dependency>
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js</artifactId>
<version>${graalvm.version}</version>
</dependency>
<dependency>
<groupId>org.graalvm.truffle</groupId>
<artifactId>truffle-api</artifactId>
<version>${graalvm.version}</version>
</dependency>
<dependency>
<groupId>org.graalvm.regex</groupId>
<artifactId>regex</artifactId>
<version>${graalvm.version}</version>
</dependency>
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<version>${icu.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.runtime.diagnostics</groupId>
<artifactId>runtime-diagnostics-tool</artifactId>
Expand Down Expand Up @@ -2671,6 +2701,8 @@
<!-- OAS3 Versions -->
<swagger.parser.orbit.version>2.1.18.wso2v1</swagger.parser.orbit.version>
<transport.http.netty>6.3.50</transport.http.netty>
<graalvm.version>23.0.4</graalvm.version>
<icu.version>72.1</icu.version>
<runtime.diagnostics.version>1.1.0</runtime.diagnostics.version>
</properties>
<pluginRepositories>
Expand Down

0 comments on commit cf124b9

Please sign in to comment.