Welcome!

XML Authors: Liz McMillan, Anne Buff, Carmen Gonzalez, Paige Leidig, Sanjeev Sharma

Related Topics: Java, XML, SOA & WOA, Websphere, Weblogic, AJAX & REA

Java: Article

Part 3 | Component Models in Java

Service Component Architecture Model

Service Component Architecture (shortly referred as SCA) is a technology for creating services from components. SCA is a set of OASIS standards and part of it is developed with the collaboration of vendors from open source community, referred as "OSOA" Open SOA. SCA helps to build systems as a collection of interconnected components. The components created in SCA communicate through the services. The advantage of SCA is its neutral component model. It allows services to be built by any language component like Java, C++, BPEL, JavaScript, Ruby, Python etc. SCA addresses two important needs of component world:

  • Complexity
  • Reusability

SCA is best suited model for distributed systems. SCA simplifies building of systems by simple assembling of components. SCA like other component model discussed in the previous sections facilitates component assembly in the middle tier - business tier of N-tier architecture. SCA has some key elements like services, components, composites and domains.

In SCA, applications are created and assembled as components. Components contain the functionality to be exposed to the clients. The functionality provided by the components is exposed as services. Multiple components in the application interact and get bounded by a mechanism called "wire". Components are connected through wire and their services are exposed through a composite.

Several open source tools/IDEs helps to develop SCA application using designer tools. The key elements in SCA are represented through some standard symbols are represented in Figure 1.

Figure 1: SCA Key Elements

 

Services
Services are the functionality provided by the components. They are intended to perform the business function. Services can be implemented in any language like Java, C# and BPEL. Service has two primary attributes:

  • Service Contract
  • Service Address

Service contract defines the methods, input parameters for the methods and the return value. Service contract can be defined in several ways. In Java, service contract is a simple interface (POJI - Plain Old Java Interface) which exposes the functionality of the components. Service contract in Java is usually an interface which can be used locally as well as remotely. The remote service contract will have SCA annotation @Remotable. In SOA world, the service contract is defined as a WSDL file. IDL is also one of the ways to define service contract.

While service contract exposes the functionality provided by the component, Service address is used by the clients to uniquely identify the service. Service address is unique per service. Reusability is achieved through the service address, because clients connect to the service through the service address.

Component
Component provides one or more services. Components contain the business logic for the functionality exposed by service contracts - interfaces. Components can be implemented in any language supported by runtime like Java, C#, BPEL, Ruby, Python etc. Components are implemented as POJOs in Java. The Java class has to implement the Java interface defined as the service contract. Component will have an associated service, optionally a reference and a property. The service is used for exposing the functionality of the component. A reference is another interface contract provided by some other component. Component's dependency on another component is resolved through reference. A property of a component is a configurable parameter which is used to change the behavior of the component dynamically during runtime (with some of its parameters being changed). In the Java class which represents the component, property is specified as an annotation and the reference is also mentioned as an annotation.

Figure 2: Component with Services, References and Properties

Composite
A composite is a XML file which is used for configuring components. The association of the component with the service and the reference is all mentioned in the composite. A composite is the main element which is used for configuring components. The XML file is written using a language called SCDL - Service Component Definition Language which is based on XML. The composite can be written as set of XML elements or can be created using the composite designer tools provided by IDEs.

Figure 3: Composite graphical representation

First a composite is defined, then components are defined as part of it. The services provided are defined as part of the component definition. A composite is used to configure more than one component.

If a component is dependent on another component, then a reference is defined on the component which has dependency. The reference is service contract of the other component. Service and reference are connected using "Wire". Wire acts as a binding element between client component and the target component. The wire binding can be defined as a local or remote binding. The wire binding reference is also configured in the composite. In the implementation, the references to other components are referred using @Reference annotation. The reference of the target component is obtained using dependency injection. The reference dependency injection can be constructor based or setter methods based or field based injection. However the field based injection is concise which is preferred.

If the component's behavior has to be changed during runtime through change in the value of the attributes,  a property can be defined on the composite.

Figure 4: Component Wiring

Domain
Components are created and configured in composite. The composite is deployed in SCA runtime environment called ‘Domain'. A SCA domain is a collection of SCA runtime instances. SCA runtime instances host components in containers. SCA domain allows composites to be deployed as a whole and also individual component. It is possible to deploy components from a composite to be deployed in different runtimes which is purely vendor specific. The domain provides the required services like resource sharing, communication and management to the components deployed in it.

SCA Component Model Example
The SCA component model can be understood with the same shopping Cart example discussed in the models discussed earlier.

Here in this example, there is only a single component called ‘CartServiceComponent'  which exposes its functionality through the CartService interface which is the service contract for the CartServiceComponent. As a first step, the service contract is defined. The CartService interface is a service contract which contains the business methods defined by the component.

