Welcome!

Java IoT Authors: Yeshim Deniz, Pat Romanski, Liz McMillan, Zakia Bouachraoui, Carmen Gonzalez

Related Topics: Java IoT

Java IoT: Article

CORBA vs Servlets: What to Use Where

CORBA vs Servlets: What to Use Where

Distributed object computing in Java has become increasingly popular as more complex products are written using a multi-tier architecture. A number of products and protocols are available for facilitating communication, and many developers have trouble deciding which ones to use in a given situation. Many of the communication methods work well together, and each has its strengths and weaknesses. In this article I'll discuss two of the most popular methods, CORBA and servlets. Both are useful for distributed computing, and they complement each other well.

What Is Distributed Object Computing?
Distributed object computing is development involving communication between two or more independent modules of an application. Usually, it involves communication between a client and a server - for example, a Java time-tracking application. This application would have a client side written as a Java applet and a server side that stores and retrieves information from a database. Users could enter the hours they spent on a specific project on the client side, and that information would be transferred to the server side and stored in the database. Likewise, if they wanted to retrieve previously stored hours, their request would be passed to the database and the information would then be passed back to the client side, generating a report dynamically.

This application is a good example of a multitier architecture. The client communicates with the server, and the server communicates with the database, creating three different layers to the application as well as a need for a communication protocol between each set. Since they have only the two modules, client/server applications are a special case of multitier applications. Communication between the server and the database can be done directly (using JDBC or a similar API), since the database is usually on the same intranet as the server module. However, the client and server modules not only could be on different intranets, they could also be separated by a firewall or another divider. Therefore, communication between them can be difficult. In order to communicate, the application must assemble information on one side, encapsulate it and send it to the other side, which must retrieve and decipher it. This is the problem distributed computing protocols and products are designed to solve.

What Is CORBA?
CORBA stands for Common Object Request Broker Architecture. The Object Management Group (OMG) is the body responsible for creating and maintaining the CORBA specifications. CORBA includes specifications for a language to define objects, a protocol for exchanging information and a protocol for passing objects over the Internet. Several companies have taken these specifications and developed implementations of CORBA for Java. Inprise VisiBroker is the leading commercial implementation, and Sun recently released Java IDL as a core API as part of the Java 2 platform release. There are also implementations available for different languages and platforms.

The language CORBA uses to define objects is the Interface Definition Language, or IDL. Once an object is defined using IDL, it can be translated to a specific language such as C++ or Java. This object can then be used by both the client and server modules as a native object. The object is passed between the client and the server using the Internet Inter-ORB Protocol (IIOP), a protocol for translating the General Inter-ORB Protocol (GIOP) for use with TCP/IP. In other words, IIOP is the protocol used for transferring these CORBA objects from one side to the other over the Internet.

The Object Request Broker (ORB) is the active part of a CORBA implementation. It receives a request for information from one module of the application, finds an implementation of the object associated with that information and handles the transfer between modules. For example, in the time-tracking application above, the applet code might call a method that is actually implemented in the server. When the method is called, the ORB is given the request, passes any parameters of the method to the server side, executes the method and sends the return value back to the client. This is all transparent to the client code, so that writing a client application using CORBA is not significantly different from writing a normal Java application. The CORBA specification includes ORB interoperability, guaranteeing that an object passed to one vendor's ORB can be understood by any ORB written by any other vendor. A simple example of the client server and IDL code for an application can be seen in Listing 1.

CORBA is an excellent protocol to use when the goal is to pass information transparently between the client and server. Many of the implementations exhibit high performance and are easy to use and incorporate into existing applications. The guarantee of ORB interoperability makes it easy to switch implementations and add code or JavaBeans from other sources to existing CORBA-compliant code.

What Are Servlets?
Servlets are Java modules that can be executed by a Web server. They are similar to CGI scripts, but have several significant advantages. First of all, they are run within the same process as the Web server, while CGI scripts are executed in separate processes. This makes servlets faster and more efficient than scripts. Second, servlets are written in Java, so they are immediately portable to multiple platforms and have the range and flexibility of the full Java language. This means, for example, that a servlet could also use the JDBC API to access a database, or even use CORBA to access a different server. CGI scripts are generally written in platform-specific languages or compilations of languages, making them hard to support and less flexible. Finally, the Java Servlet API allows easy access to a full range of information about the request, even allowing objects to pass between the client and server side. The most common uses of servlets are to drive dynamic Web sites and to produce dynamic HTML within a Web-based application.

