Welcome!

Java IoT Authors: Liz McMillan, Elizabeth White, Pat Romanski, William Schmarzo, Stackify Blog

Related Topics: Java IoT, Open Source Cloud

Java IoT: Article

j-Interop: An Open Source Library for COM Interoperability Without JNI

A search for pure, non-native, bi-directional interoperability with COM servers

Phew! I have drawn a picture to explain this entire cycle, just follow the alphabet.

I hope I was able to provide a concise introduction to the discovery and activation cycle. Let's see how the "QueryInterface" works and how the API call "Add (...)" is handled.

12.  The remote connection has now been established and we have an interface pointer to the remote IUnknown (the "IRemUnknown"). A QueryInterface () call to obtain the "ITestCOMServer"" interface will result in the following activities taking place.
13.  When the client invokes the IUnknown::QueryInterface, the COM runtime invokes the IRemUnknown::RemQueryInterface method on the OXID object in the target object exporter. The OXID object then invokes the QueryInterface() method on (possibly multiple) interfaces in the exporter (remember, the exporter knows all the interfaces the COM server has exported out). Please note that the IRemUnknown::RemQueryInterface method differs from the IUnknown::QueryInterface method since it can request several interface pointers in one call. The standard IUnknown::QueryInterface method is actually used to carry out this request on the server side.
14.  If found, the requested interface from the COM server is then marshaled as a MIP and sent back to the callee. This MIP carries a new IPID symbolizing this interface. The OXID and OID remain the same.
15.  Now that we have the interface pointer let's call "Add" on it. Upon receiving the ptrTestServer->Add(1, 2, int *) call, the COM runtime marshals the parameters in the NDR format and channels the request to the target object exporter identified by the OXID-resolved RPC binding (we did that in steps 9 and 10).
16.  The COM runtime on the server side finds the target interface based on the IPID that's contained in the RPC header. This IPID is of the ITestCOMServer interface that was returned to the client during a previous QueryInterface call.
17.  With the help of the Object exporter, the COM runtime invokes the method Add(...) on the correct interface of the COM server object and marshals the return values in the NDR format. These values are sent back to the callee using RPC infrastructure.
18.  The same cycle follows during the Release() call, the COM runtime invokes the IRemUnknown::RemRe lease() method on the OXID object in the target object exporter. The OXID object then invokes the Release() method on (possibly multiple) interfaces in the exporter.

This completes the entire cycle of obtaining an interface, executing an API on it, and subsequently releasing it. There's an additional task that the COM runtime also does and that's keeping the COM Server objects alive during a session. This is done via a ping mechanism. Pinging is carried out on a per-object (per-OID), not a per-interface (per-IPID) basis. Architecturally, at its server machine, each exported object (each exported OID) has associated with it a "ping period" that must elapse without getting a ping on that OID before all the remote references to IPIDs associated with that OID can be considered to have expired. Once expiration has occurred, the interfaces behind the IPIDs might get reclaimed (exactly when is implementation-specific).

I've tried to keep the explanation of DCOM internals as simple as possible. There's much more that happens, but I'm running out of space and I think you're running out of patience, so let's get to j-Interop. (Figure 4)

j-Interop
Suffice it to say j-Interop implements almost the entire DCOM protocol with its own Oxid Resolver service, pinging mechanism, Object exporter, etc. These are required for handling event callbacks, proxying a Java server in place of a COM server (bi-directional access), and making sure that the COM server isn't garbage collected while a client is connected to it and vice versa.

The library comes with pre-implemented packages for automation. This includes support for IDispatch, ITypeInfo, and ITypeLib. For more flexibility, it provides an API set to invoke operations directly on a COM server without going through automation. Another important feature is to allow full access and manipulation of the Windows Registry in a platform-independent manner.

The implementation has been tested on all advanced Windows and Fedora platforms and displays upward compatibility from JRE 1.3.1. For more technical specifications please visit http://j-interop.sourceforge.net.

I'll show you an implementation using j-Interop to call the ITestCOMServer from Java is Listing 1.

As you can see it's pretty straightforward. The ITestCOMServer supports the IDispatch interface. I've shown both ways of accessing the COM server, i.e., via the dispatch interface as well as via a direct call. From my experience, I'd suggest using the IDispatch interface, whenever it's available. It's much easier to program that way.