package com.online.shopping.intf;

import java.util.Collection;

public interface CartService {
public void addItem(Product product, int quantity);
public Collection<Product> listItems();    
public double getTotalPrice();
public void clearCart();
}

The CartService is implemented by the class CartServiceImpl is a POJO which represents the CartServiceComponent.

package com.online.shopping.impl;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import com.online.shopping.intf.CartService;
import com.online.shopping.intf.Product;

public class CartServiceImpl implements CartService {
Map<Product, Integer> items = new HashMap<Product, Integer>();      
@Override
public void addItem(Product product, int quantity) {
if(items.containsKey(product)) {
quantity +=items.get(product);
}
items.put(product, quantity);
}

@Override
public Collection<Product> listItems() {
return items.keySet();
}

@Override
public double getTotalPrice() {
double totalPrice = 0;
for(Product product: items.keySet()) {
totalPrice+=product.getPrice()* items.get(product);           
}
return totalPrice;
}

@Override
public void clearCart() {
items.clear();
}

}

The service contract and the component are connected using SCA composite designer tool provided by IDEs like Eclipse. Using the tool, a composite is created named ‘Cart.composite'. The composite is an XML file which will have an associated Cart.composite_diagram which represents the composite file as a graphical representation. In the Cart composite diagram, using the component creation tool, a component is created named ‘CartServiceComponent'. A service is added to the composite named ‘CartService'.  Using the designer tool, the Java interface file is dragged and dropped on to the Service defined and the Java implementation class to the CartServiceComponent. The service is promoted using the tool (that is exposing the service for clients to consume it). The graphical representation of composite diagram is as follows:

Figure 5: SCA Component Model - Cart Component Example

The composite file contains XML code that describes the component assembly in the composite diagram.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<sca:composite xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" name="Cart" targetNamespace="http://eclipse.org/SCACart/Cart">
<sca:component name="CartServiceComponent">
<sca:implementation.java
class="com.online.shopping.impl.CartServiceImpl"/>

<sca:service name="CartService">
<sca:interface.java
interface="com.online.shopping.intf.CartService"/>
</sca:service>

</sca:component>

<sca:service name="CartService"         
promote="CartServiceComponent/CartService"/>

</sca:composite>

The CartServiceComponent is created and assembled. The component is deployed in SCADomain as a single component with the id ‘CartService'. This is evident from the <sca:service> element having an attribute called ‘promote' in the composite XML file. The SCADomain is the runtime for the SCA components. In this example, Apache Tuscany is the runtime used for deploying composite. The client for the CartServiceComponent first looks up for the composite in the SCADomain where it is deployed. From the domain, client looks for the service with the service address and the service contract. Once it gets the service reference, the client consumes the methods exposed by the component.

package com.client.shopping;

import java.util.Collection;

import org.apache.tuscany.sca.host.embedded.SCADomain;

import com.online.shopping.intf.CartService;
import com.online.shopping.intf.Product;

public class CartClient {

public static void main(String arg[]) {
SCADomain scaDomain = SCADomain.newInstance("Cart.composite");
CartService cartService = scaDomain.getService(
CartService.class, "CartServiceComponent");

Product product = new Product();
product.setName("OSGi");
product.setPrice(550.00);
cartService.addItem(product, 20);

Product newProduct = new Product();
newProduct.setName("SCA");
newProduct.setPrice(300.00);
cartService.addItem(newProduct, 10);

Collection<Product> productItems = cartService.listItems();
for(Product items: productItems) {
System.out.println(items.getName()+"******"+ items.getPrice());             
}            

System.out.println("Total Price of Cart Items: "+cartService.getTotalPrice());

cartService.clearCart();
}
}

Thus SCA component model provides easy steps for creating and assembling components. Assembling components is easy by linking the reference to the service of the target components. SCA promotes reuse through service contracts and address and solves complexity through loose coupling. SCA as a component model promotes reusability and it is highly preferred for assembly if components. The advantage of SCA is its language neutral for several languages like Java, C#, Ruby etc.

Summary
Componentization provides several advantages. The component models play an important role in developing, deploying and assembling of components for an application. Component models provide a simpler way for component reference and look up and hence making the development easier.

In this article we discussed about four latest component models in Java - Enterprise JavaBeans, Spring, OSGi and SCA in brief. We understand that each component model has its own standards for development and assembly. The runtime environment provided by these component framework helps in execution of the components developed using the appropriate model. We also tried to understand the similarity and differences of these component models through a simple component ‘Cart' component which is part of online shopping application.

More Stories By Piram Manickam

Piram Manickam works at Infosys Limited. He would like to acknowledge and thank Sangeetha S, a beloved colleague and friend, for her invaluable contributions in this work.

More Stories By Subrahmanya SV

Subrahmanya SV works at Infosys Limited. He would like to acknowledge and thank Sangeetha S, a beloved colleague and friend, for her invaluable contributions in this work.

