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

workspace master and agent : avoid scan of classes at runtime in order to find DynaModules #6922

Merged
merged 5 commits into from
Nov 1, 2017

Conversation

mkuznyetsov
Copy link
Contributor

@mkuznyetsov mkuznyetsov commented Oct 23, 2017

What does this PR do?

Today, ws-che-master and ws-che-agent are deployed using war files. In order to have extensibility, we can apply a @DynaModule annotation on guice class modules. Then, at runtime, Servlet container(Tomcat) is scanning the jar files to find the @DynaModuleclasses and then call the org.eclipse.che.inject.ModuleScanner class by calling onStartupmethod

When Che is initialized, it calls CheBootStrapclass that ask the modules found by the scanner by calling modules.addAll(ModuleScanner.findModules());

The issue is that we've a lot of scanning operations (performed by SCI (ServletContainerInitializer) .
Following https://wiki.apache.org/tomcat/HowTo/FasterStartUp if we disable all JAR scanning operations we lost the ability to use DynaModulewhich is not good.

The idea is then to still disable scanning at runtime but keep using DynaModule.
By writing a plugin that could scan all @DynaModule when generating the war file, we could avoid the scan at runtime and then keep the ability to use `@DynaModule``

This PR introduces this plugin and the use of this plugin inside ws-master and ws-agent.
On the agent, we should also add <absolute-ordering />element but it will break archetypes/custom assemblies.

How is it working ?

The DynaModule plugin scan all the classes (there is a way to skip some jars that we're sure doesn't contain any @DynaModule annotations) and generate a class that provides a getModules() method returning all DynaModule modules.
This class is then loaded at runtime and CheBootstrap can load these modules, avoiding the use of scanning classes at runtime.

Details

  • Plugin uses ASM visitor to scan classes avoiding the need to instantiate classes (if some dependencies are available only at runtime)
  • Plugin generates a META-INF/services/org.eclipse.che.inject.ModuleFinder file contaning the generated class.
  • Plugin generates the class implementing the ModuleFinder interface (getModules() method) at process-classes lifecycle (based on maven lifecycle : process-classes | post-process the generated files from compilation, for example to do bytecode enhancement on Java classes)
  • ModuleScanner class also ask ServiceLoader SPI to get modules through ModuleFinder implementations.

then CheBootStrap is able to find all DynaModule modules.

the flow being:
CheBootStrap --> ModuleScanner.getModules() --> ServiceLoader --> GeneratedClass.getModules()

What issues does this PR fix or reference?

#6169

Changelog

workspace master and agent : avoid scan of classes at runtime in order to find DynaModules

Release Notes

N/A

Docs PR

N/A

@mkuznyetsov mkuznyetsov added status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. target/che6 labels Oct 23, 2017
@mkuznyetsov mkuznyetsov requested a review from benoitf October 23, 2017 14:04
@benoitf benoitf added the kind/enhancement A feature request - must adhere to the feature request template. label Oct 23, 2017
@benoitf
Copy link
Contributor

benoitf commented Oct 24, 2017

FYI there is a merge conflict

@skabashnyuk skabashnyuk added this to the 6.0.0-M1 milestone Oct 25, 2017
@mkuznyetsov mkuznyetsov merged commit 5a58402 into che6 Nov 1, 2017
@benoitf benoitf removed the status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. label Nov 2, 2017
@mkuznyetsov mkuznyetsov deleted the avoid-jar-scan-che6 branch November 17, 2017 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement A feature request - must adhere to the feature request template.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants