OSGI (Dynamic model system for Java)

Source: Internet
Author: User
Tags abstract definition

OSGI (Dynamic model system for Java)
The OSGi (Open Service Gateway Initiative) technology is a dynamic model system for Java. The OSGi service platform provides services to Java, which makes Java a preferred environment for software integration and software development. Java provides portability for products that are supported on multiple platforms. OSGi technology provides standardized primitives that allow applications to be built using refined, reusable, and collaborative components. These components can be assembled into an application and deployment.Chinese Name:Open Service Gateway ProtocolForeign Name:Open Service Gateway InitiativeApplication ObjectJava Dynamic Model SystemcategoryGateway Protocol Directory

1 background

2 Security protocols

3 Frame Structure

4 Standard Service

5 Framework Services

6 System Services

7Hello World

? 3 Summary

8 Books

1 Background
The OSGi service platform provides the ability to dynamically change constructs on multiple network devices without rebooting. To minimize coupling and to enable these coupling degrees to be manageable, OSGi technology provides a service-oriented architecture that enables these components to dynamically discover each other. OSGi UnitedOSGIThe alliance has developed many common functional standard component interfaces such as HTTP server, configuration, log, security, user Management, XML, and so on. The compatibility plug-in implementations of these components can be obtained from different computer service providers that have different optimizations and usage costs. However, the service interface can be developed on the basis of exclusive rights. Because OSGi technology provides pre-built and predictive component subsystems for integration, OSGi technology allows you to benefit from improved time-to-market and lower development costs. Because these components can be dynamically released to the device, OSGi technology also lowers maintenance costs and has a unique new accessory market opportunity. [1]2 security protocols
The security mechanism is based on the Java and JAVA2 security model. The design of the Java language limits many structures. For example, a cache overflow that is often encountered in a virus is unlikely to occur. The access control in the Java language restricts code visibility. The OSGi platform extends the model by using a private class (a mechanism that cannot be used in the standard way in Java). The JAVA2 security model provides a complete module that examines the accessibility of code to resources. OSGi adds full dynamic rights management, simplifying the work of operators and system administrators. The OSGi federation has defined a number of protocol services that map external protocols to OSGi services. HTTP Service (Httpservice) The HTTP service is the servlet runner. Bundles provides servlets, these server-side applet-based HTTP protocols become available. The dynamic Update feature of the OSGi Service platform makes the HTTP service a very attractive Web server that can be updated with the new servlet and can be updated remotely without restarting if needed. UPnP Service (Upnpservice) Universal Plug and Play (UPnP) is an emerging consumer electronics standard. The UPnP service in OSGi maps a device to a service registration on a UPnP network. Similarly, it can map an OSGi service to a UPnP network. This is the recommended specification in Release version 3. The DMT Management (dmtadmin) Open Mobility Alliance (OMA) provides a complete set of mobile device management based on the device management tree. The DMT Management service defines how the tree is accessed and/or expanded in the OSGi service platform.3 Frame structure
The core component of the OSGi specification is the OSGi framework. This framework provides a standard environment for applications that are called components (bundles). The entire framework can be divided into several levels:OSGIL0: Operating Environment L1: module L2: Lifecycle Management L3: Service registration [1] There is also a ubiquitous security system that penetrates all layers. The L0 layer execution environment is a specification for the Java environment. JAVA2 Configuration and sub-specifications, such as J2SE,CDC,CLDC,MIDP and so on, are effective execution environments. The OSGi platform has standardized an execution environment, which is a small variant based on the base profile and the minimum requirements identified in an execution environment, which is useful for OSGi components. The L1 module layer defines the load policy for the class. The OSGi framework is a powerful, tightly defined class loading model. It's based on Java, but it adds modularity. In Java, there is normally a classpath that contains all classes and resources. The OSGi module layer adds a private class to a module and has a controllable inter-module link. The module layer is fully integrated with the security architecture and can be deployed to a fully user-managed system that deploys closed systems, defenses, or vendor decisions. The L2 lifecycle layer adds bundles that can be dynamically installed, opened, closed, updated, and uninstalled. These bundles depend on the module layer with class loading, but add APIs to manage these modules at run time. The life cycle layer introduces the dynamics that normally do not belong to an application. The extended dependency mechanism is used to ensure that the environment is operating correctly. Life cycle operations are protected against viruses by the security architecture. The L3 layer adds service registration. Service registration provides a bundles-oriented, dynamic collaboration model. Bundles can collaborate through traditional class sharing, but class sharing is incompatible with dynamic installation and uninstallation code. Service registration provides a complete model for sharing objects between bundles. A large number of events are defined to handle the registration and deletion of services. These services are just Java objects that can represent anything. Many services are similar to server objects, such as HTTP servers, while others represent a real-world object, such as a nearby Bluetooth phone. This service module provides a complete security guarantee. The Service security module uses a clever way to secure communication between bundles.4 Standard Service
On top of that framework, the OSGi Alliance defines a number of services. These services are specified through a Java interface. Bundles can actuallyOSGIThis interface, and register the service at the registration service level. The client of the service finds it in the registry, or responds when it appears or disappears. This is similar to how the SOA architecture uses Web services for publishing. The main difference is that Web services always require a transport layer, which makes it thousands of times times slower than OSGi services with direct method invocation. At the same time, OSGi components can respond to the presence and disappearance of these services. More information can be found in the OSGi Service platform release version 4 manual or pdf download. It is important to note that each service is an abstract definition, independent of the implementation of different computer service providers.5 Framework Services
The OSGi framework provides a rights management service, a package management service, and a start-level service. These services are available as aOSGISelect to indicate the operation of the frame. The framework service is as follows: Rights Management (Permissionadmin) current or future bundles permissions are maintained through this service. Once they are set, the rights service is activated immediately. Package management (Packageadmin) bundles similar and resource sharing packages. Updates to bundles may require the system to recalculate these dependencies. This package management service provides information about the actual package sharing status of the system and the ability to refresh the packages that have been shared. That is, cancel dependencies and recalculate dependencies. The start level (startlevel) boot level is a bundles collection that should run at the same time or should be initialized before others have started. The start level service sets the current startup level, a start level for each bundle, and the auditing of the current settings. The URL processor (urlhandler) Java environment supports a provider model for URL handlers. However, this is a single piece that cannot be used in a collaborative environment like OSGi that may have many providers. This service specification enables any component to provide additional URL handlers.6 System Services
System services provide the level of functionality that is required in each system. Log service, configuration Management Service, device accessOSGIServices, user Management Services, IO Connector services, and parameter services are all part of the system's services. Log service (Logservice) log information, warning, debugging, or error messages are handled through the log service. It accepts log entities and assigns these entities to other bundles that subscribe to this information. Configuration Management Service (Configurationadminservice) The service provides a flexible, dynamic model for setting up and getting configuration information. Device Access Service (Deviceaccessservice) device access is a mechanism by which OSGi matches a driver for a new device and automatically downloads a bundles that implements that drive. This can be used as a Plug and Play scenario. User Management Service (useradminservice) the service uses a database of user information for authorization and authentication purposes. IO Connector Service (ioconnectorservice) The IO Connector Service implements the Cdc/cldcjavax package and serves as a service. The service allows bundles to provide a new mode of exchangeable protocols. Parameter Service (PREFERENCESSERVICE) This service provides the accessibility of a parameter-level database similar to the Windows registry or Java parameter classes. The dynamic nature of Component Runtime Service (COMPONENTRUNTIME) services--they can go free at any time--makes it harder to write software. The build runtime specification simplifies handling these dynamic aspects by providing an XML file that is based on a dependency declaration. The primary deployment format for Deployment Management Services (Deploymentadmin) OSGi is bundle, which is a jar/zip file. Deployment Management provides a second alternative format: deployment packages. The deployment package is capable of joining bundles and corresponding resources into a single delivery that can be installed and unloaded. The complete resource processor model allows user code to augment the resource type. Event Management Service (Eventadmin) Many OSGi events have specific typed interfaces that make it difficult to receive and filter events. The Event Service provides a generalized topic-based event mechanism. This specification includes mappings for all existing frameworks and service events. The Application Management Service (APPLICATIONADMIN) Osgibundle model differs from a typical desktop or mobile phone application model that relies on startup and shutdown forms. The Application Management Service provides the traditional application model and the management facilities it requires.7Hello World
0. PrefaceThis document describes how to use an implementation--equinox of the OSGi framework to teach you how to configure a simple OSGi development environment and to develop a HelloWorld program in this environment that covers the three levels of content in the previous introductory article, Let you consolidate what you know before you practice. Say no more, let's begin! [2] Development Environment EstablishmentWhat is 1.1 Equinox? From a code perspective, Equinox is actually the complete implementation of the OSGi core standard, and adds some additional functionality on top of it (such as adding a command line to the framework and a program execution entry). All of the things we've explained in our previous introductory article are actually a small part of the OSGi core standard. In fact, its core is a jar package, which can be executed (as a standard Java package) and a bundle (manifest contains an OSGi bundle of meta data). Now all you need to know is that we can use the code of the Equinox project to run a real OSGi framework, and after the framework is launched, you can put the bundle you have developed to run inside. 1.2 Downloads Equinoxequinox is available on the Eclipse website, which lists the various versions for our selection: Here we use the 3.7 version of Equinox, downloaded and placed in a separate folder (here my path is E:\OSGi Framework\equinox) 1.3 Starting the framework from the command line if you start the framework, it will suffice to have the jar package above, and we enter the command line as follows: Java–jar org.eclipse.osgi_3.7.0. V20110613.jar-console will then enter the Equinox console: If a osgi> prompt appears, the boot succeeds. Some basic commands for the Equinox console are as follows (case-sensitive):
Install [URL] Install the bundle represented by the URL into the framework
Uninstall [Bundleid] Unload Id=bundleid Bundle
Start [Bundleid] Start a bundle
Stop [Bundleid] Stop a bundle
Refresh [Bundleid] Refresh Bundle
Update [Bundleid] Update the content of bundles
Ss Simple display of the status of all bundles
Status Show installed bundles and registered services
headers [Bundleid] Displaying metadata in bundles ' manifest
1.4 Eclipse setting up the environment in the previous section, you can see the way to start and control the framework, which is quite a simple process. But just because the environment is running is not enough, we need a development environment. 1.4.1 Settings First we don't need to install the necessary plugins, as long as you have a newer version of Eclipse on the line. Then go to Eclipse's window->preferences interface, select target platform under plug-in development and now there is only one runing platform on the right, our task is to click "Add ..." button to add a platform of our own, enter the following interface: Select the default first one, and click Next. Click "Add ..." here: Select "Directory": Select the path of your Equinox jar package, then click Finish to go back to the interface: this time you will find that there is more out of the path you just set, the path described in the "1 plug-ins Available "is what we put in the Equinox jar package. Continue clicking Finish, back to the beginning of the interface this time more out a new target platform, tick on, and then OK.  [2] 1.4.2 Start Open menu item Run->run configurations ..., in the OSGi framework item, Create a new runconfiguration: This is now automatically included in the Equinox Jar, click Run to see the effect: The Eclipse console also appears with an OSGi prompt indicating that you have successfully started. You can try the commands you just talked about and see what you can output (for example, I typed SS).  [2] 1.4.3 Create a new project to open the interface for new project, select Plug-in Project: Then enter project's name, select an OSGi at TargetPlatform Framework->equinox or standard line, click Next: Here is actually the bundle of manifest file settings, where the ID is bundle-symbolicname, Version is the bundle's release number, the following can decide whether to define Bundleactivator, click Finish to create a project to this point, the development environment has been established (this project just to demonstrate how to build, Will not be used in the next content, can be deleted). &nbsP [2] 2 HelloWorld code is now everything, only owes HelloWorld. To cover the three levels of the OSGi framework, this HelloWorld may be a little more complicated than the other OSGi HelloWorld programs you see. If you're unfamiliar with some of the APIs in your code, remember to go back to the previous introductory article to find the corresponding content, which will help you understand the code. The key code inside is already highlighted in yellow. (For space reasons, the import statements in the Code are omitted) 2.1 Definition and implementation of HelloWorld first we create an engineering org.serc.helloworld, in which we create an interface that contains the SayHello method, ready to serve as a service interface: the package Org.serc.helloworld;public interface Hello {void SayHello ();} Then, implement this interface: Package Org.serc.helloworld.impl;public class Helloimpl implements Hello{final String Hellostring;public Helloimpl (String hellostring) {this.hellostring= hellostring;} public void SayHello () {System.out.println (this.hellostring);}} The SayHello of this class implementation is to output a hellostring string that is obtained when the object is constructed. In order to expose this interface, we need to include the following entry in the manifest file: export-package:org.serc.helloworld;version= "1.0" next, in order to register the service in the framework, We have defined a Activator:package Org.serc.helloworld.activator;public class Activator implements Bundleactivator {private List<serviceregistration> registrations = new arraylist<serviceregistration> ();p ublic void Start ( Bundlecontext ctx) {Registrations.add (Ctx.registerservice (Hello.class.getName (), New Helloimpl ("Hello, OSGi"), null)); public void Stop (Bundlecontext ctx) {for (serviceregistration registration:registrations) {System.out.println (" Unregistering: "+ registration); Registration.unregister ();} We passed in the "Hello, OSGi" string for this helloimpl, in order for this Activator to work, it needs to be defined in the manifest file as follows: Bundle-activator:o Rg.serc.helloworld.activator.Activator The final manifest content of this Bundle is as follows: Bundle-manifestversion:2bundle-symbolicname:o Rg.serc.helloworldbundle-version:1.0bundle-activator:org.serc.helloworld.activator.activatorimport-package:o Rg.osgi.frameworkexport-package:org.serc.helloworld;version= "1.0" 2.2 Acquire and execute the SayHello service create a project org.serc.helloworld.client, create a bundleactivator called Hellouser, where the Start method obtains the service object with the interface as Hello, and through this object to invoke Sayh Ello Method: Package Org.serc.helloworld.client;public class Hellouser implements Bundleactivator {public void start ( Bundlecontext ctx) {servicereference ref = Ctx.getservicereference (Hello.class.getName ()); if (ref! = null) {Hello Hello = Null;try{hello= (Hello) ctx.getservice (ref), if (hello! = null) Hello.sayhello (); ElseSystem.out.println ("Service: Hello---objectnull ");} catch (RuntimeException e) {e.printstacktrace ();} finally {Ctx.ungetservice (ref); hello= null;}} else {System.out.println ("Service:hello---notexists");}} public void Stop (Bundlecontext ctx) throws Exception {}} In order to get the definition of Hello this interface, we also need to import in the manifest file Hello, package:bundle-manifestversion:2bundle-symbolicname:org.serc.helloworld.clientbundle-version. : 1.0bundle-activator:org.serc.helloworld.client.hellouserimport-package:org.serc.helloworld;version= "[1.0,2.0) ", the process of the org.osgi.framework2.3 HelloWorld program may be more difficult to see the code than the process of implementation of the program, representing the various functions of these classes of interdependence, the entire relationship starts with the definition of Hello interface And then to the Hello interface is implemented, to get Helloimpl, and then to Activator to register Helloimpl as a service in the framework, and then to hellouser by interacting with the framework to get the service just registered, and using this service to output the string The last optional process is when we stop org.serc.helloworld the bundle, the program will log off the previously registered service. 2.4 Execution of the program through the above work, we got two of our own defined bundle:org.serc.helloworldorg.serc.helloworld.client now open the Run configurations interface, We'll see the bundles tag. These two bundles: in other words, the OSGi frameworkAt startup, the 2 bundles are automatically install and start. 2.5 using the command line to view changes in the state of the framework during the execution of a program 2.4 actually gives only one result, if you are not quite sure how the result is specific, then this section should be able to help you better understand the process of output results. Below we will install and execute the bundle step by Equinox with some command lines, and look at the changes in the state of the framework in the process to let you figure out how the result came from. First cancel the auto-start of the two HelloWorld bundle in the Run configuration: then click Run, and you will not be able to output the Hello, OSGi string immediately, so let's look at the bundle with the "SS" command first. Status: Visible two bundles are not out of active state, the description does not start, now we execute "Start 8" To start Org.serc.helloworld. This bundle is using the Services command to view the currently registered service, we will see a large number of system services to come up with the following one of the services this is obviously we registered after start, but there is no one bundle is using this service 。 Next we start the bundle of 9th, which is the bundle we use to invoke the service, and then output the string "Hello, OSGi." So what happens if we start with bundle 9th without starting the number 8th bundle? You can give it a try because we have already processed the exception that has no service in the code, then we will have the corresponding output. Let's stop number 8th. We can see that the service we have just registered has been written off, and now we execute Refresh 11 (that is, the bundle of number 9th) to re-execute the Start method of the bundleactivator that the Hello Service has ceased to exist. From here we can see, in fact, the boot order of the bundle is also a need to pay attention to the link, sometimes you define the bundle is Order-sensitive, you must have some pre-bundle to start, after the bundle can start correctly.  [2] 3 SummaryThis document is the last chapter in the introductory article, and I hope that the reader will be able to take the time to read these 4 documents and gain some insight into how the OSGi framework works and its advantages. [2]
  
