|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|
Microservices are a very exciting architectural approach that many organizations are looking to as a way to accelerate innovation. Microservices promise to allow teams to move away from monolithic "ball of mud" systems, but the reality is that, in the vast majority of organizations, different projects and technologies will continue to be developed at different speeds. How to handle the dependencies between these disparate systems with different iteration cycles? Consider the "canoncial problem" in this scenario: microservice A (releases daily) depends on a couple of additions to backend B (re...
Nov. 29, 2015 05:00 AM EST Reads: 456
The Internet of Things is clearly many things: data collection and analytics, wearables, Smart Grids and Smart Cities, the Industrial Internet, and more. Cool platforms like Arduino, Raspberry Pi, Intel's Galileo and Edison, and a diverse world of sensors are making the IoT a great toy box for developers in all these areas. In this Power Panel at @ThingsExpo, moderated by Conference Chair Roger Strukhoff, panelists discussed what things are the most important, which will have the most profound effect on the world, and what should we expect to see over the next couple of years.
Nov. 29, 2015 04:30 AM EST Reads: 482
Container technology is shaping the future of DevOps and it’s also changing the way organizations think about application development. With the rise of mobile applications in the enterprise, businesses are abandoning year-long development cycles and embracing technologies that enable rapid development and continuous deployment of apps. In his session at DevOps Summit, Kurt Collins, Developer Evangelist at Built.io, examined how Docker has evolved into a highly effective tool for application delivery by allowing increasingly popular Mobile Backend-as-a-Service (mBaaS) platforms to quickly crea...
Nov. 29, 2015 04:00 AM EST Reads: 372
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 Day 2 Keynote at 17th Cloud Expo, Sandy Carter, IBM General Manager Cloud Ecosystem and Developers, and a Social Business Evangelist, wil...
Nov. 29, 2015 03:00 AM EST Reads: 589
PubNub has announced the release of BLOCKS, a set of customizable microservices that give developers a simple way to add code and deploy features for realtime apps.PubNub BLOCKS executes business logic directly on the data streaming through PubNub’s network without splitting it off to an intermediary server controlled by the customer. This revolutionary approach streamlines app development, reduces endpoint-to-endpoint latency, and allows apps to better leverage the enormous scalability of PubNub’s Data Stream Network.
Nov. 29, 2015 03:00 AM EST Reads: 336
Apps and devices shouldn't stop working when there's limited or no network connectivity. Learn how to bring data stored in a cloud database to the edge of the network (and back again) whenever an Internet connection is available. In his session at 17th Cloud Expo, Ben Perlmutter, a Sales Engineer with IBM Cloudant, demonstrated techniques for replicating cloud databases with devices in order to build offline-first mobile or Internet of Things (IoT) apps that can provide a better, faster user experience, both offline and online. The focus of this talk was on IBM Cloudant, Apache CouchDB, and ...
Nov. 29, 2015 02:45 AM EST Reads: 418
I recently attended and was a speaker at the 4th International Internet of @ThingsExpo at the Santa Clara Convention Center. I also had the opportunity to attend this event last year and I wrote a blog from that show talking about how the “Enterprise Impact of IoT” was a key theme of last year’s show. I was curious to see if the same theme would still resonate 365 days later and what, if any, changes I would see in the content presented.
Nov. 29, 2015 01:00 AM EST Reads: 434
Cloud computing delivers on-demand resources that provide businesses with flexibility and cost-savings. The challenge in moving workloads to the cloud has been the cost and complexity of ensuring the initial and ongoing security and regulatory (PCI, HIPAA, FFIEC) compliance across private and public clouds. Manual security compliance is slow, prone to human error, and represents over 50% of the cost of managing cloud applications. Determining how to automate cloud security compliance is critical to maintaining positive ROI. Raxak Protect is an automated security compliance SaaS platform and ma...
Nov. 28, 2015 08:00 PM EST Reads: 431
The Internet of Things (IoT) is growing rapidly by extending current technologies, products and networks. By 2020, Cisco estimates there will be 50 billion connected devices. Gartner has forecast revenues of over $300 billion, just to IoT suppliers. Now is the time to figure out how you’ll make money – not just create innovative products. With hundreds of new products and companies jumping into the IoT fray every month, there’s no shortage of innovation. Despite this, McKinsey/VisionMobile data shows "less than 10 percent of IoT developers are making enough to support a reasonably sized team....
Nov. 28, 2015 01:00 PM EST Reads: 479
Just over a week ago I received a long and loud sustained applause for a presentation I delivered at this year’s Cloud Expo in Santa Clara. I was extremely pleased with the turnout and had some very good conversations with many of the attendees. Over the next few days I had many more meaningful conversations and was not only happy with the results but also learned a few new things. Here is everything I learned in those three days distilled into three short points.
Nov. 28, 2015 12:00 PM EST Reads: 341
With major technology companies and startups seriously embracing IoT strategies, now is the perfect time to attend @ThingsExpo 2016 in New York and Silicon Valley. Learn what is going on, contribute to the discussions, and ensure that your enterprise is as "IoT-Ready" as it can be! Internet of @ThingsExpo, taking place Nov 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 17th Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The Internet of Things (IoT) is the most profound cha...
Nov. 28, 2015 12:00 PM EST Reads: 554
DevOps is about increasing efficiency, but nothing is more inefficient than building the same application twice. However, this is a routine occurrence with enterprise applications that need both a rich desktop web interface and strong mobile support. With recent technological advances from Isomorphic Software and others, rich desktop and tuned mobile experiences can now be created with a single codebase – without compromising functionality, performance or usability. In his session at DevOps Summit, Charles Kendrick, CTO and Chief Architect at Isomorphic Software, demonstrated examples of com...
Nov. 28, 2015 11:45 AM EST Reads: 408
As organizations realize the scope of the Internet of Things, gaining key insights from Big Data, through the use of advanced analytics, becomes crucial. However, IoT also creates the need for petabyte scale storage of data from millions of devices. A new type of Storage is required which seamlessly integrates robust data analytics with massive scale. These storage systems will act as “smart systems” provide in-place analytics that speed discovery and enable businesses to quickly derive meaningful and actionable insights. In his session at @ThingsExpo, Paul Turner, Chief Marketing Officer at...
Nov. 28, 2015 11:15 AM EST Reads: 417
In his keynote at @ThingsExpo, Chris Matthieu, Director of IoT Engineering at Citrix and co-founder and CTO of Octoblu, focused on building an IoT platform and company. He provided a behind-the-scenes look at Octoblu’s platform, business, and pivots along the way (including the Citrix acquisition of Octoblu).
Nov. 28, 2015 11:00 AM EST Reads: 517
In his General Session at 17th Cloud Expo, Bruce Swann, Senior Product Marketing Manager for Adobe Campaign, explored the key ingredients of cross-channel marketing in a digital world. Learn how the Adobe Marketing Cloud can help marketers embrace opportunities for personalized, relevant and real-time customer engagement across offline (direct mail, point of sale, call center) and digital (email, website, SMS, mobile apps, social networks, connected objects).
Nov. 28, 2015 10:30 AM EST Reads: 316
We all know that data growth is exploding and storage budgets are shrinking. Instead of showing you charts on about how much data there is, in his General Session at 17th Cloud Expo, Scott Cleland, Senior Director of Product Marketing at HGST, showed how to capture all of your data in one place. After you have your data under control, you can then analyze it in one place, saving time and resources.
Nov. 28, 2015 10:00 AM EST Reads: 199
The Internet of Everything is re-shaping technology trends–moving away from “request/response” architecture to an “always-on” Streaming Web where data is in constant motion and secure, reliable communication is an absolute necessity. As more and more THINGS go online, the challenges that developers will need to address will only increase exponentially. In his session at @ThingsExpo, Todd Greene, Founder & CEO of PubNub, exploreed the current state of IoT connectivity and review key trends and technology requirements that will drive the Internet of Things from hype to reality.
Nov. 28, 2015 08:45 AM EST Reads: 442
Two weeks ago (November 3-5), I attended the Cloud Expo Silicon Valley as a speaker, where I presented on the security and privacy due diligence requirements for cloud solutions. Cloud security is a topical issue for every CIO, CISO, and technology buyer. Decision-makers are always looking for insights on how to mitigate the security risks of implementing and using cloud solutions. Based on the presentation topics covered at the conference, as well as the general discussions heard between sessions, I wanted to share some of my observations on emerging trends. As cyber security serves as a fou...
Nov. 28, 2015 08:45 AM EST Reads: 332
With all the incredible momentum behind the Internet of Things (IoT) industry, it is easy to forget that not a single CEO wakes up and wonders if “my IoT is broken.” What they wonder is if they are making the right decisions to do all they can to increase revenue, decrease costs, and improve customer experience – effectively the same challenges they have always had in growing their business. The exciting thing about the IoT industry is now these decisions can be better, faster, and smarter. Now all corporate assets – people, objects, and spaces – can share information about themselves and thei...
Nov. 28, 2015 06:00 AM EST Reads: 255
Continuous processes around the development and deployment of applications are both impacted by -- and a benefit to -- the Internet of Things trend. To help better understand the relationship between DevOps and a plethora of new end-devices and data please welcome Gary Gruver, consultant, author and a former IT executive who has led many large-scale IT transformation projects, and John Jeremiah, Technology Evangelist at Hewlett Packard Enterprise (HPE), on Twitter at @j_jeremiah. The discussion is moderated by me, Dana Gardner, Principal Analyst at Interarbor Solutions.
Nov. 28, 2015 05:30 AM EST Reads: 736