Servlet objects are usually passed using the Hypertext Transfer Protocol (HTTP). HTTP, the most common Internet transfer protocol, is supported by all Web browsers and servers. It's specifically designed for transferring Hypertext content over the Internet, and is specialized for doing so. This means that while servlets are extremely efficient for producing and transferring dynamic HTML, they are less efficient for transferring objects between an applet and a server. For comparison, they are faster for object transfer than some implementations of CORBA, but slower than most.

Servlet implementation depends mainly on the Web server chosen to incorporate them. Sun has released a product, the Java Web Server, that natively supports servlets. A number of products, including one from Sun, add servlet support to existing Web servers, so most common ones can now support servlets. A complete list of supported servers is available from the JavaSoft home page. Once you've written a servlet and compiled it using the JDK and the Java Servlet API (or the Java Servlet Development Kit), you put the class file into a specific servlet directory in the Web server hierarchy and restart the server. At that point the servlet is ready for use. A simple example of a servlet can be found in Listing 2.

Which Should I Use?
Servlets and CORBA both have their strengths and weaknesses, and which is appropriate depends on the situation. CORBA is optimized for transferring objects transparently, while servlets are designed more for server-side processing resulting in dynamic HTML.

In the time-tracking application listed above, there are two functions that happen with reasonable frequency: storing information to the database and generating reports. In the first case, the application should pass data from the client to the server and store it in the database. This is simple object passing from an applet to a server application, which CORBA does very efficiently. The same process could be done with servlets, but it would require more coding and maintenance to work efficiently, and would generally have poorer performance. The second case is more complicated - are the reports in HTML or in Java? If HTML, then the application is passing a request to the Web server and expecting dynamic HTML in return, something that servlets do most effectively. Again, the same process could be done using CORBA (pass the request to the back end using CORBA and use that to write an HTML file that can then be displayed or downloaded by the client), but in this case CORBA requires more coding and more maintenance, and has poorer performance. However, if the report front end is in Java, CORBA again becomes a better answer.

In the case of a Java front end and HTML reporting, new questions come up. Each method is useful in its area, but there's a lot of overhead involved in implementing two different communication methods in one application, particularly a small one. Some other considerations are budget and memory requirements. Running a client-side applet, an ORB, a server-side application, a Web server and possibly a servlet plug-in can be expensive and memory intensive enough to demand a decision between the two methods. Until recently, servlets tended to be the cheaper alternative, since kits for running servlets with the major Web servers can be downloaded free. The introduction of Java IDL, however, has generated a CORBA option that is also distributed free, so either one is now a reasonable choice on a small budget. In this case, the best way to make a decision, if you can use only one method, is to plan to optimize the application for one method or the other.

One possibility is to change the front end for the application entirely to HTML. Most time-tracking applications have reasonably simple front ends and could be easily converted to HTML. This would eliminate the need for CORBA, since all pages are now dynamic HTML and will be most efficiently served by servlets. Conversely, you might decide to use a different reporting tool that uses a Java front end, eliminating the need for any HTML, which then allows you to use CORBA most effectively. Finally, you might decide to leave both the way they are and do some performance testing to see whether it is more efficient to use CORBA for your HTML or servlets for your applets, since these performance measurements are very much dependent on CORBA implementation and code specifics. Since each method can be used to duplicate the other one, once you have chosen the one with the minimum loss of performance, you can standardize on that method.

Larger applications, on the other hand, benefit greatly from using more than one method of communication. Performance and scalability are critical issues for large applications, and using more than one method can assure that the application is optimized for maximum performance. CORBA and servlets don't interfere with each other at all in an application, and can be used side by side in the same code without any problems. For example, a Web site management application may let the user save dynamic HTML to a database and then view it. CORBA could be used to send the information to the database and a servlet could then be invoked to retrieve the information, do any dynamic substitution necessary and display the final dynamic Web page. Using both can be a distinct advantage over having to optimize an application for only one method.

