Tuesday, October 26, 2010

OSGi Bundle of Hello World



This is "Hello, OSGi" series of the second part. OSGi has been introduced prior to what will continue on the following article describes the content, about a simple OSGi Bundle: Hello World are developed.

51CTO Editors: OSGi entry and practice of all captures

Develop a simple Hello World of OSGi Bundle (OSGi binding package)

In OSGi, the software is released in the form of Bundle. A Bundle from the Java classes and other resources of its Bundle for other services, you can also import other Bundle in Java packages; Meanwhile, OSGi's Bundle where the equipment can provide some of its features. Eclipse for the development of OSGiBundle provides excellent support, which not only provides a wizard to create the OSGi Bundle, and also provides embedded Equinox container, you can use the OSGi container implementation and debugging plug-ins. Please note that each Eclipse plug-in essence, is an OSGi Bundle, just add this OSGiBundle some Eclipse-specific code only. Let us look at how to use Eclipse to develop a simple OSGi the HelloWorld Bundle.

3.1. New Bundle

1) In Eclipse, click on "File-> New-> Project" menu, you will see a new project to create dialog boxes;

2) In the New Project dialog box, select the "Plug-inProject (plug-in project)" and click "Next (Next)" button, you will see the plug-in project dialog box;

3) In the plug-in project dialog box, type the following values:

Project Name (Project Name): com.javaworld.sample.HelloWorld

Target Platform (target platform): an OSGiFramework-> Standard (OSGi Framework -> standard)

4) the requirements of other input values using default values and click "Next (Next)" button, you will see the plug-in context of the dialog box;

5) In the plug-in the context of the dialog box, select the default values and click "Next (Next)" button;

6) In the Template dialog box, select the "Hello OSGiBundle (Hello, OSGi package)" template, then click "Finish (complete)" button to complete the project.

Eclipse will take a few seconds Clock Generation HelloWorld Bundle template code, it built two files: Activator.java and MANIFEST.MF, the following, let us look at these two files:

3.1.1. Activator.java file

Source List 1.Activator.java

package com.javaworld.sample.helloworld; importorg.osgi.framework.BundleActivator; importorg.osgi.framework.BundleContext; publicclass Activator implements BundleActivator (public void start (BundleContext context) throws Exception (System.out.println ("Helloworld" );) public void stop (BundleContext context) throws Exception (System.out.println ("GoodbyeWorld");))

If you want your Bundle developed in their own startup or shutdown notice, you should create a new class, make it happen BundleActivator interface, the same time, you also need to comply with the following rules:

This class implements BundleActivator interface must have a public, non-constructor with parameters, so, OSGi framework will call the class of Class.newInstance () method to create this BundleActivator object;

Activator class vessel will call start () method to start the Bundle, therefore, we can start () method to perform initialization of the operation some resources, for example, we can get in the way the database connection, for later use. The start () method the only parameter is a BundleObject object, Bundles can be the object and the OSGi framework for communication, we can get from the object information related to OSGi container; If a Bundle thrown, the container will be the home for the "stopped (stopped)" status, this time, this Bundle can not provide services outside.

If we are to close a Bundle, the container will call the Activator class in the stop () method. Therefore, we can stop () method to perform clean-up tasks some resources, such as the release of the database connection.

Once in place Activator class, you can MANIFEST.MF file to the package to pass the legal name of the container. Here we look at the MANIFEST.MF file.

3.1.2. MANIFEST.MF file

Bundle the file is the deployment descriptor, its format and the normal JAR file in the MANIFEST.MF file in the same package, it consists of a series of attributes and values corresponding to the composition of these attributes, the attribute name in the beginning of each line, we can say its head for the property. OSGi specification, you can use the property description of your head to the container Bundle. Your HelloWorld Bundle of MANIFEST.MF file should look as shown in Listing 2:

Source Code Listing 2. Hello World Bundle in the MANIFEST.MF file

Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: HelloWorld Plug-in Bundle-SymbolicName: com.javaworld.sample.HelloWorld Bundle-Version: 1.0.0 Bundle-Activator: com.javaworld.sample.helloworld.Activator Bundle -Vendor: JAVAWORLD Bundle-Localization: plugin Import-Package: org.osgi.framework; version = "1.3.0"

We take a look at the properties used in this document head:

Bundle-ManifestVersion

The property first told OSGi container, the Bundle will follow the OSGi specification, value of 2 indicates the Bundle and the OSGi specification, version 4 compatible; if the attribute value is 1, then said of the package and the OSGi version 3 or earlier versions.

Bundle-Name

Bundle-based head of the property defines a short, can read the name;

Bundle-SymbolicName

This property defines a head-centered Bundle unique, non-localized name; When you need to access from another a specified Bundles Bundle, you must use the name.

Bundle-Version

The first property gives the version number of this Bundle.

Bundle-Activator

The first gives the property used in this Bundle listener class name, the attribute value is optional. Listeners will Activator in the start () and stop () method of monitoring. In Listing 2, the value of the property first com.javaworld.sample.helloworld.Activator.

Bundle-Vendor

The first property is the expression of the issuers Bundle.

Bundle-Localization

The attribute header contains the localization files in this Bundle location, our HelloWorld Bundle of documents is not localized, but the Eclipse IDE automatically generates the property is still the first

Import-Package

The first attribute defines the Bundle package introduced in Java, I will manage this dependence later sections explain in detail the problem. Now, HelloWorld Bundle is ready, let's run and see its output.

3.2. Run Bundle

I mentioned earlier, Eclipse IDE has a built-in EquinoxOSGi container, you can use it to execute or debug OSGi Bundle. Follow these steps just HelloWorld Bundle:

