-
15. Re: Quartz Scheduling questions
risenhoover May 1, 2008 6:03 PM (in response to risenhoover)Hi Zahid,
My scheduling class is already in a different class. I added the @AutoCreate to it and it still doesn't work.
Thanks for the tip, though.
-
16. Re: Quartz Scheduling questions
zahidmaqbool May 2, 2008 3:13 AM (in response to risenhoover)Ok try this:
@Name("asyncDownloader") @AutoCreate public class AsyncAFSDownloader { @Asynchronous @Transactional @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public QuartzTriggerHandle schedulePayment(@Expiration Date when, @IntervalDuration Long interval, @FinalExpiration Date endDate ) { // do the repeating or long running task until endDate AFSStatusController afsc = new AFSStatusController(); System.out.println("\n\n\n\n-------------------------------------" + "Scheduler Started, Executing Job to Process AFS Response Downloader and State Progressor----------------\n\n\n\n"); QuartzTriggerHandle handle = new QuartzTriggerHandle("AFSTrigger"); //do your processing here return handle; } }
and this is the observer which calls it:
@Transactional @Name("startupTesting") public class StartupTesting { @Logger private Log log; @In AsyncAFSDownloader asyncDownloader; /** * This is called by seam after initialization * has finished. */ @Observer("org.jboss.seam.postInitialization") public void observe() { try { log.info("Trying to Start Cron Job"); Calendar cal = Calendar.getInstance (); cal.set (2040, Calendar.MAY, 10); QuartzTriggerHandle handle = asyncDownloader.schedulePayment(new Date(), 60*1000L, cal.getTime()); } catch(Exception e) { e.printStackTrace(); log.info("Operation Failed"); } log.info("Job Started"); } }
Just now managed to get Cron Job also working .. If you need any code reagrading that let me know
-
17. Re: Quartz Scheduling questions
zahidmaqbool May 2, 2008 3:16 AM (in response to risenhoover)I forgot to mention it should work without the Transaction annotation also. But I have used it cause I inject the JbpmContext, I removed other code for readibility
-
18. Re: Quartz Scheduling questions
risenhoover May 10, 2008 10:01 PM (in response to risenhoover)At last! It works! I moved the @Asynchronous, @Expiration, etc. tags to the Local Interface of the EJB and it started working. I'm not sure why this makes a difference, but there it is.
Thanks for all the help!
-
19. Re: Quartz Scheduling questions
j1.jonathan.m.clarke.dsl.pipex.com May 26, 2008 11:06 PM (in response to risenhoover)Hi All,
I'm new to JBoss Seam. I'd like to use Quartz to invoke autonomous behaviour at startup, which is then contacted by numerous session beans throughout the life of the application. However, having followed the instructions of numerous forums, including this one, I'm still unable to get my asynched method scheduled. So,
1. I have jboss-seam-2.0.2.GA and jboss-4.2.2.GA installed.
2. I have used 'seam setup' and 'seam create-project' according to the standard instructions.
3. My components.xml file includes:
xmlns:async="http://jboss.com/products/seam/async" http://jboss.com/products/seam/async http://jboss.com/products/seam/async-2.0.xsd <async:quartz-dispatcher/>
4. My classes are:
public class Processor { Integer fIndex = 0; @Asynchronous public QuartzTriggerHandle doWork( @Expiration Date aWhen, @IntervalDuration Long aInterval, @FinalExpiration Date aStoptime) { System.out.println("Ticking Over Processor"); System.out.println(fIndex.toString()); fIndex++; return null; } } public class Initiator { Processor fProcessor = new Processor(); @Observer("org.jboss.seam.postInitialization") public void observe() { Calendar fCalendar = Calendar.getInstance(); fCalendar.set(2040, Calendar.MAY, 10); fProcessor.doWork(new Date(), 1000L, fCalendar.getTime()); } }
They are intended to be POJOs, and there is no indication in the limited documentation that they should be further annotated for Seam.
Am I doing anything obviously wrong? Many thanks for your time.
-
20. Re: Quartz Scheduling questions
j1.jonathan.m.clarke.dsl.pipex.com May 26, 2008 11:12 PM (in response to risenhoover)Sorry, I forgot to say that the only debug output is:
INFO [STDOUT] Ticking Over Processor INFO [STDOUT] 0
This happens only once, indicating that the 'observer' functions as expected, but the scheduled method does not.
Also, the classes I've indicated above are the only ones I've implemented on top of the skeleton generated by 'seam create-project'
Thanks again.
-
21. Re: Quartz Scheduling questions
cpopetz May 27, 2008 2:37 AM (in response to risenhoover)@Asynchronous (and virtually every other cool seam annotation) depends upon an interceptor which is only run on targets that are seam components. So you can't do:
Processor fProcessor = new Processor();
but instead you should do:
@In Processor processor;
and annotate your processor class with:
@Name("processor")
-
22. Re: Quartz Scheduling questions
j1.jonathan.m.clarke.dsl.pipex.com May 27, 2008 11:13 PM (in response to risenhoover)Brilliant! Thank you. In my naivety, I'd assumed that the @In annotation was associated only with UI-based injection, rather than injections based on a search through all framework contexts. I don't have a web development background, and it's certainly a bit of a mindset change. I had to add @AutoCreate to the Processor class, and @Scope(APPLICATION), in order preserve the state of fIndex, and it works fine. What I'm hoping to do, though, is to have several instances of the Processor class, each operating independently. However, with the @In Processor clause, in turn based on @Name(
processor
), doesn't that preclude instantiating more than one object of that class type? I'm hoping that the documentation will detail this, in due course, but it's struggling to drag itself away from the usual single instances that go with the trivial database table/session bean examples. -
23. Re: Quartz Scheduling questions
cpopetz May 28, 2008 5:02 AM (in response to risenhoover)You are correct, you'll need to place your component in a shorter scope than application if you want to have more than one, or use a @Role.
I really recommend reading the reference docs front to back, twice. In addition, Dan Allen's
Seam in Action
and Michael Yuan's Seam-book-with-a-really-long-title-that-I-can't-remember are both excellent. In particular, if you haven't worked in web frameworks before, Seam is going to bite you if you don't read up. -
24. Re: Quartz Scheduling questions
j1.jonathan.m.clarke.dsl.pipex.com May 28, 2008 9:21 AM (in response to risenhoover)Will do. Thanks for your help.
-
25. Re: Quartz Scheduling questions
ashok.ashok.k.vedainformatics.com Aug 23, 2011 7:44 AM (in response to risenhoover)Thanks Daniel, your reply saved my time.