-
1. Re: Method call after package deployment
jae77 May 12, 2004 12:18 PM (in response to afsilva)you could do this w/ a custom mbean that registers itself for notifications w/ the EJB deployer. once the mbean gets the notice that your ejb has been deployed, you could then make the call to the ejb.
there may be other "simpler" approaches to accomplishing this, but unfortunately i am not sure of what they are (if any). -
2. Re: Method call after package deployment
raja05 May 12, 2004 12:26 PM (in response to afsilva)The setSessionContext should be a good place to initialize stuff. You could have a Singleton do the startup operations. Infact i had an implementation where my MDBs would load up a set of properties into a Hash at startup.
Or the option specified by jae77 would work although it wud be Jboss specific -
3. Re: Method call after package deployment
jae77 May 12, 2004 1:07 PM (in response to afsilva)the setSessionContext method isn't invoked until after ejbCreate is called. if you're looking to load some properties, why not just do it in the ejbCreate method?
afsilva: what are you trying to accomplish that requires calling the ejb method as soon as it's deployed? that will help guide you in the correct direction. -
4. Re: Method call after package deployment
formenti May 13, 2004 3:23 AM (in response to afsilva)You can use a
class Startup implements MBeanRegistration, StartupMBean
(maybe you found something about this on the net) or call the method inside the init() of a web Filter. If I understand your question... :)
Gio -
5. Re: Method call after package deployment
afsilva May 13, 2004 6:08 AM (in response to afsilva)I came up with an alternative solution. With JNDI it is possible to discover all my session beans deployed, then through reflection, I can invoke a specific method:
... ic = new InitialContext(); NamingEnumeration enum = new ic.list("ejb/mysessionbeans"); while (num.hasMore()) { NameClassPair ncp = (NameClassPair)enum.next(); EJBHome ejbhome = (EJBHome)ic.lookup("ejb/mysessionbeans/" + ncp.getName()); if (ejbhome.getEJBMetaData().isStatelessSession()) { Method m = ejbhome.getClass().getMethod("create", null); Object o = m.invoke(ejbhome, null); m = o.getClass().getMethod("initPlugin", null); o = m.invoke(o, null); } ...
And this code is invoked by JBoss at deployment time with the org.jboss.varia.scheduler.Scheduler:<mbean code="org.jboss.varia.scheduler.Scheduler" name=":service=Scheduler"> <attribute name="StartAtStartup">true</attribute> <attribute name="SchedulableClass">myPackage.PluginInitializer</attribute> <attribute name="InitialStartDate">NOW</attribute> <attribute name="SchedulePeriod">1000</attribute> <!-- do not care --> <attribute name="InitialRepetitions">1</attribute> </mbean>
It's not 100% portable (because the scheduler), but I think it's close enough.
Thanks all for the replies!
André