8 Books
deep understanding of OSGi1. "In-depth understanding of Osgi:equinox principles, applications and best Practices" [3] Zhou Zhiming & Xiaixiaoming, Published: 2013-2-1. Description: This book contains 14 chapters, divided into 4 parts. Part One (chapter 1th): Approaching OSGi, mainly describes what OSGi is and why OSGi is used. The second part (the 2nd to 4th Chapter): OSGi specification and principle, to the latest OSGi R5.0 core specifications in a comprehensive interpretation, first of all, the establishment of the OSGi module, description, the processing of dependencies, and then explained the bundle of the starting principle and scheduling management, Finally, the content related to local and remote services is explained. Part III: OSGi Service and Equinox Application Practice (5th to 11th), not only explains the technical details of the most commonly used sub-specifications and services in the OSGi Service outline specification and Enterprise specification, but also demonstrates the use of Equinox through a BBS case based on Equinox. The most important is also through the source code analysis of Equinox key functions of the implementation mechanism and principles. Part IV: Best Practices (Chapter 12th to 14th) summarizes a number of best practices for OSGi, including practical tips on how bundles are named, module partitioning, dependency processing to maintain OSGi dynamics, hypervisor startup sequence, and API baseline Management module versions. It also introduces the principles of spring DM and how to test the program in the OSGi segment. 2. Eclipse rcp and spring OSGi: technical explanations and best practices [4]Eclipse rcp and spring OSGiJiangbei, Published: 2013-1-1. Description: The book is divided into 3 parts: The basic chapter (1th to 5th) details a series of core concepts related to Eclipse RCP, the Eclipse RCP development environment, and SWT, JFace, Forms, Interface programming techniques commonly used in the development of Eclipse RCP, such as Nebula and Windowbuilder, and advanced chapters (6th to 12th) systematically explain the fundamentals of Eclipse RCP application development and how the various components of the Eclipse RCP software PRODUCT are built, As well as the use of Eclipse RCP extensions and the development of extension points, readers who have mastered these technical knowledge will be able to build a fully structured Eclipse RCP software and resolve failures encountered during software development; the actual combat chapter (13th to 15th) details the Eclipse RCP and spring OSGi Framework, Hibernate ORM Framework, JPA specification, MAVEN tools integration, and its modular design with Java. 3.osgi Chinese community [5] Profile: A community of modular, dynamic development technologies maintained by the "Software collaborative research and Development Support Technology" Group of the National Engineering Research Center of Peking University. Beginners, advanced people and Daniel can share their skills and experience, free communication and learning, and enrich themselves in their contributions and harvests.  For more students, researchers and practitioners to provide a broader platform for communication. Resources
  • 1. Dynamic model System OSGi . Open source Community Network [citation date 2012-08-18].

  • 2. OSGI development environment established and Hello World . OSGi Chinese Community [citation date 2013-05-28].

  • 3. Zhou Zhiming, Xiaixiaoming. In-depth understanding of Osgi:equinox principles, applications and best practices. Beijing: Mechanical industry Press, 2013:I-II.

  • 4. Jiangbei. Eclipse RCP and spring OSGi: technical explanations and best practices. Beijing: Mechanical industry Press, 2013:I-II.

  • 5. National Engineering Research Center for Software engineering. PKU unnamed station [citation dated 2013-05-28].

    • OSGi Service Platform, Release 3, IOS Press, ISBN 1-58603-311-5
    • External Links
      • OSGi Chinese community--promoting the spread of Java modular development technology
      • OSGi official website--downloadable standard specifications, providing a variety of information
      • FAQ
      • OSGi World Congress-2004 Congress in October in Barcelona
      • ProSyst software gmbh-leading OSGi software Provider for Remote Management and Service Delivery
      • Aqute:osgi info-information about OSGi and access to seminars
      • Oscar:an OSGi Framework Implementation-open Source OSGi Framework implementation under BSD license
      • Oscar bundle Repository (OBR)-A community-oriented bundle Repository and incubator for OSGi bundle developers
      • Knopflerfish OSGi Open Source OSGi implementation under BSD license
      • Oxygen Project
      • servicebinder-automated Service Dependency Management for the OSGi services platform
      • Dependency manager-automatically Managing service dependencies in OSGi
      • Makewave-leading OSGi Technology Provider, maintains the open source OSGi implementation Knopflerfish

OSGI (Dynamic model system for Java)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.