|By Piram Manickam, Subrahmanya SV||
|April 10, 2012 01:30 PM EDT||
This article introduces the concepts of Component Oriented Development and Assembly (CODA) using the OSGi Service platform with an example application. The article starts with an introduction to software components, elaborates with an example application, followed by an overview of the OSGi Service platform, and an implementation of the example application using this platform.
Introduction to Software Components
Components are parts that can be assembled to form a larger system. Electronic components such as ICs (Integrated Circuits) are assembled together to build an electronic system; similarly software components are assembled together to build a software system. Software systems have a static form as well as a dynamic runtime form. Software components can be assembled either in static form or dynamic form. In either case, the software component is an independent unit of development, deployment, and assembly. Using components to build software systems will provide many architectural advantages apart from promoting ease of reuse.
Age Calculation - An Example Application
Consider an application meant for calculating the age of people. Assume this application prompts the user to provide her personal details such as name and date of birth. Once the user provides the details, the application calculates the age of the person as of today and displays it with a personal greeting. Such an application can be built from the following software components:
- UserProfile Component: Responsible for collecting the personal details of the user such as name and date of birth
- Age Component: Responsible for calculating the age, given the date of birth
- Greeting Component: Responsible for displaying the greeting message along with age of the person; needs to make use of the UserProfile component to obtain input from the user and Age component to calculate the age
- AgeCalculationApp Component: Responsible for invoking the Greeting service provided by Greeting component
The components can be represented in a UML component diagram as shown in Figure 1. The dotted arrow lines in the diagram denote dependency.
Figure 1: Components in the Age Calculation application
Interfaces of Software Components
A software interface is a collection of software operations. Software components interact with one another by invoking the software operations. To facilitate structured interactions across components, each component exposes one or more software interfaces through which other components can interact. The exposed interfaces of a component are called as its "provided interfaces." Internals of the component implement the service contracts exposed by the provided interfaces.
Apart from providing services, a component needs to consume services provided by other components. The set of services that a component wants to consume is specified through "required interfaces". A component can work with any other component that provides the required interfaces. Hence there is no tight coupling between one component and another; the dependency of a component is only with interfaces and not with other components.
Interfaces in the Age Calculation Application
Let us identify the interfaces provided and required by each of the four components in the Age Calculation application.
The Age component is responsible for calculating the age, given the date of birth. Hence it needs to provide a service for calculating the age. Let's expose this service through a provided interface IAgeCalculation. The Java code for this interface is given in Figure 2.
Figure 2: AgeCalculation Java interface code
In the IAgeCalculation interface definition, Calendar is a data type defined in java.util package to represent the date. IAge is a custom-defined data type to hold the age. The Java code for IAge is shown in Figure 3.
Figure 3: Java code for data type IAge
The Age Component can be represented in a UML component diagram as shown in Figure 4. The lollipop connector from the component denotes provided interface.
Figure 4: UML representation of Age component
The UserProfile component is responsible for collecting the personal information from end user and passing it back to the consuming component. Let us define an interface called as IUserProfileCollection to expose this service. The Java code for this interface is shown in Figure 5.
Figure 5: Java code for IUserProfileCollection interface
When the method collectUserProfile() is called, the component starts an interactive session with the end user to collect her personal information. During the user interaction session, the method isProfileCollected() will return false; after the user interaction session has finished and the user profile has been collected, this method will return true. At this time, the user profile is ready for pick-up by the consuming component and it can do so by invoking giveUserProfile() method.
giveUserProfile() method returns the user profile information through a custom defined data type IUserProfile. Java code for IUserProfile data type is given in Figure 6.
Figure 6: Java code for IUserProfile data type
The UserProfile component in a UML component diagram notation is shown in Figure 7.
Figure 7: UML representation of UserProfile component
The Greeting component is responsible for displaying the greeting message along with the age. We'll expose this service through the IGreeting interface. The Java code for IGreeting interface is shown in Figure 8.
Figure 8: Java code for interface IGreeting
The Greeting component provides the IGreeting service, and it requires the IAgeCalculation and IUserProfileCollection services. The required and provided interfaces of the Greeting component can be represented using the UML component diagram as shown in Figure 9. The receptacle sockets in the component diagram denote required interfaces.
Figure 9: UML representation of Greeting component
The AgeCalculationApp component is responsible for invoking the IGreeting service of Greeting component. The AgeCalculationApp itself does not provide any service. The UML diagram for this component is shown in Figure 10.
Figure 10: UML representation of AgeCalculationApp
Components are assembled together to build a software system. Components for an assembly should be chosen such a way that, amongst the chosen components the set of required interfaces is fulfilled by the set of provided interfaces. The four components of the example application can be assembled to result in Age Calculation application. UML component diagram denoting this assembly is shown in Figure 11. Connectors with a lollipop and a receptacle together show how two components assemble over a common interface (one component provides the interface and another component requires it).
Figure 11: UML representation of Age Calculation application assembly
Once an application is assembled, specific components from the assembly can be replaced with compatible newer components. Let us say we have two new components - GUIUserProfile and GUIGreeting, which have same interfaces as UserProfile and Greeting components, respectively. Then these new components can replace the old components to provide us with a GUI application. The application assembly would then look like Figure 12.
Figure 12: Age Calculation GUI Application Assembly
Introduction to the OSGi Service Platform
OSGi Service is a standards based software development platform. The platform standards are specified by the OSGi Alliance (http://www.osgi.org), formerly known as the Open Services Gateway initiative. OSGi alliance is an industry backed nonprofit organization.
OSGi platform provides a modularity and component model on top of Java. Figure 13 illustrates how OSGi logically fits in a development / deployment stack.
Figure 13: OSGi From Development / Deployment Perspective
At the core of the OSGi platform is the OSGi framework defined by standards. OSGi framework is the runtime environment on which OSGi applications can be executed. OSGi framework specifies a common API using which application developers can develop OSGi applications. The OSGi framework specifications is used by OSGi framework developers also, who build implementations of the framework as per the specifications.
There are a number of framework implementations available from different developers. A few well known framework implementations are listed below:
- Apache Felix (http://felix.apache.org)
- Eclipse Equinox (http://www.eclipse.org/equinox)
- Knoplerfish (http://www.knoplerfish.org)
The functionality of OSGi framework is divided into many layers. For our purposes, we shall focus on Modules Layer and Services Layer. Figure 14 illustrates the layers we would like to focus.
The modules layer is the bottom most layer interacting with the runtime framework. The modules layer defines a modularity framework on top of standard Java so that modules expose and interact via well-defined APIs. Individual module is called as a "bundle" in OSGi. OSGi bundle is the atomic unit of deployment on an OSGi framework. An OSGi bundle is nothing but a Java Archive (JAR) File with some special manifest information that would be used by the OSGi framework when the bundle is deployed. Unlike a normal JAR file, which exposes all its code when it is deployed on a Java Virtual Machine (JVM), the bundle does not expose all the code contained within. Only code (Java packages) marked for explicit export is exposed outside the bundle.
Figure 14: OSGi Framework Functional Layers
Above the Module layer is the Services layer. An OSGi Service is defined by a Java interface. Any bundle can implement the service, and register the service with the OSGi Service Registry. OSGi Service Registry, defined as part of framework standards, supports a publish, subscribe, and look-up mechanism of exchanging services across components. A bundle can register the service that it has implemented with the OSGi Service Registry. A bundle requiring a service can query the OSGi Service Registry to look-up any registered service implementation. Instead of looking-up, a bundle can also subscribe to be notified on service registration / unregistration events. These mechanisms make the bundles that provide service and bundles that consume service unaware of each other, leading to independent development and deployment of these components. Once deployed, they can be assembled dynamically using the OSGi Service Registry.
Implementing Age Calculation Using OSGi
The Age Calculation application has one bundle for each of the components. Each bundle has a Java package that is exposed for access from outside and an internal Java package. The exposed package defines the interfaces and the internal package contains implementation classes. The package diagram for all the bundles is shown in Figure 15.
Figure 15: Age Calculation Application bundles
The service provided by each bundle is exposed by using the OSGi Declarative Services framework. Using the same framework, each bundle also specifies the list of services it requires. The OSGi Declarative Services framework (also known as Service Component Runtime), will perform the work of registering the provided service with the OSGi Service Registry and obtaining the required service through look-up into OSGi Service Registry. Thus, the Declarative Services framework provides automatic assembly of deployed components.
As an example, let us consider the Greeting bundle. The Declarative Services specification of the components in this bundle is done through an XML file, which is given in Figure 16.
Figure 16: Greeting component Declarative Service Definition
The XML file contains following metadata about the Greeting component:
- A component by name com.demo.greeting is defined
- The component is implemented by the class com.demo.greeting.internal.Greeting
- The component requires two interfaces - IuserProfileCollection and IAgeCalculation. These required interfaces should be dynamically wired to this component using setUserProfileCollection() and setAgeCalculation() methods on the component implementation class.
- The component provides a service through the provided interface com.demo.greeting.IGreeting.
To understand how the Greeting component works, some portions of the implementation class is presented in Figure 17. The Greeting class has two field variables referring to the services required by this component. In the component Declarative Service metadata setter methods of these two variables are linked to the service reference (required interface). Hence when the Service Component Runtime (SCR) activates this component, it would call the setter methods to point these variables to objects which provide the service. For example, an instance of AgeCalculator object from Age component would be passed to ageCalculation_ member variable.
Figure 17: Implementation of Greeting component
The Greeting class's implementation of greet() method obtains the user profile by invoking IUserProfileCollection service. From the obtained profile, date of birth is extracted and IAgeCalculation service is used to calculate the age. Finally the method displays the age along with a greeting to the user.
Output from the Example Application
The Age Calculation application, with console mode user interaction components, has the following output.
osgi> What is your first name?
What is your last name?
What is your title (Mr./Ms./Mrs./Prof./Dr.)?
What is your year of birth?
What is your month of birth (1-12)?
What is your date of birth (1-31)?
Hello Mr. Albert Einstein, you are 132 years, 10 months, and 3 days old.
If we replace the Greeting and UserProfile components in the application assembly with GUIGreeting and GUIUserProfile components, the application output is as below:
The source code of the application can be downloaded as a zip file containing an Eclipse workspace folder. To open the source code and run the application simply unzip the folder and switch the Eclipse workspace to point to the unzipped folder. Choose the appropriate components in the Run Configuration to run either console version or the GUI version of the assembly. For example, for the GUI version, the following run configuration will be applicable:
|newuniverse 01/31/12 03:10:00 AM EST|
The Internet of Everything (IoE) brings together people, process, data and things to make networked connections more relevant and valuable than ever before – transforming information into knowledge and knowledge into wisdom. IoE creates new capabilities, richer experiences, and unprecedented opportunities to improve business and government operations, decision making and mission support capabilities.
Jul. 29, 2015 03:15 PM EDT Reads: 237
The Internet of Things is not only adding billions of sensors and billions of terabytes to the Internet. It is also forcing a fundamental change in the way we envision Information Technology. For the first time, more data is being created by devices at the edge of the Internet rather than from centralized systems. What does this mean for today's IT professional? In this Power Panel at @ThingsExpo, moderated by Conference Chair Roger Strukhoff, panelists addressed this very serious issue of profound change in the industry.
Jul. 29, 2015 03:00 PM EDT Reads: 1,256
Discussions about cloud computing are evolving into discussions about enterprise IT in general. As enterprises increasingly migrate toward their own unique clouds, new issues such as the use of containers and microservices emerge to keep things interesting. In this Power Panel at 16th Cloud Expo, moderated by Conference Chair Roger Strukhoff, panelists addressed the state of cloud computing today, and what enterprise IT professionals need to know about how the latest topics and trends affect their organization.
Jul. 29, 2015 02:00 PM EDT Reads: 1,169
SYS-CON Events announced today that HPM Networks will exhibit at the 17th International Cloud Expo®, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. For 20 years, HPM Networks has been integrating technology solutions that solve complex business challenges. HPM Networks has designed solutions for both SMB and enterprise customers throughout the San Francisco Bay Area.
Jul. 29, 2015 01:45 PM EDT Reads: 422
For IoT to grow as quickly as analyst firms’ project, a lot is going to fall on developers to quickly bring applications to market. But the lack of a standard development platform threatens to slow growth and make application development more time consuming and costly, much like we’ve seen in the mobile space. In his session at @ThingsExpo, Mike Weiner, Product Manager of the Omega DevCloud with KORE Telematics Inc., discussed the evolving requirements for developers as IoT matures and conducted a live demonstration of how quickly application development can happen when the need to comply wit...
Jul. 29, 2015 07:30 AM EDT Reads: 278
Explosive growth in connected devices. Enormous amounts of data for collection and analysis. Critical use of data for split-second decision making and actionable information. All three are factors in making the Internet of Things a reality. Yet, any one factor would have an IT organization pondering its infrastructure strategy. How should your organization enhance its IT framework to enable an Internet of Things implementation? In his session at @ThingsExpo, James Kirkland, Red Hat's Chief Architect for the Internet of Things and Intelligent Systems, described how to revolutionize your archit...
Jul. 28, 2015 06:30 PM EDT Reads: 1,377
It is one thing to build single industrial IoT applications, but what will it take to build the Smart Cities and truly society-changing applications of the future? The technology won’t be the problem, it will be the number of parties that need to work together and be aligned in their motivation to succeed. In his session at @ThingsExpo, Jason Mondanaro, Director, Product Management at Metanga, discussed how you can plan to cooperate, partner, and form lasting all-star teams to change the world and it starts with business models and monetization strategies.
Jul. 28, 2015 04:30 PM EDT Reads: 1,755
Converging digital disruptions is creating a major sea change - Cisco calls this the Internet of Everything (IoE). IoE is the network connection of People, Process, Data and Things, fueled by Cloud, Mobile, Social, Analytics and Security, and it represents a $19Trillion value-at-stake over the next 10 years. In her keynote at @ThingsExpo, Manjula Talreja, VP of Cisco Consulting Services, discussed IoE and the enormous opportunities it provides to public and private firms alike. She will share what businesses must do to thrive in the IoE economy, citing examples from several industry sectors.
Jul. 28, 2015 11:00 AM EDT Reads: 2,036
Growth hacking is common for startups to make unheard-of progress in building their business. Career Hacks can help Geek Girls and those who support them (yes, that's you too, Dad!) to excel in this typically male-dominated world. Get ready to learn the facts: Is there a bias against women in the tech / developer communities? Why are women 50% of the workforce, but hold only 24% of the STEM or IT positions? Some beginnings of what to do about it! In her Opening Keynote at 16th Cloud Expo, Sandy Carter, IBM General Manager Cloud Ecosystem and Developers, and a Social Business Evangelist, d...
Jul. 27, 2015 09:00 PM EDT Reads: 2,040
There will be 150 billion connected devices by 2020. New digital businesses have already disrupted value chains across every industry. APIs are at the center of the digital business. You need to understand what assets you have that can be exposed digitally, what their digital value chain is, and how to create an effective business model around that value chain to compete in this economy. No enterprise can be complacent and not engage in the digital economy. Learn how to be the disruptor and not the disruptee.
Jul. 27, 2015 10:00 AM EDT Reads: 2,022
Akana has released Envision, an enhanced API analytics platform that helps enterprises mine critical insights across their digital eco-systems, understand their customers and partners and offer value-added personalized services. “In today’s digital economy, data-driven insights are proving to be a key differentiator for businesses. Understanding the data that is being tunneled through their APIs and how it can be used to optimize their business and operations is of paramount importance,” said Alistair Farquharson, CTO of Akana.
Jul. 27, 2015 09:00 AM EDT Reads: 312
Business as usual for IT is evolving into a "Make or Buy" decision on a service-by-service conversation with input from the LOBs. How does your organization move forward with cloud? In his general session at 16th Cloud Expo, Paul Maravei, Regional Sales Manager, Hybrid Cloud and Managed Services at Cisco, discusses how Cisco and its partners offer a market-leading portfolio and ecosystem of cloud infrastructure and application services that allow you to uniquely and securely combine cloud business applications and services across multiple cloud delivery models.
Jul. 27, 2015 08:00 AM EDT Reads: 1,895
The enterprise market will drive IoT device adoption over the next five years. In his session at @ThingsExpo, John Greenough, an analyst at BI Intelligence, division of Business Insider, analyzed how companies will adopt IoT products and the associated cost of adopting those products. John Greenough is the lead analyst covering the Internet of Things for BI Intelligence- Business Insider’s paid research service. Numerous IoT companies have cited his analysis of the IoT. Prior to joining BI Intelligence, he worked analyzing bank technology for Corporate Insight and The Clearing House Payment...
Jul. 26, 2015 09:00 PM EDT Reads: 1,560
In his keynote at 16th Cloud Expo, Rodney Rogers, CEO of Virtustream, discussed the evolution of the company from inception to its recent acquisition by EMC – including personal insights, lessons learned (and some WTF moments) along the way. Learn how Virtustream’s unique approach of combining the economics and elasticity of the consumer cloud model with proper performance, application automation and security into a platform became a breakout success with enterprise customers and a natural fit for the EMC Federation.
Jul. 26, 2015 08:00 AM EDT Reads: 2,142
"Optimal Design is a technology integration and product development firm that specializes in connecting devices to the cloud," stated Joe Wascow, Co-Founder & CMO of Optimal Design, in this SYS-CON.tv interview at @ThingsExpo, held June 9-11, 2015, at the Javits Center in New York City.
Jul. 25, 2015 02:00 PM EDT Reads: 380
SYS-CON Events announced today that CommVault has been named “Bronze Sponsor” of SYS-CON's 17th International Cloud Expo®, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. A singular vision – a belief in a better way to address current and future data management needs – guides CommVault in the development of Singular Information Management® solutions for high-performance data protection, universal availability and simplified management of data on complex storage networks. CommVault's exclusive single-platform architecture gives companies unp...
Jul. 25, 2015 01:00 PM EDT Reads: 1,947
Electric Cloud and Arynga have announced a product integration partnership that will bring Continuous Delivery solutions to the automotive Internet-of-Things (IoT) market. The joint solution will help automotive manufacturers, OEMs and system integrators adopt DevOps automation and Continuous Delivery practices that reduce software build and release cycle times within the complex and specific parameters of embedded and IoT software systems.
Jul. 25, 2015 12:15 PM EDT Reads: 446
"ciqada is a combined platform of hardware modules and server products that lets people take their existing devices or new devices and lets them be accessible over the Internet for their users," noted Geoff Engelstein of ciqada, a division of Mars International, in this SYS-CON.tv interview at @ThingsExpo, held June 9-11, 2015, at the Javits Center in New York City.
Jul. 25, 2015 12:00 PM EDT Reads: 1,523
Internet of Things is moving from being a hype to a reality. Experts estimate that internet connected cars will grow to 152 million, while over 100 million internet connected wireless light bulbs and lamps will be operational by 2020. These and many other intriguing statistics highlight the importance of Internet powered devices and how market penetration is going to multiply many times over in the next few years.
Jul. 25, 2015 09:00 AM EDT Reads: 1,481
SYS-CON Events announced today that Dyn, the worldwide leader in Internet Performance, will exhibit at SYS-CON's 17th International Cloud Expo®, which will take place on November 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. Dyn is a cloud-based Internet Performance company. Dyn helps companies monitor, control, and optimize online infrastructure for an exceptional end-user experience. Through a world-class network and unrivaled, objective intelligence into Internet conditions, Dyn ensures traffic gets delivered faster, safer, and more reliably than ever.
Jul. 24, 2015 11:00 PM EDT Reads: 2,050