Part 3 | Component Models in Java

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

ServicesServices 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.

ComponentComponent 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

CompositeA 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

DomainComponents 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 ExampleThe 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.

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.

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.

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.

SummaryComponentization 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.

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 sangeethas@infosys.com.

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.

At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throug...

This month @nodexl announced that ServerlessSUMMIT & DevOpsSUMMIT own the world's top three most influential Kubernetes domains which are more influential than LinkedIn, Twitter, YouTube, Medium, Infoworld and Microsoft combined.
NodeXL is a template for Microsoft® Excel® (2007, 2010, 2013 and 2016) on Windows (XP, Vista, 7, 8, 10) that lets you enter a network edge list into a workbook, click a button, see a network graph, and get a detailed summary report, all in the familiar environment of...

IT professionals are also embracing the reality of Serverless architectures, which are critical to developing and operating real-time applications and services. Serverless is particularly important as enterprises of all sizes develop and deploy Internet of Things (IoT) initiatives.
Serverless and Kubernetes are great examples of continuous, rapid pace of change in enterprise IT. They also raise a number of critical issues and questions about employee training, development processes, and opera...

At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throug...

Atmosera delivers modern cloud services that maximize the advantages of cloud-based infrastructures. Offering private, hybrid, and public cloud solutions, Atmosera works closely with customers to engineer, deploy, and operate cloud architectures with advanced services that deliver strategic business outcomes. Atmosera's expertise simplifies the process of cloud transformation and our 20+ years of experience managing complex IT environments provides our customers with the confidence and trust tha...

The Japan External Trade Organization (JETRO) is a non-profit organization that provides business support services to companies expanding to Japan. With the support of JETRO's dedicated staff, clients can incorporate their business; receive visa, immigration, and HR support; find dedicated office space; identify local government subsidies; get tailored market studies; and more.

At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throug...

As you know, enterprise IT conversation over the past year have often centered upon the open-source Kubernetes container orchestration system. In fact, Kubernetes has emerged as the key technology -- and even primary platform -- of cloud migrations for a wide variety of organizations.
Kubernetes is critical to forward-looking enterprises that continue to push their IT infrastructures toward maximum functionality, scalability, and flexibility.
As they do so, IT professionals are also embr...

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...

As you know, enterprise IT conversation over the past year have often centered upon the open-source Kubernetes container orchestration system. In fact, Kubernetes has emerged as the key technology -- and even primary platform -- of cloud migrations for a wide variety of organizations.
Kubernetes is critical to forward-looking enterprises that continue to push their IT infrastructures toward maximum functionality, scalability, and flexibility.
As they do so, IT professionals are also embracing the reality of Serverless architectures, which are critical to developing and operating real-t...

At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throughout enterprises of all sizes.

Technology has changed tremendously in the last 20 years. From onion architectures to APIs to microservices to cloud and containers, the technology artifacts shipped by teams has changed. And that's not all - roles have changed too. Functional silos have been replaced by cross-functional teams, the skill sets people need to have has been redefined and the tools and approaches for how software is developed and delivered has transformed. When we move from highly defined rigid roles and systems to more fluid ones, we gain agility at the cost of control. But where do we want to keep control? How d...

Cloud computing budgets worldwide are reaching into the hundreds of billions of dollars, and no organization can survive long without some sort of cloud migration strategy. Each month brings new announcements, use cases, and success stories.