[dj] geoaxis: I was responding to how you do dependency injection in daemons [17:27] [geoaxis] djgregor, oh [17:28] [dj] The JMX bean for the daemon extends this: http://opennms.svn.sourceforge.net/viewvc/opennms/opennms/trunk/opennms-services/src/main/java/org/opennms/netmgt/daemon/AbstractSpringContextJmxServiceDaemon.java?view=markup [17:29] [dj] 2. You add a daemon context for the daemon to this file: http://opennms.svn.sourceforge.net/viewvc/opennms/opennms/trunk/opennms-services/src/main/resources/beanRefContext.xml?view=markup [17:30] [geoaxis] ok , well i had forgotten about it, in case of pollerBackEnd its already there [17:31] [geoaxis] one probelm though ..what happens if i want references beyond daemons [17:31] [dj] 3. And finally, you wire up the daemon (make sure its bean is called "daemon"): http://opennms.svn.sourceforge.net/viewvc/opennms/opennms/trunk/opennms-services/src/main/resources/META-INF/opennms/applicationContext-eventDaemon.xml?view=markup [17:31] [geoaxis] shall i pass them to the method which is being called, or they should be injected as well [17:32] [dj] what do you want to reference? [17:32] [dj] or do other daemons need to reference yours? [17:32] [geoaxis] a Dao [17:32] [dj] so, look at that beanRefContext.xml file [17:32] [dj] you'll see that the various daemon contexts extend a configuration context or a base daemon context, which extends the DAO context [17:33] [dj] so, it's a gimme [17:33] [dj] so, there's the daoContext which includes applicationContext-dao.xml; then the daemonContext extends daoContext and includes a few daemon-specific things (an eventIpcManager, I think) [17:34] [dj] and then commonContext defines a few configuration files that aren't in applicationContext-dao.xml [17:34] [dj] finally, the per-daemon contexts either extend daemonContext or commonContext, depending on what they need [17:34] [geoaxis] i see [17:35] [dj] BTW, pollerbackend and pollerfrontend are for the remote poller [17:35] [geoaxis] yeah, so where would I place for Poller.java [17:36] [geoaxis] or i should come from Pollerd and pass references of dao to daemon and then to the Poller [17:36] [dj] Start with Statsd... it's pretty simple: http://opennms.svn.sourceforge.net/viewvc/opennms/opennms/trunk/opennms-services/src/main/java/org/opennms/netmgt/statsd/jmx/ [17:36] [dj] You'll see in the jmx/Statsd.java class that it specifies the context name from beanRefContext.xml to use [17:37] [dj] the non-jmx Statsd.java is the real daemon: http://opennms.svn.sourceforge.net/viewvc/opennms/opennms/trunk/opennms-services/src/main/java/org/opennms/netmgt/statsd/Statsd.java?view=markup [17:38] [dj] you'll see that it is spring-wired, has afterPropertiesSet for initialization, etc.. [17:38] [geoaxis] ok, but that is an example for daemon ..would this work on say Poller.java [17:39] [dj] Er, sorry, the actual daemon needs to extend SpringServiceDaemon [17:39] [dj] let me see what Poller.java does... one sec [17:39] [dj] Ha! Nice, Poller.java is dependency injected by jmx/Pollerd.java [17:40] [dj] So, mostly, you change jmx/Pollerd.java to a tiny file with just two methods like statsd/jmx/Statsd.java [17:42] [geoaxis] i see [17:42] [dj] Then, change Poller.java to extend SpringServiceDaemon, InitializingBean, and DestroyableBean (or whatever that interface in Spring is called). [17:43] [dj] you'll change onInit in Poller.java to afterPropertiesSet, as well as onStart to start and onStop to whatever the method is in DestroyableBean [17:43] [geoaxis] it sounds so simple :P [17:44] *geoaxis needs coffee [17:44] [dj] heh [17:44] *djgregor_work is drinking tea at a coffeeshop [17:44] [dj] geoaxis: we could stand to document this. :-) [17:45] [dj] but it will be changing at some point to OSGi [17:45] [dj] geoaxis: it's messy partially because a lot of the daemons implemented things differently [17:45] [geoaxis] yeah, i figured ..just read some comments of browzow about that on ML (OSGi) [17:45] [dj] Some daemons put a lot of stuff directly into their JMX bean and delegated some to the actual daemon bean; some delegated everything to the daemon bean [17:46] [geoaxis] ok ..so what you pointed out should be all (i will try to follow it up in a while) [17:46] [dj] geoaxis: yeah; statsd is probably the simplest example [17:47] [geoaxis] yeah well it was mentioned in my first meeting [17:48] [dj] pretty much just create src/main/resources/META-INF/opennms/applicationContext-poller.xml that creates a bean called "daemon" for org.opennms.netmgt.poller.Poller and injects the stuff that the Java code in jmx/Pollerd injects now. [17:49] [dj] Then, rip out nearly everything in jmx/Pollerd.java and make it look like jmx/Statsd.java [17:49] [geoaxis] hmmm [17:50] [geoaxis] would it affect any tests by any chance [17:51] [dj] lastly, edit beanRefContext.xml, adding a bean like one of the existing ones, giving it the same name as what is mentioned in the getSpringContext() method of your new, freshly-minted jmx/Pollerd class [17:51] [dj] geoaxis: of course! :-) [17:52] [dj] actually, maybe not substantially [17:52] [dj] I bet that none of the poller tests exercise jmx/Pollerd [17:52] [dj] So, the worst thing is that some of the method names on Poller would need to change (onInit -> afterPropertiesSet, etc..), or you could always add *new* method names that point at the old, existing ones [17:53] [dj] I'll give you time to digest; bug me if you need anything (and if you don't see me around, here, dj@opennms.org works) [17:54] [geoaxis] sure thanks again [17:55] [dj] np, glad to help