Thursday, October 29, 2015

WSO2 Carbon Kernel 5.0.0-alpha: Introduction to the all new jar-to-OSGi-bundle converter tool

WSO2 Carbon-kernel 5.0.0-alpha has been released with all new features integrated into it. You will be able to gather an excellent insight into it from the release notesWSO2 Carbon documentation and you can check out the source code from this link.

But speaking of its all new features, I am intending to analyse one such new feature that has been introduced into the kernel, through this post. The new Java Archive (.jar) to OSGi-bundle converter, a functionality which had been part of the earlier Carbon-kernel versions as well, has been revamped and brought forward along with a fresh approach. 

A good introduction to this feature can be found in the documentation itself and I believe reading the docs will be really beneficial in order to understand its functionality, usage, imposed restrictions, reasons for the change in implementation and etc.

Since the above link I have provided covers the high level details about the tool, I intend to analyse its implementation within this post.

As mentioned in the article, this functionality was part of the org.wso2.carbon.server module of the previous Carbon-kernel versions. The following two Java classes primarily contained all implementation of the jar-to-bundle converter functionality.
When you observed these two classes, the following points would become evident to you:
  • The implementation is tightly coupled with the Carbon-kernel such that you cannot specify any desired source Java archive (.jar) file or directory containing such files and a destination directory for the generated OSGi bundles. 
  • No usage of the all new Java features such as NIO package, lambda expressions, streams and etc.
  • The execution of this functionality occurs at the server startup, which effectively increments the server startup time, further. 
Hence, we have decided to implement this as a separate module which is equivalent to an optional tool which the user can execute rather than executing it at the server startup, by default. Hence, we have introduced a fresh Maven module within the Carbon-kernel code base named tools. Plus this tool can be used to make jar-to-bundle conversion(s) between any two specified locations unlike in the previous case which only transacted between the CARBON_HOME/repository/components/lib and CARBON_HOME/repository/components/dropins directories. The usage instructions for this tool has been provided in the documentation

The new implementation is primarily composed of four classes which are as follows:
  • BundleGenerator.java - Contains the executor main method along with validations on file paths and file permissions, user arguments and etc.
  • BundleGeneratorUtils.java - Contains utility methods which are used during the conversion process.
  • Constants.java - Defines constants used within BundleGeneratorUtils.java class' utility methods.
  • JarToBundleConverterException.java - a custom exception class for the tool.
In-depth analysis of all classes and their methods can be found in the Java Doc comments.

Finally, it has to be mentioned that further improvements will take place in the future in relation with this tool. Any suggestions and ideas in relation with this tool are highly appreciated.  

No comments:

Post a Comment