|
SYS-CON Magazines
|
Top Linux Links You Must Click On
Feature A JNI-Bridged Java Desktop Application
Native Performance and Java Control - Bridging Domain Gaps
By: Mario de Sa Vera
Aug. 1, 2006 06:15 PM
I'm going to share my experience of enabling a graphics-oriented GIS visualization module with a C++ rendering engine for a Java desktop application using JNI technology.
The solution gave the Java desktop application visualization module a native equivalent performance and saved a lot of duplicative effort in natively implemented rendering functionalities that could be accessed by the Java application layer. It also promoted full integration between the GIS visualization module and the application control peer. First I'll present the architecture and then discuss how JNI can be a great solution for a well-designed native layers integration. I'll also present, throughout the text, some third-party solutions currently available, giving references and links for more information on this still challenging matter.
The Architecture
Some Relevant Implementation Details The Java control layer simply delegates the UI events over to the native layer, which in turn does the response callbacks to the Java Bridge through a jobject proxy. See Listing 1. We ended up with JVIPE (Java VIPE) having equivalent performance to the C++ version saving development duplication related to rendering the Maps and Cartographic elements - to mention a few. What we do now is implement first in C++ and bridge it to Java. The single data cache was also a major achievement because it wasn't possible with the previous solution using CORBA. We basically succeeded on performance and memory allocation too. The client application inherited JVIPE functionalities through the Tdk Java API and is currently in production. The drawback is still the unavoidable conversion of the geometry native data types to Java for plotting. I'm currently checking JDK1.4 NIO features for the vector data blocks' native access to the raster data types whose conversion is also very costly.
JNI Analysis
Native Code Access from Java Analysis The answer isn't as obvious as you may think. Code reuse is a questionable issue. Moving to a modern programming language will usually be a worthy move it because new language efforts usually gather technological improvements together and get rid of past mistakes. Experience says that old libraries will eventually be migrated to modern languages to be continued and improved. So the question becomes, what kind of native code should we directly access against a rewrite approach? That question is a little simpler to answer. To answer it I'll risk generalizing two answers taken from a design decision:
Now that we have some idea of when to bring a tower of Babel to our code, let's analyze some technologies.
The JNI Choice JNI is a standard Java API. By definition Java demands native resources access. Different technologies could replace JNI however. I've seen some sites analyzing CORBA pros and cons against JNI, and COM has been a choice for Microsoft solution providers. But it's best to analyze the situation you're trying to apply the technology to and then decide if it makes sense. The first candidate to bridge the two worlds was CORBA since its IDL-based specifications provide language independence and we could take advantage of the client/server technology to create a distributed version of the application. After a couple of weeks of implementing a CORBA middle layer we ended up rewriting the caching model multiple times and wound up with very poor performance and a duplicated cache (the data was loaded first into the native layer and then into the Java visualization layer). All these problems basically stemmed from the separate processes scenario that CORBA - and any other inter-process (IPC) technology - brings in. That recommended JNI as the middle layer.
JNI Considerations JNI, as an API, offers flexibility but requires some education to use though it's not too steep of a learning curve. There are some products and tools that can be used to help make the JNI experience simpler. One major effort is Noodle Glue - also a Bridge pattern-oriented solution that works as a bridger to the native class to automatically generate a Java wrapper. It's sophisticated and robust, and was being open sourced when last seen. The other is JNIWrapper, the apparent proprietary market leader so far, which follows more of an Adapter pattern model in that it tries to adapt some native types so you can access native resources through direct method calls. Reader Feedback: Page 1 of 1
Subscribe to our RSS feeds now and receive the next article instantly!
Subscribe to the World's Most Powerful Newsletters
|
||||||||||||||||||||