I am using Jboss5.1.x, EJB3.0
I am into this subject for couple of days now. I heard it suppose to be easy, but it seems that or it's lack of documents or it was hard for me to get some things.
My scenario is to have a scheduled task which will trigger when I first deploy my application server project to jboss and then I want my proccess to re-executed every X time.
I have finally managed to add the quartz mbean to jboss-service.xml
but:
how do I trigger it after server deployment automaticly? I saw I must do it through servlet? so how will I trigger the servlet on project deploy? cant I trigger it without a servlet and do it straightly on EJB bean?
after it being trigger, I want to call from the trigger method to an EJB stateless bean.
i would want the scenario to be something like this:
(application deploy -> Quartz -> EJB bean -> ..) insteadof (application deploy - > Quartz -> servlet -> EJB bean)
how would I do that? this is the code I found:
InitialContext ctx = new InitialContext();
StdScheduler scheduler = (StdScheduler) ctx.lookup("Quartz");
JobDetail jd = new JobDetail("myjob", scheduler.DEFAULT_GROUP, NewJob.class);
CronTrigger ct = new CronTrigger("cronTrigger", "group2", "0 0/5 * * * ?");
scheduler.scheduleJob(jd, ct);
it seems that by this code it only triggers POJO's ("NewJob.class"). and I want to trigger EJB stateless bean.
anyone has any answers? please.. worst case I will switch from Quartz to something else.
thanks, ray.
I don't fully understand your question - or rather I am guessing that there is more than one question here, but I don't quite follow the language of it, as you seem to be using the word "trigger" (a quartz term) in more than one way.
At any rate, there is one of your questions that I can clearly understand and answer, and that is how to get quartz to invoke a method on your EJB. Simply write a Job class that contains code in its execute() method that knows how to lookup and invoke that EJB. Then scheduler and instance of that job, and whenever it fires it will invoke the EJB. Quartz actually ships with an EJBInvokerJob that does just that, so you may be able to use it without modification, or may want to use its source code as your starting point. (Note that the Job quartz ships with invokes EJB v.2 beans. However, there is class available for invoking EJB3 beans, which you can download here: http://jira.opensymphony.com/browse/QUARTZ-732)
Your other question about the mbean and servlet you need to restate, as it confuses me why you would be using both mechanisms.