Java IoT Authors: Liz McMillan, Elizabeth White, Yeshim Deniz, Zakia Bouachraoui, Pat Romanski

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
The deluge of IoT sensor data collected from connected devices and the powerful AI required to make that data actionable are giving rise to a hybrid ecosystem in which cloud, on-prem and edge processes become interweaved. Attendees will learn how emerging composable infrastructure solutions deliver the adaptive architecture needed to manage this new data reality. Machine learning algorithms can better anticipate data storms and automate resources to support surges, including fully scalable GPU-c...
Machine learning has taken residence at our cities' cores and now we can finally have "smart cities." Cities are a collection of buildings made to provide the structure and safety necessary for people to function, create and survive. Buildings are a pool of ever-changing performance data from large automated systems such as heating and cooling to the people that live and work within them. Through machine learning, buildings can optimize performance, reduce costs, and improve occupant comfort by ...
The explosion of new web/cloud/IoT-based applications and the data they generate are transforming our world right before our eyes. In this rush to adopt these new technologies, organizations are often ignoring fundamental questions concerning who owns the data and failing to ask for permission to conduct invasive surveillance of their customers. Organizations that are not transparent about how their systems gather data telemetry without offering shared data ownership risk product rejection, regu...
René Bostic is the Technical VP of the IBM Cloud Unit in North America. Enjoying her career with IBM during the modern millennial technological era, she is an expert in cloud computing, DevOps and emerging cloud technologies such as Blockchain. Her strengths and core competencies include a proven record of accomplishments in consensus building at all levels to assess, plan, and implement enterprise and cloud computing solutions. René is a member of the Society of Women Engineers (SWE) and a m...
Poor data quality and analytics drive down business value. In fact, Gartner estimated that the average financial impact of poor data quality on organizations is $9.7 million per year. But bad data is much more than a cost center. By eroding trust in information, analytics and the business decisions based on these, it is a serious impediment to digital transformation.
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...
Predicting the future has never been more challenging - not because of the lack of data but because of the flood of ungoverned and risk laden information. Microsoft states that 2.5 exabytes of data are created every day. Expectations and reliance on data are being pushed to the limits, as demands around hybrid options continue to grow.
Digital Transformation and Disruption, Amazon Style - What You Can Learn. Chris Kocher is a co-founder of Grey Heron, a management and strategic marketing consulting firm. He has 25+ years in both strategic and hands-on operating experience helping executives and investors build revenues and shareholder value. He has consulted with over 130 companies on innovating with new business models, product strategies and monetization. Chris has held management positions at HP and Symantec in addition to ...
Enterprises have taken advantage of IoT to achieve important revenue and cost advantages. What is less apparent is how incumbent enterprises operating at scale have, following success with IoT, built analytic, operations management and software development capabilities - ranging from autonomous vehicles to manageable robotics installations. They have embraced these capabilities as if they were Silicon Valley startups.
As IoT continues to increase momentum, so does the associated risk. Secure Device Lifecycle Management (DLM) is ranked as one of the most important technology areas of IoT. Driving this trend is the realization that secure support for IoT devices provides companies the ability to deliver high-quality, reliable, secure offerings faster, create new revenue streams, and reduce support costs, all while building a competitive advantage in their markets. In this session, we will use customer use cases...