Welcome!

XML Authors: Pat Romanski, Liz McMillan, Carmen Gonzalez, Elizabeth White, Esmeralda Swartz

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
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.
Connected devices are changing the way we go about our everyday life, from wearables to driverless cars, to smart grids and entire industries revolutionizing business opportunities through smart objects, capable of two-way communication. But what happens when objects are given an IP-address, and we rely on that connection, sometimes with our lives? How do we secure those vast data infrastructures and safe-keep the privacy of sensitive information? This session will outline how each and every connected device can uphold a core root of trust via a unique cryptographic signature – a “bir...
SYS-CON Events announced today that Utimaco 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. Utimaco is a leading manufacturer of hardware based security solutions that provide the root of trust to keep cryptographic keys safe, secure critical digital infrastructures and protect high value data assets. Only Utimaco delivers a general-purpose hardware security module (HSM) as a customizable platform to easily integrate into existing software solutions, embed business logic and build s...
SYS-CON Events announced today that SOA Software, an API management leader, 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. SOA Software is a leading provider of API Management and SOA Governance products that equip business to deliver APIs and SOA together to drive their company to meet its business strategy quickly and effectively. SOA Software’s technology helps businesses to accelerate their digital channels with APIs, drive partner adoption, monetize their assets, and achieve a...
How do APIs and IoT relate? The answer is not as simple as merely adding an API on top of a dumb device, but rather about understanding the architectural patterns for implementing an IoT fabric. There are typically two or three trends: Exposing the device to a management framework Exposing that management framework to a business centric logic • Exposing that business layer and data to end users. This last trend is the IoT stack, which involves a new shift in the separation of what stuff happens, where data lives and where the interface lies. For instance, it’s a mix of architectural style...
Almost everyone sees the potential of Internet of Things but how can businesses truly unlock that potential. The key will be in the ability to discover business insight in the midst of an ocean of Big Data generated from billions of embedded devices via Systems of Discover. Businesses will also need to ensure that they can sustain that insight by leveraging the cloud for global reach, scale and elasticity.
BSQUARE is a global leader of embedded software solutions. We enable smart connected systems at the device level and beyond that millions use every day and provide actionable data solutions for the growing Internet of Things (IoT) market. We empower our world-class customers with our products, services and solutions to achieve innovation and success. For more information, visit www.bsquare.com.
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...
SYS-CON Events announced today that Matrix.org has been named “Silver Sponsor” of Internet of @ThingsExpo, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Matrix is an ambitious new open standard for open, distributed, real-time communication over IP. It defines a new approach for interoperable Instant Messaging and VoIP based on pragmatic HTTP APIs and WebRTC, and provides open source reference implementations to showcase and bootstrap the new standard. Our focus is on simplicity, security, and supporting the fullest feature set.
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...
P2P RTC will impact the landscape of communications, shifting from traditional telephony style communications models to OTT (Over-The-Top) cloud assisted & PaaS (Platform as a Service) communication services. The P2P shift will impact many areas of our lives, from mobile communication, human interactive web services, RTC and telephony infrastructure, user federation, security and privacy implications, business costs, and scalability. In his session at Internet of @ThingsExpo, Robin Raymond, Chief Architect at Hookflash Inc., will walk through the shifting landscape of traditional telephone a...
WebRTC defines no default signaling protocol, causing fragmentation between WebRTC silos. SIP and XMPP provide possibilities, but come with considerable complexity and are not designed for use in a web environment. In his session at Internet of @ThingsExpo, Matthew Hodgson, technical co-founder of the Matrix.org, will discuss how Matrix is a new non-profit Open Source Project that defines both a new HTTP-based standard for VoIP & IM signaling and provides reference implementations.

SUNNYVALE, Calif., Oct. 20, 2014 /PRNewswire/ -- Spansion Inc. (NYSE: CODE), a global leader in embedded systems, today added 96 new products to the Spansion® FM4 Family of flexible microcontrollers (MCUs). Based on the ARM® Cortex®-M4F core, the new MCUs boast a 200 MHz operating frequency and support a diverse set of on-chip peripherals for enhanced human machine interfaces (HMIs) and machine-to-machine (M2M) communications. The rich set of periphera...

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.
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...
SYS-CON Events announced today that Matrix.org has been named “Silver Sponsor” of Internet of @ThingsExpo, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Matrix is an ambitious new open standard for open, distributed, real-time communication over IP. It defines a new approach for interoperable Instant Messaging and VoIP based on pragmatic HTTP APIs and WebRTC, and provides open source reference implementations to showcase and bootstrap the new standard. Our focus is on simplicity, security, and supporting the fullest feature set.
Predicted by Gartner to add $1.9 trillion to the global economy by 2020, the Internet of Everything (IoE) is based on the idea that devices, systems and services will connect in simple, transparent ways, enabling seamless interactions among devices across brands and sectors. As this vision unfolds, it is clear that no single company can accomplish the level of interoperability required to support the horizontal aspects of the IoE. The AllSeen Alliance, announced in December 2013, was formed with the goal to advance IoE adoption and innovation in the connected home, healthcare, education, aut...
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...
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...