1) Click Run脿Run ... menu (translators note, in Eclipse3.3, click Run脿Open Run Diglog ... menu);

2) Eclipse will open the "Create, manage and run configuration (new, management and operation of configuration)" dialog box, double-click "EquinoxOSGi Framework" button, Eclipse will open the run-time configuration dialog;

3) In the above dialog, the Name (name) values of the input box to HelloWorld Bundle;

4) You will notice that in the Workspace plug-in directory, there is a plugin called com.javaworld.sample.HelloWorld, select it; in TargetPlatform (target platform), please ensure that the org.eclipse.osgi plug-in is selected . Your Run (Run) dialog box should appear as shown in Figure 1:






Figure 1. HelloWorld Bundle run configuration

5) Now, click the Run (Run) button, you should see the console view, print out the "HelloWorld". In fact, Eclipse is OSGi console to open the console view.

3.2.1. OSGi Panel

OSGi OSGi container console is a command line interface, you can in the console to start, stop, install, update and delete Bundles. In EclipseIDE, please click on the console view has focus, then press the Enter key, then you can see the OSGi prompt, as shown in Figure 2: (translators note, in Eclipse3.3, if you do not see to the OSGi prompt, run the configuration in Figure 1, click the Arguments tab, and then ProgramArguments (process parameters) the input box, type "-console", and then re-run the Bundle).






Figure 2. OSGi console and HelloWorldActivator.java

Here are a few frequently used OSGi command, you can use these commands to interact with the OSGi container.

ss: This command displays all installed Bundles and their status, it will display the Bundle ID, Bundle and Bundle short name of the state; start : This command will start a Bundle; stop : This command will stop A Bundle; update : This command uses the new JAR file to update a Bundle; install : This command will install a new Bundle OSGi container; uninstall : OSGi container unloaded from an installed Bundle.

Please note that these commands are provided for OSGi specification, so you can use them to interact with any OSGi container.

Read here, I hope you OSGi Bundle development with a general understanding.









相关链接:



Taste CorelDRAW10: color docker



Using "replace" one-time elimination of the hard carriage return



Hot Multimedia Creation Tools



Assembly LANGUAGE instruction and by Example



MKV To PSP



ESSO Card From The City To Look Into The Need For Integration



How to convert protected wma to mp3 for ipod



Qingdao Shengli Oilfield Nursing Home Use Maxima



Enjoys a bandwidth 10M 20M 20M exclusive exclusive special price



Storage Inventory And Barcoding



MP4 To WMP



If THE turmoil on Wall Street later to 30 years



AVI To Zune



Samba Can Be The First To Support GPLv3 Break With Concerns



Introduction Games Card



Thursday, October 7, 2010

Credit "to bear the blame," Who back?


Some time ago, I saw major domestic media have reported that the central bank put into use personal credit information database, but in most media reports have described has a plot, Mr. Wang is a place for non-payment of Guangdong Development Bank Credit card annual fee was added in the personal credit database, a bad record, no knowledge of his purchase of agricultural bank loan was rejected.

Similarly, because a friend recently I apply for CITIC Industrial Bank's credit card was refused, and also because of his bad credit record. Through memories, Then he remembered who was in the Guangdong Development Bank to help friends who work for the completion of issuing process over a broad mandate issued credit card, apply for credit cards, said the first year annual fee waiver for the second year, if not paid do not want to continue to use annual fee you can. However, after more than a year without receiving any calls, text messaging, e-mail notice shall pay an annual fee of the case, the Guangdong Development Bank will be directly sent a reminder of the lawyer's letter, This the second year that do not pay annual fee does not work, and has been the payment date ... ... although very happy things finally settled, it is clear that, by banks to add in the personal credit history in a bad record into the aftermath of the incident.

In accordance with the central bank's statement, the national network of individual credit database, whether the future can even pay their individual water, electricity and gas charges are included in the scope of credit history, credit history and personal financial activities will play an increasingly important role. The central bank's super-scale CRM system, number of people covered, the breadth of applications is beyond doubt. However, I work in the financial system through a friend understand that the personal credit database of features is not perfect, and now can not distinguish between malicious and good debt arrears. That is, for a person with intent to defraud, one because of his bad memory and forget to pay a fee and a bank staff as a result of negligence or dereliction of duty in arrears without the knowledge of who they personally credit history credit database may even be the same. If the individual credit database, can only record a delinquent act and no delinquent behavior, can not record the reasons for arrears and assessment is malicious or non-malicious, then functions of this CRM system is also equivalent to a simple notebook, Moreover, some bank staff may not fulfill this obligation in accordance with the workflow (for example, the amount of notification bill, charge date, mortgage or car loan interest rate increases as a result of whether the monthly payment adjustments), then the person probably just made a scapegoat The copies of the.

The author believes that individual credit database, the mind should be put into use in the financial activities of the individual's actual behavior to determine a person's credit rating. However, due to the imperfections of the system, coupled with still no one able to bank credit, service records, assessment, and standardized system of bank staff working attitude, methods can determine your credit rating, and also we can do is frequently used as soon as the card is not all the write-off in the future no more free to work in a bank to help students and friends to complete the task card, after all, more than one card, the more a pair of hands affect your credit record.






Recommended links:



Catalogs Audio CD Players



ASF to MPEG



Shop Games Arcade



Vector graphics on the Description of several concepts



Balanced and non-equilibrium GIS GIS



Feeling so steady and VB API (1)



quot the language dll vbe6intl.dll could not be



ASF To MPG



DreamweaverMX BUILD Guestbook (4)



MOV to MP4



New Office Suites And Tools



Baidu pressed into the C2C site Taobao payment or ism



Congratulations to the Formal establishment of the Pan-micro Jinan Branch



Internal control: harm than good, or at every step