5 Replies Latest reply on May 13, 2004 6:08 AM by Andre Silva

    Method call after package deployment

    Andre Silva Newbie

      Hi,

      Is there some way to make JBoss call a specific method from a stateless session bean at deployment time, not dependent on user calling home.create(...) (and activating ejbCreate )?

      In other words: After package deploy finalization, I would like JBoss could call a method from a session bean inside the package. Something similar to the ServletContextListener in web applications.

      Thanks,

      Andre

        • 1. Re: Method call after package deployment
          jae Master

          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
            Raja Master

            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
              jae Master

              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
                Giovanni Formenti Newbie

                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
                  Andre Silva Newbie

                  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é