Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support isolated classloading for Java modules #98

Closed
gbrail opened this issue Dec 12, 2014 · 1 comment
Closed

Support isolated classloading for Java modules #98

gbrail opened this issue Dec 12, 2014 · 1 comment
Milestone

Comments

@gbrail
Copy link
Contributor

gbrail commented Dec 12, 2014

We will add a new, non-standard, NPM module called "trireme-support". This module will include a function called "loadJars" that allows the user to specify an array of file names of JAR files.
Internally, this module will use a native module (loaded via process.binding) called "trireme-native-support". This way, non-Trireme users can still import "trireme-support", which will support a way to tell if code is running on Trireme.

With this solution, instead of writing the Java module and putting it on the system classpath as they are doing now, the user can include the JAR file from Node.js code.

When "loadJar" is called, the following will happen:

  1. Trireme will create a new classloader. (Each invocation of "loadJars" will create a new classloader.) The classloader will not be shared with any other invocations of "loadJar" within the same Node.js application or with any other Node.js application on the same JVM.

  2. Trireme will inspect the argument to "loadJars". If it is a single string, then it will attempt to open the JAR file described by the string. If it is an array of strings, then it will open each and create a classloader that includes all the JAR files. An exception will be thrown if any file cannot be opened.

  3. While opening JAR files, Trireme will apply the same "Sandbox" policy that it applies to all other files.

  4. Once the classloader is created, Trireme will use the ServiceLoader pattern (java.util.ServiceLoader) to load Node.js modules implemented using the "NodeInterface" interface from Trireme. (This is the existing mechanism for extending Trireme with Java code and is already in use within Trireme and Edge.)

  5. After "loadJar" has completed, the modules will not be loaded, but they will be available in the Node.js namespace for loading. The user can now load them using "require" in the same manner they would load a Java module that was placed on the system classpath.

Once loaded, the jars do not run in any particular security manager (other than the system security manager).

@gbrail gbrail added this to the 0.8.5 milestone Dec 12, 2014
@gbrail
Copy link
Contributor Author

gbrail commented Dec 15, 2014

The enhancement is in, and can be best explained and used via the "trireme-support" module on NPM:

https://www.npmjs.com/package/trireme-support

@gbrail gbrail closed this as completed Dec 15, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant