OSGi + Felix Example2b writing

Source: Internet
Author: User

In the previous blog post we explained the traditional registered service and declarative services of OSGi, and then we wrote the OSGi + Felix Example2, a blog post where we wrote a bundle and an interface and implemented the interface accordingly, The service was registered in the Start method of the bundle and was not used for this service. The program written in this article still does not use this service, only the corresponding registration, in EXAMPLE3 will explain the use of this service.

Program

Changes in the program are only part of the activator, the specific procedures are as follows:

 Packagecn.com.example2b;ImportCn.com.example2.DictionaryService;ImportOrg.osgi.framework.BundleActivator;ImportOrg.osgi.framework.BundleContext;ImportJava.util.Dictionary;Importjava.util.Hashtable;/** * Created by Administrator on 2016/6/19. * * Public  class Activator implements bundleactivator {     Public void Start(Bundlecontext context)throwsException {hashtable<string, string> props =NewHashtable<string, string> (); Props.put ("Language","French"); Context.registerservice (DictionaryService.class.getName (),NewDictionaryimpl (), props); System.out.println ("Service registered ..."); } Public void Stop(Bundlecontext context)throwsException {}Private Static  class Dictionaryimpl implements dictionaryservice {String[] M_dictionary = {"Bienvenue","Au","Tutoriel","OSGi"}; Public Boolean Checkword(String Word) {word = Word.tolowercase (); for(inti =0; i < m_dictionary.length; i++) {if(M_dictionary[i].equals (Word)) {return true; }            }return false; }    }}
Summarize

In contrast to example2, the change is only the bundle Start method, in the service registration when the parameters passed in different, it is expected that Felix official website to do so is to familiarize us with the OSGi registration services, this article does not use the corresponding services, but this article, the individual has some other ideas , that is, the Dictionaryservice implementation class can be extracted separately, used alone, because in almost every bundle in the post has this interface implementation class, although the m_dictionary is different, these will be extracted separately in example6 use , because the use of service registration and the Felix website are different in the following article, and this section will not be discussed again.

OSGi + Felix Example2b writing

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.