Figure 5 is normally how a Windows COM client communicates with its COM server. j-Interop does this as well and so for the COM server it's like an ordinary COM client. Whether the Java application is on Windows or Unix, it doesn't matter.

More examples and documentation can be downloaded from the SourceForge site mentioned previously.

The advantages offered by using a non-native library like j-Interop include:

  • Clean integration of two of the leading technologies without writing any native code: j-Interop eliminates any need to write native (JNI) DLLs, cutting development time, and shortening the entire software lifecycle for the products (based on j-Interop). Such products are also saved from any kind of instable functions that result from poorly written native code (DLLs).
  • Accessing COM components from any type of Java client, including applets, EJBs, servlets, JSPs, and standalone applications: Since it's pure Java, j-Interop can be used within any J2EE server and on any platform (that supports Java).
  • Maximizing reuse of existing Java and COM components: All the plumbing on interoperating with COM servers is done by j-Interop, it makes reusing same components again, instead of porting back and forth between domains, a more lucrative and viable option.
  • There should no longer be a dependency on cross-platform resources thus minimizing cost and im-proving quality: The same resources for Java can be used without any additional training/competency building and the turnaround time can be brought down substantially. Not having to deal with native code also removes the complexity associated with maintaining the same. The code is now much cleaner and distinctly segregated between the two domains. Debugging the projects based on j-Interop is substantially easier than debugging JNI-based DLL projects.
  • Easier deployment since there's no custom code at the server: No special treatment has to be given to j-Interop clients, they just behave like standard DCOM clients. This is a big advantage in terms of administering the machines where the COM servers are deployed. The administrator doesn't have to care about security or the instability of native components bringing the server down (Denial of Service).
DCE/RPC
DCE/RPC stands for Distributed Computing Environment/Remote Procedure Calls. It originated from Network Computing System (NCS) RPC developed by Apollo (which later got acquired by HP).DCE/RPC specifies a complete set of APIs and Models to abstract the usual nuances of an RPC system like a named lookup, subsequent handshake\binding, passing of call data between two parties , handling communication errors, security etc.. It provides protocol support for both Connectionless and Connection Oriented communication and has a wide transport base, UDP, TCP/IP, SMB, HTTP to name a few. It also has a generic security model supporting several authentication mechanisms such as DCE, Kerberos and GSSAPI.

The full specification can be obtained from www.theopengroup.com.

More Stories By Vikram Roopchand

Vikram Roopchand is a Technical Architect working for Infosys Technologies Ltd. (www.infosys.com). He has about 8.5 years of experience and specializes in Cross Platform development across Content Management and Business Intelligence domains.

Comments (1) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
Peter 01/11/07 07:17:29 PM EST

Fantastic article! I wish I had this library back in 99!