Where Can I Get More Information?
More information on CORBA, including CORBA, IDL and IIOP specifications, is available at www.omg.org/, the OMG home page. There is also a CORBA home page at www.corba.org/ and JavaSoft's Java IDL is available for download from the Products and APIs section of the Java home page, java.sun.com/. Information on servlets, the Java Web Server and the Java Servlet API is available from the servlet home page at jeeves.javasoft.com/. This page includes a list of products available from other vendors to support servlets on a number of servers.

More Stories By Rachel Gollub

Rachel Gollub, founder of SilentQ Software Company, learned Java as a JavaSoft engineer from 1995 to 1997, and has worked at several start-ups since then. She writes articles and gives presentations on Java and related subjects

Comments (0)

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.


IoT & Smart Cities Stories
Dion Hinchcliffe is an internationally recognized digital expert, bestselling book author, frequent keynote speaker, analyst, futurist, and transformation expert based in Washington, DC. He is currently Chief Strategy Officer at the industry-leading digital strategy and online community solutions firm, 7Summits.
Digital Transformation is much more than a buzzword. The radical shift to digital mechanisms for almost every process is evident across all industries and verticals. This is often especially true in financial services, where the legacy environment is many times unable to keep up with the rapidly shifting demands of the consumer. The constant pressure to provide complete, omnichannel delivery of customer-facing solutions to meet both regulatory and customer demands is putting enormous pressure on...
IoT is rapidly becoming mainstream as more and more investments are made into the platforms and technology. As this movement continues to expand and gain momentum it creates a massive wall of noise that can be difficult to sift through. Unfortunately, this inevitably makes IoT less approachable for people to get started with and can hamper efforts to integrate this key technology into your own portfolio. There are so many connected products already in place today with many hundreds more on the h...
The standardization of container runtimes and images has sparked the creation of an almost overwhelming number of new open source projects that build on and otherwise work with these specifications. Of course, there's Kubernetes, which orchestrates and manages collections of containers. It was one of the first and best-known examples of projects that make containers truly useful for production use. However, more recently, the container ecosystem has truly exploded. A service mesh like Istio addr...
Digital Transformation: Preparing Cloud & IoT Security for the Age of Artificial Intelligence. As automation and artificial intelligence (AI) power solution development and delivery, many businesses need to build backend cloud capabilities. Well-poised organizations, marketing smart devices with AI and BlockChain capabilities prepare to refine compliance and regulatory capabilities in 2018. Volumes of health, financial, technical and privacy data, along with tightening compliance requirements by...
Charles Araujo is an industry analyst, internationally recognized authority on the Digital Enterprise and author of The Quantum Age of IT: Why Everything You Know About IT is About to Change. As Principal Analyst with Intellyx, he writes, speaks and advises organizations on how to navigate through this time of disruption. He is also the founder of The Institute for Digital Transformation and a sought after keynote speaker. He has been a regular contributor to both InformationWeek and CIO Insight...
Andrew Keys is Co-Founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life settlement products to hedge funds and investment banks. After, he co-founded a revenue cycle management company where he learned about Bitcoin and eventually Ethereal. Andrew's role at ConsenSys Enterprise is a mul...
To Really Work for Enterprises, MultiCloud Adoption Requires Far Better and Inclusive Cloud Monitoring and Cost Management … But How? Overwhelmingly, even as enterprises have adopted cloud computing and are expanding to multi-cloud computing, IT leaders remain concerned about how to monitor, manage and control costs across hybrid and multi-cloud deployments. It’s clear that traditional IT monitoring and management approaches, designed after all for on-premises data centers, are falling short in ...
In his general session at 19th Cloud Expo, Manish Dixit, VP of Product and Engineering at Dice, discussed how Dice leverages data insights and tools to help both tech professionals and recruiters better understand how skills relate to each other and which skills are in high demand using interactive visualizations and salary indicator tools to maximize earning potential. Manish Dixit is VP of Product and Engineering at Dice. As the leader of the Product, Engineering and Data Sciences team at D...
Dynatrace is an application performance management software company with products for the information technology departments and digital business owners of medium and large businesses. Building the Future of Monitoring with Artificial Intelligence. Today we can collect lots and lots of performance data. We build beautiful dashboards and even have fancy query languages to access and transform the data. Still performance data is a secret language only a couple of people understand. The more busine...