|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 Things (IoT) is about the digitization of physical assets including sensors, devices, machines, gateways, and the network. It creates possibilities for significant value creation and new revenue generating business models via data democratization and ubiquitous analytics across IoT networks. The explosion of data in all forms in IoT requires a more robust and broader lens in order to enable smarter timely actions and better outcomes. Business operations become the key driver of IoT applications and projects. Business operations, IT, and data scientists need advanced analytics t...
Aug. 28, 2015 12:30 AM EDT Reads: 324
With the proliferation of connected devices underpinning new Internet of Things systems, Brandon Schulz, Director of Luxoft IoT – Retail, will be looking at the transformation of the retail customer experience in brick and mortar stores in his session at @ThingsExpo. Questions he will address include: Will beacons drop to the wayside like QR codes, or be a proximity-based profit driver? How will the customer experience change in stores of all types when everything can be instrumented and analyzed? As an area of investment, how might a retail company move towards an innovation methodolo...
Aug. 27, 2015 06:15 PM EDT Reads: 379
As more and more data is generated from a variety of connected devices, the need to get insights from this data and predict future behavior and trends is increasingly essential for businesses. Real-time stream processing is needed in a variety of different industries such as Manufacturing, Oil and Gas, Automobile, Finance, Online Retail, Smart Grids, and Healthcare. Azure Stream Analytics is a fully managed distributed stream computation service that provides low latency, scalable processing of streaming data in the cloud with an enterprise grade SLA. It features built-in integration with Azur...
Aug. 27, 2015 05:45 PM EDT
WebRTC has had a real tough three or four years, and so have those working with it. Only a few short years ago, the development world were excited about WebRTC and proclaiming how awesome it was. You might have played with the technology a couple of years ago, only to find the extra infrastructure requirements were painful to implement and poorly documented. This probably left a bitter taste in your mouth, especially when things went wrong.
Aug. 27, 2015 02:45 PM EDT Reads: 377
As more intelligent IoT applications shift into gear, they’re merging into the ever-increasing traffic flow of the Internet. It won’t be long before we experience bottlenecks, as IoT traffic peaks during rush hours. Organizations that are unprepared will find themselves by the side of the road unable to cross back into the fast lane. As billions of new devices begin to communicate and exchange data – will your infrastructure be scalable enough to handle this new interconnected world?
Aug. 27, 2015 02:15 PM EDT
SYS-CON Events announced today that IceWarp 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. IceWarp, the leader of cloud and on-premise messaging, delivers secured email, chat, documents, conferencing and collaboration to today's mobile workforce, all in one unified interface
Aug. 27, 2015 02:00 PM EDT Reads: 323
Too often with compelling new technologies market participants become overly enamored with that attractiveness of the technology and neglect underlying business drivers. This tendency, what some call the “newest shiny object syndrome,” is understandable given that virtually all of us are heavily engaged in technology. But it is also mistaken. Without concrete business cases driving its deployment, IoT, like many other technologies before it, will fade into obscurity.
Aug. 27, 2015 01:00 PM EDT Reads: 283
Consumer IoT applications provide data about the user that just doesn’t exist in traditional PC or mobile web applications. This rich data, or “context,” enables the highly personalized consumer experiences that characterize many consumer IoT apps. This same data is also providing brands with unprecedented insight into how their connected products are being used, while, at the same time, powering highly targeted engagement and marketing opportunities. In his session at @ThingsExpo, Nathan Treloar, President and COO of Bebaio, will explore examples of brands transforming their businesses by t...
Aug. 27, 2015 11:30 AM EDT
SYS-CON Events announced today that Micron Technology, Inc., a global leader in advanced semiconductor systems, 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. Micron’s broad portfolio of high-performance memory technologies – including DRAM, NAND and NOR Flash – is the basis for solid state drives, modules, multichip packages and other system solutions. Backed by more than 35 years of technology leadership, Micron's memory solutions enable the world's most innovative computing, consumer,...
Aug. 27, 2015 10:00 AM EDT Reads: 121
Through WebRTC, audio and video communications are being embedded more easily than ever into applications, helping carriers, enterprises and independent software vendors deliver greater functionality to their end users. With today’s business world increasingly focused on outcomes, users’ growing calls for ease of use, and businesses craving smarter, tighter integration, what’s the next step in delivering a richer, more immersive experience? That richer, more fully integrated experience comes about through a Communications Platform as a Service which allows for messaging, screen sharing, video...
Aug. 27, 2015 06:15 AM EDT Reads: 512
SYS-CON Events announced today that Pythian, a global IT services company specializing in helping companies leverage disruptive technologies to optimize revenue-generating systems, has been named “Bronze Sponsor” of SYS-CON's 17th Cloud Expo, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. Founded in 1997, Pythian is a global IT services company that helps companies compete by adopting disruptive technologies such as cloud, Big Data, advanced analytics, and DevOps to advance innovation and increase agility. Specializing in designing, imple...
Aug. 26, 2015 08:00 AM EDT Reads: 157
Akana has announced the availability of the new Akana Healthcare Solution. The API-driven solution helps healthcare organizations accelerate their transition to being secure, digitally interoperable businesses. It leverages the Health Level Seven International Fast Healthcare Interoperability Resources (HL7 FHIR) standard to enable broader business use of medical data. Akana developed the Healthcare Solution in response to healthcare businesses that want to increase electronic, multi-device access to health records while reducing operating costs and complying with government regulations.
Aug. 26, 2015 07:00 AM EDT
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.
Aug. 3, 2015 06:45 PM EDT Reads: 776
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...
Aug. 2, 2015 11:15 AM EDT Reads: 538
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.
Aug. 1, 2015 10:00 AM EDT Reads: 468
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. 30, 2015 07:30 PM EDT Reads: 1,556
MuleSoft has announced the findings of its 2015 Connectivity Benchmark Report on the adoption and business impact of APIs. The findings suggest traditional businesses are quickly evolving into "composable enterprises" built out of hundreds of connected software services, applications and devices. Most are embracing the Internet of Things (IoT) and microservices technologies like Docker. A majority are integrating wearables, like smart watches, and more than half plan to generate revenue with APIs within the next year.
Jul. 30, 2015 02:30 PM EDT Reads: 268
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. 30, 2015 12:00 PM EDT Reads: 2,215
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. 30, 2015 09:00 AM EDT Reads: 2,306
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,437