4 Replies Latest reply on Oct 9, 2009 5:34 AM by alesj

    Confused about POJO service

      Hello,

      The new mc is probably the most feature-rich container out there. You can roll with anything from POJOs to MBeans. However, I am a little confused due to the multitude of options. My predicament is this:

      I want to create a service to be deployed in JBoss. Until recently, I'd create a SAR and launch my thread in start(), then kill it in stop() of my MBean. I do this at deployment/undeployment time, so I do not really need the JMX features to control the service. Therefore I want to turn it into a POJO service and remove dependencies on MBean classes. How would you go about packaging such a POJO service so that:

      1) it may be included in an EAR (The SAR approach requires that an MBean be defined in jboss-service.xml so it is no longer an option)

      2) it executes on application startup / shutdown

        • 1. Re: Confused about POJO service
          alesj

          Simply create a POJO - drop the MBean stuff - and place it any META-INF/somename-jboss-beans.xml.
          See JBoss5 config files on how MC's schema looks like.

          MC tries to execute create/start/stop/destroy parameterless methods on the bean by default if they exist.
          So, just keep the start() and stop() and you're fine.

          • 2. Re: Confused about POJO service

            Would that be packaged in a JAR for JBoss to pick it up?

            My current test (which does not get activated) is a JAR with one class and one interface (the interface defines the start/stop methods) as follows:

            public class MyServiceImpl implements MyService {
             private Logger logger;
            
             public void start() {
             logger = LoggerFactory.getLogger(MyServiceImpl.class);
             logger.info("has been started");
             }
            
             public void stop() {
             logger.info("has been shut down");
             logger = null;
             }
            }


            It contains a META-INF/my-service-beans.xml as follows:
            <?xml version="1.0" encoding="UTF-8"?>
            <deployment xmlns="urn:jboss:bean-deployer:2.0">
             <bean name="MyService" class="test.MyServiceImpl" />
            </deployment>


            I drop it into the deploy folder (archived, not exploded) but nothing happens.


            • 3. Re: Confused about POJO service

              Ok, I got it. The deployment descriptor filename must be "jboss-beans.xml" otherwise the jar is ignored.

              BTW, this is an opportunity to document in the forum the naming issue: When can you use a different filename? You mentioned it in your reply and I've also seen it in various articles (e.g. the DZone article).

              Thanks for your help.

              • 4. Re: Confused about POJO service
                alesj

                 

                "karypid" wrote:

                When can you use a different filename?

                It depends on the BeanDeployer:
                - http://anonsvn.jboss.org/repos/jbossas/projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/deployer/kernel/BeanDeployer.java