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