Grinding Java |
IntroductionWhen I first started writing for EDM I wrote to promote the usage of Java. I am a big Java advocate (DAH), and back then I felt that many people did not learn Java simply because there were very little "hands on" real world Java examples out there. Today the situation is quite different, JavaSoft's documentation is superb and even their tutorial started dealing with the new stuff (as in Swing) before I got to it. So where do I fit in? JavaWorld, JavaUniverse and JavaSoft supply pretty much all that is needed in examples and documentation. PC Week, Wired and others supply way too many opinion columns which simply seek sensation rather than journalism. I decided to change the theme of the articles, I will stop posting the large amount of code and write about the development itself. I am currently working on several Java based projects, I believe they are quite interesting and I will (staring next month) write about the development of these projects from the angle of the lessons learned. I will also keep studying upcoming Java APIs and post overviews of their performance and resources for those APIs. You will already notice the light amount of code I produced this month, this is due to my lack of time since I have been spending most of my time working on other Java projects. Shai. A quick introduction to distributed computingYou may be wondering what took me so long in writing an article on distributed computing. It is my second favorite subject. I have been waiting for Sun to support Corba in RMI, and now that it has it is time to start supporting RMI against the common foe, DCOM. What are distributed objects? You probably know of RPC (remote procedure call) which allows a process call a procedure which may physically execute on another computer. Distributed objects invoke methods on objects which may exist on other computers. In what way are distributed objects better than RPC? In the same way in which OO programming languages are better than procedural languages. The mileage may vary with the type of distributed object technology (DCOM is quite similar to RPC). I found that the best way to explain distributed computing is by explaining the technologies which implement the concepts and their differences. Currently 3 major technologies are in the distributed computing battle ground: Corba "Common Object Request Broker Architecture" - (My favorite) Corba supports the creation of objects on the basis of interfaces written in a language called IDL (Interface Definition Language). A Corba object can be written in any language (object oriented or not) and it will expose an object oriented interface. We can write an object in Java that will make use of legacy code written in C++, SmallTalk, C or even Cobol. A Corba object supports multiple inheritance so our Java code can inherit code from every the supported language. Corba has 16 defined services which allow Corba programmers to add functionality to their objects using inheritance and standard interfaces. RMI "Remote Method Invocation" - RMI is very similar to Corba in some aspects. In fact RMI can be considered as a Corba ORB. RMI allows a Java VM to invoke a method on another Java VM and it supplies a registry mechanism and a simple to use interface. RMI also supports passing objects by value using the serialization mechanism. ActiveX - The Microsoft "standard" relies on an architecture quite similar to C++ vtables. ActiveX redefines the meaning of the word object to not include instances. In order to understand fully the issues at hand I will compare each of the important aspects of the technologies. HistoryCorba: In the May 1989 a group called OMG (Object Management Group) was formed by 8 companies (Sun, 3Com, American Airlines, Canon, Data General, HP, Philips and Unisys) whose goal was to create a standard upon which object technology can blossom. Today OMG has more than 700 members (which is quite a lot considering the fact that each member is usually a billion dollar corporation) and it has completed the first two phases of its standard and is well into the third phase. OMG's technologies are standard and open to every one, OMG membership which is required for a vote on the standard is quite expensive but the resulting standards are free. There exist more than 12 implementations of ORB for almost any platform and several Java ORBs (Object Request Brokers; I know of 5). All Corba 2.0 compliant ORBs can interact with one another seamlessly. RMI: In JDK 1.1 JavaSoft introduced RMI which is quite odd since they also introduced JOE which is a Corba ORB, and thus supplies very similar functionality to RMI. RMI was widely criticised by the Corba community since it did not comply to the Corba standard. Recently Sun announced that RMI will be implemented on top of IIOP (Internet Inter-Orb Protocol) which is the Corba standard for ORB interaction. That announcement means that now RMI is Corba compliant and RMI programs will work with Corba programs as if the objects are one and the same. ActiveX: Began its life as DCOM and network OLE. OLE1 was useless when Windows 3 first came out. One of the biggest reasons was its reliance on DDE as the underlying mechanism. Microsoft decided to construct a new mechanism which it called LRPC (Lightweight RPC) to allow the functionality of COM to sit upon it. OLE2 was then constructed upon COM. Although COM existed as a product for years, DCOM had a delayed release since MS at the time did not consider the market ready. DCOM is based on a language very similar to Corba's IDL, ODL (Object Definition Language) since they are both derived from DCE. ConceptsCorba: When programming in Corba you must map your legacy code to IDL interfaces which will look very familiar to you C++ programmers out there. An IDL interface is something very similar to a class declaration in C++ or an interface in Java. Corba treats all objects as references, if an object is passed to another computer through a function call it will not be the actual object but a reference to the remote object. This sounds to many first time Corba programmers as a fault, but it is not. Since Corba supports all platforms binary code from one computer platform should not be transmitted to another, transmitting binary objects over a net can forms a nesting ground for security problems. The interface contains information of the methods that can be invoked, the classes that are inherited and the services that are supported. Corba then defines 16 services which allow the programmer to offer truly "smart objects" which will act independently. Those services are: Life Cycle - Everything that has to do with the objects life. Moving, deleting, copying, etc. Persistence - A Corba object never dies. If the object you requested is not running it will be invisibly loaded from the persistent storage. The object persistence is invisible and supports both ODBMS's and RDBMS's.
Note: To get my bias out of the way, I believe ActiveX is the root of all evil mostly because the information I write here about ActiveX is true. I am biased but ActiveX is a still horrible product. ActiveX: DCOM was based on COM which was based on an idea derived from C++: the vtables. In C++, every class which contains a virtual function (a function that may be overridden by a subclass) has a vtable which has an entry for every virtual function in the class. The vtable contains pointers to the functions in the correct subclass so when a method is invoked the vtable will send the call to the correct method. ActiveX does not support inheritance, it only supports interfaces. The most important interface in ActiveX is IUnknown which has methods to discover the other interfaces supported by the COM object. EVERY ActiveX component must implement IUnknown, this is usually invisible to the programmer which simply uses Visual C++ to automatically generate the code, but the object will be bloated anyway. COM objects will always be very large since they are always derived from large class library. COM does not support instances at the object level. A COM object has a unique ID for the vtable implementation, yet it has no id for the object itself. Unique objects in COM are usually achieved by mapping references to the object directly to the C++ object instance. COM's speed potential is quite good since it has a simple (thus fast) vtable, yet many Corba implementations are reported to be faster. COM has no services but it does declare many interfaces, OLE 2 is in fact a set of COM interfaces for application interaction. ActiveX supports passing by value which means:
SupportersCorba: all of the founding members, and IBM - SOM is IBM's implementation of Corba. IBM is writing a new Corba implementation which will support all the 16 services titled Component Broker, it will be on top of SOM 4. IBM is an active member of OMG who contributed to such services as persistence, transaction, etc. Oracle - Oracle's is writing an ORB which they intend to use to migrate their current database users to object technology. Corba's persistence services allow them to use a relational database while using true OO programming. Netscape - Navigator 4 supports IIOP and is in fact bundled with Visigenic ORB for Java. Netscape is very committed to Corba and their new visual JavaScript tool supports Corba. Netscape server software is bundled with Visigenic ORB too. Corba success stories may be found at http://www.corba.org/csstory.htm OMG is at http://www.omg.org/ RMI: RMI is rapidly growing and will probably reach a larger audience now that Corba is no longer an enemy. RMI's biggest supporter is JavaSoft, I haven't heard of any large organizations embracing RMI. The biggest commitment I have seen for RMI is in IBM's San Francisco frameworks which will use RMI. ActiveX: ActiveX is supported by Microsoft who created the "open group" whose purpose is to turn ActiveX into an open standard (good luck); they are at http://www.activex.org/. The ActiveX supporters divide among 2 groups, those with a heavy windows stake, and those who go both ways (ActiveX and Corba). The first group: Adobe Systems, Computer Associates International, Microsoft Corporation, Visio. The other group: DEC and Hewlett Packard have Corba ORB's too and Powersoft has Corba development tools. CompatibilityCorba: can be used in any programming language which has appropriate bindings. Corba was designed to be language independent, i.e. Corba supports multiple inheritance which is not supported by Java yet you can still use multiple inheritance in Corba-Java objects, Corba even works with C which is not even object oriented. Corba has standard bindings to allow it to interact with ActiveX components, that way Corba objects may be manipulated from visual development environments which support only ActiveX (such as Delphi and VB). RMI: RMI can only run on top of Java (which is also its strongest advantage of simplicity). If RMI's IIOP protocol is implemented well, RMI will be able to connect to Corba ORBs and through them to ActiveX components. ActiveX: Was designed in C++ and has strong bounds to that language. ActiveX components can potentially be written in other languages (notably Java and VB) but they don't blend well into the language. As a side note: an ActiveX component written in Java will still not be portable or small. ActiveX may interact with a Corba ORB if that ORB supports that interaction, Microsoft refuses to support IIOP. SummaryCorba is a very strong solution even if your project uses only Java Corba should not be ignored as a solution, yet RMI may be a simple straight forward shortcut and could possibly scale to much larger projects. I feel ActiveX is the devil incarnate, hopefully you will feel the same once you study the facts about that technology. I am attaching an example of a very simple RMI program, I wanted to present a Corba example too but I don't have time to get into the Java Corba bindings. |