This content has been marked as final.
Show 8 replies
-
1. Re: Start quartz cron when Seam apps is up
nickarls Jan 14, 2008 1:42 AM (in response to thejavafreak)You could probably place an observer on org.jboss.seam.postInitialization and tickle it from there.
-
2. Re: Start quartz cron when Seam apps is up
marx3 Jan 14, 2008 2:28 AM (in response to thejavafreak)or maybe use servlet with
<load-on-startup>1</load-on-startup> ?
What's better? -
3. Re: Start quartz cron when Seam apps is up
nickarls Jan 14, 2008 2:57 AM (in response to thejavafreak)"Marx3" wrote:
or maybe use servlet with
<load-on-startup>1</load-on-startup> ?
What's better?
If you are using seam-stuff in your job it is probably best waiting for seam to signal that the init is complete (and it saves you from writing a servlet and mapping it) -
4. Re: Start quartz cron when Seam apps is up
thejavafreak Jan 14, 2008 4:12 AM (in response to thejavafreak)"nickarls" wrote:
You could probably place an observer on org.jboss.seam.postInitialization and tickle it from there.
Hi Nick,
Thanks for the hint. I'm going to read the document and try it first.
Thanks, -
5. Re: Start quartz cron when Seam apps is up
cavani Jan 14, 2008 6:42 AM (in response to thejavafreak)I am using this:
@Name("bootstrap") @Scope(ScopeType.APPLICATION) @BypassInterceptors @Startup public class Bootstrap { @Create public void start() throws Exception { Events.instance().raiseTimedEvent("comeEvent", new CronSchedule((Long) null, "0 0 6 * * ?")); } @Destroy public void stop() { } }
It's working, but may not be exactly what you want.
Other way (once setted you can't get cron trigger anymore, so...):@Name("synchronizationTimer") @Scope(ScopeType.APPLICATION) @Startup public class SynchronizationTimer { private static final String defaultTrigger = "0 0 3 * * ?"; @Logger private Log log; private QuartzTriggerHandle handle; private String trigger = defaultTrigger; @Create public void start() throws Exception { // uncomment this if you want set timer on startup setTrigger(defaultTrigger); } public void restoreDefault() { setTrigger(defaultTrigger); } public void setTrigger(String trigger) { try { QuartzTriggerHandle handle = QuartzDispatcher.instance().scheduleTimedEvent("someEvent", new CronSchedule((Long) null, trigger)); if (this.handle != null) this.handle.cancel(); this.handle = handle; this.trigger = trigger; } catch (Exception e) { log.error("Erro configurando timer: #0", e, trigger); } } public String getTrigger() { return trigger; } public void cancel() { try { if (handle != null) handle.cancel(); handle = null; trigger = null; } catch (Exception e) { log.error("Erro configurando timer: #0", e, trigger); } } @Destroy public void stop() { cancel(); } }
Thanks, -
6. Re: Start quartz cron when Seam apps is up
cavani Jan 14, 2008 6:52 AM (in response to thejavafreak)Sorry by portuguese log, but it is very easy to undestand.
Second, I put the comment but didn't comment the code on start method, so...
Both are Seam components and it is interesting to use:@In private SynchronizationTimer synchronizationTimer;
to control the timer.
Thanks, -
7. Re: Start quartz cron when Seam apps is up
thejavafreak Jan 15, 2008 3:07 AM (in response to thejavafreak)I've got it working now. I was just curious why didn't you have an Observer method for the comeEvent?
-
8. Re: Start quartz cron when Seam apps is up
cavani Jan 15, 2008 6:29 AM (in response to thejavafreak)sorry, I show you half side of code (timed event generator), so yes... and this name was a typo.... should be "someEvent"... you must set observer over some public method on any seam component.
In my case, it is on another component that it is SLSB:@Local public interface Handler { void doSomething(); } @Name("xxx") @Stateless public HandlerBean implements Handler { // ... @Observer("someEvent") public void doSomething() { // ... } }
That way, the business logic code stay with EJB...
Thanks,