More Stories By S Sangeetha

S Sangeetha is a Senior Technical Architect at the E-Commerce Research Labs at Infosys Limited. She has over 15 years of experience in architecture, design and development of enterprise Java applications. She is also involved in enhancing the technical skills of Architects at Infosys. She has co-authored a book on ‘J2EE Architecture’ and also has written numerous articles on Java for various online Java forums like JavaWorld, java.net, DevX.com and internet.com. She can be reached at [email protected]

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.


@ThingsExpo Stories
SYS-CON Events announced today that Harbinger Systems will exhibit at SYS-CON's 15th International Cloud Expo®, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Harbinger Systems is a global company providing software technology services. Since 1990, Harbinger has developed a strong customer base worldwide. Its customers include software product companies ranging from hi-tech start-ups in Silicon Valley to leading product companies in the US and large in-house IT organizations.
The only place to be June 9-11 is Cloud Expo & @ThingsExpo 2015 East at the Javits Center in New York City. Join us there as delegates from all over the world come to listen to and engage with speakers & sponsors from the leading Cloud Computing, IoT & Big Data companies. Cloud Expo & @ThingsExpo are the leading events covering the booming market of Cloud Computing, IoT & Big Data for the enterprise. Speakers from all over the world will be hand-picked for their ability to explore the economic strategies that utility/cloud computing provides. Whether public, private, or in a hybrid form, clo...
SYS-CON Events announces a new pavilion on the Cloud Expo floor where WebRTC converges with the Internet of Things. Pavilion will showcase WebRTC and the Internet of Things. The Internet of Things (IoT) is the most profound change in personal and enterprise IT since the creation of the Worldwide Web more than 20 years ago. All major researchers estimate there will be tens of billions devices--computers, smartphones, tablets, and sensors – connected to the Internet by 2020. This number will continue to grow at a rapid pace for the next several decades.
SYS-CON Events announced today that Gridstore™, the leader in software-defined storage (SDS) purpose-built for Windows Servers and Hyper-V, will exhibit at SYS-CON's 15th International Cloud Expo®, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Gridstore™ is the leader in software-defined storage purpose built for virtualization that is designed to accelerate applications in virtualized environments. Using its patented Server-Side Virtual Controller™ Technology (SVCT) to eliminate the I/O blender effect and accelerate applications Gridsto...
SYS-CON Events announced today that Red Hat, the world's leading provider of open source solutions, will exhibit at Internet of @ThingsExpo, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Red Hat is the world's leading provider of open source software solutions, using a community-powered approach to reliable and high-performing cloud, Linux, middleware, storage and virtualization technologies. Red Hat also offers award-winning support, training, and consulting services. As the connective hub in a global network of enterprises, partners, a...
As the Internet of Things unfolds, mobile and wearable devices are blurring the line between physical and digital, integrating ever more closely with our interests, our routines, our daily lives. Contextual computing and smart, sensor-equipped spaces bring the potential to walk through a world that recognizes us and responds accordingly. We become continuous transmitters and receivers of data. In his session at Internet of @ThingsExpo, Andrew Bolwell, Director of Innovation for HP’s Printing and Personal Systems Group, will discuss how key attributes of mobile technology – touch input, senso...
The Internet of Things (IoT) is making everything it touches smarter – smart devices, smart cars and smart cities. And lucky us, we’re just beginning to reap the benefits as we work toward a networked society. However, this technology-driven innovation is impacting more than just individuals. The IoT has an environmental impact as well, which brings us to the theme of this month’s #IoTuesday Twitter chat. The ability to remove inefficiencies through connected objects is driving change throughout every sector, including waste management. BigBelly Solar, located just outside of Boston, is trans...
Connected devices and the Internet of Things are getting significant momentum in 2014. In his session at Internet of @ThingsExpo, Jim Hunter, Chief Scientist & Technology Evangelist at Greenwave Systems, will examine three key elements that together will drive mass adoption of the IoT before the end of 2015. The first element is the recent advent of robust open source protocols (like AllJoyn and WebRTC) that facilitate M2M communication. The second is broad availability of flexible, cost-effective storage designed to handle the massive surge in back-end data in a world where timely analytics...
Internet of @ThingsExpo Silicon Valley announced on Thursday its first 12 all-star speakers and sessions for its upcoming event, which will take place November 4-6, 2014, at the Santa Clara Convention Center in California. @ThingsExpo, the first and largest IoT event in the world, debuted at the Javits Center in New York City in June 10-12, 2014 with over 6,000 delegates attending the conference. Among the first 12 announced world class speakers, IBM will present two highly popular IoT sessions, which will take place November 4-6, 2014 at the Santa Clara Convention Center in Santa Clara, Calif...
The Internet of Things (IoT) promises to evolve the way the world does business; however, understanding how to apply it to your company can be a mystery. Most people struggle with understanding the potential business uses or tend to get caught up in the technology, resulting in solutions that fail to meet even minimum business goals. In his session at Internet of @ThingsExpo, Jesse Shiah, CEO / President / Co-Founder of AgilePoint Inc., will show what is needed to leverage the IoT to transform your business. He will discuss opportunities and challenges ahead for the IoT from a market and tec...
SYS-CON Events announced today that TeleStax, the main sponsor of Mobicents, will exhibit at Internet of @ThingsExpo, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. TeleStax provides Open Source Communications software and services that facilitate the shift from legacy SS7 based IN networks to IP based LTE and IMS networks hosted on private (on-premise), hybrid or public clouds. TeleStax products include Restcomm, JSLEE, SMSC Gateway, USSD Gateway, SS7 Resource Adaptors, SIP Servlets, Rich Multimedia Services, Presence Services/RCS, Diame...
From a software development perspective IoT is about programming "things," about connecting them with each other or integrating them with existing applications. In his session at @ThingsExpo, Yakov Fain, co-founder of Farata Systems and SuranceBay, will show you how small IoT-enabled devices from multiple manufacturers can be integrated into the workflow of an enterprise application. This is a practical demo of building a framework and components in HTML/Java/Mobile technologies to serve as a platform that can integrate new devices as they become available on the market.
SYS-CON Events announced today that O'Reilly Media has been named “Media Sponsor” of SYS-CON's 15th International Cloud Expo®, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. O'Reilly Media spreads the knowledge of innovators through its books, online services, magazines, and conferences. Since 1978, O'Reilly Media has been a chronicler and catalyst of cutting-edge development, homing in on the technology trends that really matter and spurring their adoption by amplifying "faint signals" from the alpha geeks who are creating the future. An...
The Transparent Cloud-computing Consortium (abbreviation: T-Cloud Consortium) will conduct research activities into changes in the computing model as a result of collaboration between "device" and "cloud" and the creation of new value and markets through organic data processing High speed and high quality networks, and dramatic improvements in computer processing capabilities, have greatly changed the nature of applications and made the storing and processing of data on the network commonplace.
SYS-CON Events announced today that Aria Systems, the recurring revenue expert, has been named "Bronze Sponsor" of SYS-CON's 15th International Cloud Expo®, which will take place on November 4-6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Aria Systems helps leading businesses connect their customers with the products and services they love. Industry leaders like Pitney Bowes, Experian, AAA NCNU, VMware, HootSuite and many others choose Aria to power their recurring revenue business and deliver exceptional experiences to their customers.
The Internet of Things (IoT) is going to require a new way of thinking and of developing software for speed, security and innovation. This requires IT leaders to balance business as usual while anticipating for the next market and technology trends. Cloud provides the right IT asset portfolio to help today’s IT leaders manage the old and prepare for the new. Today the cloud conversation is evolving from private and public to hybrid. This session will provide use cases and insights to reinforce the value of the network in helping organizations to maximize their company’s cloud experience.
As a disruptive technology, Web Real-Time Communication (WebRTC), which is an emerging standard of web communications, is redefining how brands and consumers communicate in real time. The on-going narrative around WebRTC has largely been around incorporating video, audio and chat functions to apps. In his session at Internet of @ThingsExpo, Alex Gouaillard, Founder and CTO of Temasys Communications, will look at a fourth element – data channels – and talk about its potential to move WebRTC beyond browsers and into the Internet of Things.
SYS-CON Events announced today that Gigaom Research has been named "Media Sponsor" of SYS-CON's 15th International Cloud Expo®, which will take place on November 4-6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Ashar Baig, Research Director, Cloud, at Gigaom Research, will also lead a Power Panel on the topic "Choosing the Right Cloud Option." Gigaom Research provides timely, in-depth analysis of emerging technologies for individual and corporate subscribers. Gigaom Research's network of 200+ independent analysts provides new content daily that bridges the gap between break...
We certainly live in interesting technological times. And no more interesting than the current competing IoT standards for connectivity. Various standards bodies, approaches, and ecosystems are vying for mindshare and positioning for a competitive edge. It is clear that when the dust settles, we will have new protocols, evolved protocols, that will change the way we interact with devices and infrastructure. We will also have evolved web protocols, like HTTP/2, that will be changing the very core of our infrastructures. At the same time, we have old approaches made new again like micro-services...
The Industrial Internet revolution is now underway, enabled by connected machines and billions of devices that communicate and collaborate. The massive amounts of Big Data requiring real-time analysis is flooding legacy IT systems and giving way to cloud environments that can handle the unpredictable workloads. Yet many barriers remain until we can fully realize the opportunities and benefits from the convergence of machines and devices with Big Data and the cloud, including interoperability, data security and privacy.