-
1. Re: How to start a session bean as soon as it is deployed
ragavgomatam Feb 1, 2008 9:35 PM (in response to masoodah)Use ejb Timer Service
-
2. Re: How to start a session bean as soon as it is deployed
masoodah Feb 2, 2008 8:37 AM (in response to masoodah)I think I m using ejb timer service.
Pl. see my code.
Can you provide me with an example please.
Thanks -
3. Re: How to start a session bean as soon as it is deployed
oskar.carlstedt Feb 3, 2008 4:00 PM (in response to masoodah)Hi All!
Important to know. An ejb is NOT started just because it is deployed. It is just available to a "client" through the application server. There is no method invoked on an ejb during or just after the deploy.
Ok, there are ways to go around this. Add a service to your ejb that is invoking your ejb. Use the @Service-annotation and then you get methods like start(), stop() create() and destroy().
Kind regards!
/Oskar -
4. Re: How to start a session bean as soon as it is deployed
wolfc Feb 4, 2008 9:37 AM (in response to masoodah)I'm planning to change this behavior in light of EJB 3.1. The supported way will be to use @PostConstruct in a @Singleton.
So for now I would say use @PosConstruct in a @Service bean.
Note that the create, start, stop, destroy methods will become deprecated and might disappear completely. -
5. Re: How to start a session bean as soon as it is deployed
masoodah Feb 4, 2008 10:01 AM (in response to masoodah)Hi All,
I got this problem resolved for EJB3 by creating a sar which calls the SessionBean and packaging with my ear as well explained in this link.
http://www.tomlauren.com/weblog/archives/000014.html
When EJB3.1 is officially released I can think of other options.
Thanks for all your help. -
6. Re: How to start a session bean as soon as it is deployed
tpawankumar Apr 1, 2008 8:38 AM (in response to masoodah)Hi oskar/wolfc
I have tried both options suggested by you but it is not working.
Following is the code of my stateless bean@Service @Stateless @Remote(ConfigService.class) @Local(ConfigService.class) public class ConfigServiceBean implements ConfigService { @PostConstruct public void test(){ System.out.println("Called test...."); } /** *some methods inside this bean **/ }
The method test() is not getting called when it is deployed.
Server i am using is Jboss 4.2.1 GA.
The method is getting called when first request is sent to the bean.
Please let me know if i miss something.
Please help me.
Thanks,
Pavan -
7. Re: How to start a session bean as soon as it is deployed
oskar.carlstedt Apr 1, 2008 9:26 AM (in response to masoodah)Hi!
When annotating with the service you have four life cycle methods that you can implement.
*create
*start
*stop
*destroy
Try call test from start and you'll se that it will be called.
Cheers
/Oskar -
8. Re: How to start a session bean as soon as it is deployed
oskar.carlstedt Apr 1, 2008 9:36 AM (in response to masoodah)Here is a short eaxample:
@Service @Management(MyServiceManagement.class) @Depends("jboss.ws:service=DeployerInterceptorEJB3") public class MyService implements MyServiceManagement { private Timer timer = null; @Resource private EJBContext ejbContext; public void start() throws Exception { timer = ejbContext.getTimerService().createTimer(1000, "Say Hello!!"); } @Timeout public void timeout(Timer timer) { System.out.println(timer.getInfo()); timer = ejbContext.getTimerService().createTimer(1000, "Say Hello again!!"); } public void stop() { timer.cancel(); } } public interface MyServiceManagement { public void start() throws Exception; public void stop() throws Exception; }
/Oskar