| By Vikram Roopchand | Article Rating: |
|
| December 28, 2006 05:00 PM EST | Reads: |
26,690 |
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 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.
Published December 28, 2006 Reads 26,690
Copyright © 2006 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
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.
![]() |
Peter 01/11/07 07:17:29 PM EST | |||
Fantastic article! I wish I had this library back in 99! |
||||
- Kindle 2 vs Nook
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- Confessions of a Ulitzer Addict
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- It's the Java vs. C++ Shootout Revisited!
- Cloud Computing Can Revitalize Your Career as Software Developer
- IBM Could "Reinvent" Java: Mills
- Oracle & Cloud Computing: Exclusive Q&A with SVP Richard Sarwal
- A Brief History of Cloud Computing
- Kindle 2 vs Nook
- Cloud CEOs, CTOs & SVPs to Speak at 4th International Cloud Computing Expo
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- The Difference Between Web Hosting and Cloud Computing
- Cloud Computing Expo: Exclusive Q&A with Yahoo! SVP Cloud Computing
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- A Cup of AJAX? Nay, Just Regular Java Please
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- The i-Technology Right Stuff
- JavaServer Faces (JSF) vs Struts
- Rich Internet Applications with Adobe Flex 2 and Java
- Java vs C++ "Shootout" Revisited
- Bean-Managed Persistence Using a Proxy List
- Reporting Made Easy with JasperReports and Hibernate
- Creating a Pet Store Application with JavaServer Faces, Spring, and Hibernate
- What's New in Eclipse?
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- i-Technology Predictions for 2007: Where's It All Headed?









