@ThingsExpo Stories
SYS-CON Events announced today that MIRAI Inc. will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. MIRAI Inc. are IT consultants from the public sector whose mission is to solve social issues by technology and innovation and to create a meaningful future for people.
SYS-CON Events announced today that Fusic will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Fusic Co. provides mocks as virtual IoT devices. You can customize mocks, and get any amount of data at any time in your test. For more information, visit https://fusic.co.jp/english/.
Smart cities have the potential to change our lives at so many levels for citizens: less pollution, reduced parking obstacles, better health, education and more energy savings. Real-time data streaming and the Internet of Things (IoT) possess the power to turn this vision into a reality. However, most organizations today are building their data infrastructure to focus solely on addressing immediate business needs vs. a platform capable of quickly adapting emerging technologies to address future ...
SYS-CON Events announced today that Taica will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Taica manufacturers Alpha-GEL brand silicone components and materials, which maintain outstanding performance over a wide temperature range -40C to +200C. For more information, visit http://www.taica.co.jp/english/.
Join IBM November 1 at 21st Cloud Expo at the Santa Clara Convention Center in Santa Clara, CA, and learn how IBM Watson can bring cognitive services and AI to intelligent, unmanned systems. Cognitive analysis impacts today’s systems with unparalleled ability that were previously available only to manned, back-end operations. Thanks to cloud processing, IBM Watson can bring cognitive services and AI to intelligent, unmanned systems. Imagine a robot vacuum that becomes your personal assistant th...
In his session at @ThingsExpo, Greg Gorman is the Director, IoT Developer Ecosystem, Watson IoT, will provide a short tutorial on Node-RED, a Node.js-based programming tool for wiring together hardware devices, APIs and online services in new and interesting ways. It provides a browser-based editor that makes it easy to wire together flows using a wide range of nodes in the palette that can be deployed to its runtime in a single-click. There is a large library of contributed nodes that help so...
SYS-CON Events announced today that Daiya Industry will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Daiya Industry specializes in orthotic support systems and assistive devices with pneumatic artificial muscles in order to contribute to an extended healthy life expectancy. For more information, please visit https://www.daiyak...
What is the best strategy for selecting the right offshore company for your business? In his session at 21st Cloud Expo, Alan Winters, U.S. Head of Business Development at MobiDev, will discuss the things to look for - positive and negative - in evaluating your options. He will also discuss how to maximize productivity with your offshore developers. Before you start your search, clearly understand your business needs and how that impacts software choices.
SYS-CON Events announced today that SIGMA Corporation will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. uLaser flow inspection device from the Japanese top share to Global Standard! Then, make the best use of data to flip to next page. For more information, visit http://www.sigma-k.co.jp/en/.
SYS-CON Events announced today that Yuasa System will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Yuasa System is introducing a multi-purpose endurance testing system for flexible displays, OLED devices, flexible substrates, flat cables, and films in smartphones, wearables, automobiles, and healthcare.
SYS-CON Events announced today that B2Cloud will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. B2Cloud specializes in IoT devices for preventive and predictive maintenance in any kind of equipment retrieving data like Energy consumption, working time, temperature, humidity, pressure, etc.
SYS-CON Events announced today that NetApp has been named “Bronze Sponsor” of SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. NetApp is the data authority for hybrid cloud. NetApp provides a full range of hybrid cloud data services that simplify management of applications and data across cloud and on-premises environments to accelerate digital transformation. Together with their partners, NetApp em...
SYS-CON Events announced today that Ryobi Systems will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Ryobi Systems Co., Ltd., as an information service company, specialized in business support for local governments and medical industry. We are challenging to achive the precision farming with AI. For more information, visit http:...
SYS-CON Events announced today that mruby Forum will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. mruby is the lightweight implementation of the Ruby language. We introduce mruby and the mruby IoT framework that enhances development productivity. For more information, visit http://forum.mruby.org/.
SYS-CON Events announced today that Mobile Create USA will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Mobile Create USA Inc. is an MVNO-based business model that uses portable communication devices and cellular-based infrastructure in the development, sales, operation and mobile communications systems incorporating GPS capabi...
SYS-CON Events announced today that Enroute Lab will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Enroute Lab is an industrial design, research and development company of unmanned robotic vehicle system. For more information, please visit http://elab.co.jp/.
Real IoT production deployments running at scale are collecting sensor data from hundreds / thousands / millions of devices. The goal is to take business-critical actions on the real-time data and find insights from stored datasets. In his session at @ThingsExpo, John Walicki, Watson IoT Developer Advocate at IBM Cloud, will provide a fast-paced developer journey that follows the IoT sensor data from generation, to edge gateway, to edge analytics, to encryption, to the IBM Bluemix cloud, to Wa...
SYS-CON Events announced today that Nihon Micron will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Nihon Micron Co., Ltd. strives for technological innovation to establish high-density, high-precision processing technology for providing printed circuit board and metal mount RFID tags used for communication devices. For more inf...
SYS-CON Events announced today that Suzuki Inc. will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Suzuki Inc. is a semiconductor-related business, including sales of consuming parts, parts repair, and maintenance for semiconductor manufacturing machines, etc. It is also a health care business providing experimental research for...
SYS-CON Events announced today that N3N will exhibit at SYS-CON's @ThingsExpo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. N3N’s solutions increase the effectiveness of operations and control centers, increase the value of IoT investments, and facilitate real-time operational decision making. N3N enables operations teams with a four dimensional digital “big board” that consolidates real-time live video feeds alongside IoT sensor data a...