POJO Lifecycle methods
Just as for "normal" MBeans in JBoss, Service POJOs support lifecycle management, but you don't need to create all these methods. You can pick and choose only those needed by your Service.
If present in the service, the container will call these methods as follows:
create() - called by the server when the service is created and all the services it depends upon have been created too. At this point the service (and all the services it depends on) is installed in the JMX server, but is not yet fully functional.
start() - called by the server when the service is started and all the services it depends upon have been started too. At this point the service (and all the services it depends on) is fully functional.
stop() - called by the server when the service is stopped. At this point the service (and all the services that depend on it) is no longer fully operational.
destroy() - called by the server when the service is destroyed and removed from the MBean server. At this point all the MBeans that depend on the
Packaging and deploying
Packaging your Service is just a matter of compiling the classes and putting them in a jar file (You can even choose to deploy them as exploder jar folder which is easier for development use)
If you're using an Eclipse based tool simply add to your Project--->Properties--->Java Build Path the library jboss-annotations-ejb3.jar which is found in your JBOSS_HOME/client folder.
If you're compiling with the console just throw a
javac -classpath c:\jboss-4.2.0.GA\client\jboss-annotations-ejb3.jar;. -d . *.java
(Change the JBoss location to your JBoss Home).
Now jar everything:
jar cvf Calculate.jar sample
and copy the Calculate.jar in the "deploy" directory of JBoss. If everything was done correctly you should see in the server logs...
|11:03:02,546 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:jar=Calculate.jar,name=CalculateInterestMBean,service=EJB3 with dependencies:
11:03:02,593 INFO [EJBContainer] STARTED EJB: sample.jmx.CalculateInterestMBean
11:03:02,609 INFO [STDOUT] CalculateInterestMBean - Creating
11:03:02,625 INFO [JmxKernelAbstraction]creating wrapper delegate for: org.jboss.ejb3.service.ServiceContainer
11:03:02,625 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:jar=Calculate.jar,name=FinancialAdvisorMBean,service=EJB3 with dependencies:
11:03:02,625 INFO [JmxKernelAbstraction] sampleJMX:service=calculateInterest
11:03:02,687 INFO [EJBContainer] STARTED EJB: sample.jmx.FinancialAdvisorMBean ejbName: FinancialAdvisorMBean
11:03:02,703 INFO [STDOUT] FinancialAdvisorMBean - Creating
11:03:02,718 INFO [EJB3Deployer] Deployed: file:/C:/jboss-4.2.0.GA/server/default/deploy/Calculate.jar/