By using the monitoring interface provided by spring DM, we can better control the service, in fact, the interface is also very simple to use, as long as the custom of a class implementation of the Osgibundleapplicationcontextlistener interface, Implement the Onosgiapplicationevent method, and register the custom class as an OSGi service, perform the appropriate logic processing by judging the event type of events, and also obtain the bundles that are currently listening, thus achieving deeper monitoring.
Public classListenerdemoImplementsosgibundleapplicationcontextlistener{@Override Public voidonosgiapplicationevent (Osgibundleapplicationcontextevent event) {String bundlename=Event.getbundle (). Getsymbolicname (); if(Eventinstanceofosgibundlecontextrefreshedevent) {//spring Context Creation Success Event System.out.println ("Service startup"); }Else if(Eventinstanceofosgibundlecontextclosedevent) {//spring context destroys event System.out.println ("Service Shutdown"); } }}
<id= "Listenerdemo" class= " Com.sample.service.listener.ListenerDemo "></bean> < ref = "Listenerdemo" interface= " Org.springframework.osgi.context.event.OsgiBundleApplicationContextListener "/>
The bundle listener interface provided by Spring DM Osgibundleapplicationcontextlistener