Hi think this discussion already happended on jira.
TomEE uses a org.apache.openejb.core.timer.TimerStore to "CRUD" timers, by default we use a memory store but it is configurable. we don't have ATM a persistent store, we have the class org.apache.openejb.core.timer.DatabaseTimerStore but it is not yet implemented. If you want to contribute it we'll be very happy to commit it. *Romain Manni-Bucau* *Twitter: @rmannibucau <https://twitter.com/rmannibucau>* *Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/> *LinkedIn: **http://fr.linkedin.com/in/rmannibucau* *Github: https://github.com/rmannibucau* 2013/7/30 tschuler <[email protected]> > Hi Leo! > > That might work. But is it possible that TomEE initializes the injected > timerservice with already existing timers for the scheduled bean? > Because only TomEE should know how timers are stored in quartz tables ... > > Best regards, > Thomas > > Von: Leonardo K. Shikida [via OpenEJB] [mailto: > [email protected]] > Gesendet: Dienstag, 30. Juli 2013 16:02 > An: Thomas Schuler > Betreff: Re: No access to timers after server restart > > Hi Thomas > > yes, this is really annoying > > you have to bypass the JEE standard and go directly inside the native > Quartz implementation to get what you want > > try something like this > > import java.util.ArrayList; > import java.util.List; > > import javax.ejb.ScheduleExpression; > import javax.ejb.Stateless; > import javax.ejb.Timeout; > import javax.ejb.Timer; > import javax.ejb.TimerConfig; > import javax.inject.Inject; > import javax.jms.JMSException; > > import org.apache.openejb.core.timer.TimerData; > import org.quartz.JobKey; > import org.quartz.Scheduler; > import org.quartz.SchedulerException; > import org.quartz.Trigger; > import org.quartz.TriggerKey; > import org.quartz.impl.StdSchedulerFactory; > import org.quartz.impl.matchers.GroupMatcher; > > (...) > @SuppressWarnings("unchecked") > public List<QuartzTrigger> listAllTimers() throws > SchedulerException { > > List<QuartzTrigger> timers = new > ArrayList<QuartzTrigger>(); > > Scheduler scheduler = this.baseService.getScheduler(); > > for (String groupName : scheduler.getJobGroupNames()) { > for (JobKey jobKey : > scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))) { > for (Trigger trigger : (List<Trigger>) > scheduler.getTriggersOfJob(jobKey)) { > TimerData timerData = > (TimerData)trigger.getJobDataMap().get("TIMER_DATA"); > String info = > (String)timerData.getInfo(); > // System.out.println(info); > if (info != null){ > QuartzTrigger qt = new > QuartzTrigger(); > qt.setDescription(info); > > qt.setKey(trigger.getKey()); > > qt.setStatus(scheduler.getTriggerState(trigger.getKey()).toString()); > > qt.setLastFire(trigger.getPreviousFireTime()); > > qt.setNextFire(trigger.getNextFireTime()); > timers.add(qt); > } > } > } > } > > return timers; > } > > QuartzTrigger is just a bean like this > > import java.io.Serializable; > import java.util.Date; > import org.quartz.TriggerKey; > > public class QuartzTrigger implements Serializable{ > private static final long serialVersionUID = -6577490874256837028L; > private String description; > private TriggerKey key; > private String status; > private Date nextFire; > private Date lastFire; > (...) > > and the scheduler is > > scheduler = new StdSchedulerFactory().getScheduler("myScheduler"); > > and don't forget to put this name (myScheduler) at > application.properties, like this > > org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreCMT > org.quartz.jobStore.dataSource=quartzDS > org.quartz.jobStore.nonManagedTXDataSource = quartzDS2 > org.quartz.scheduler.instanceName = myScheduler > org.quartz.jobStore.isClustered=false > org.quartz.scheduler.instanceId=AUTO > org.quartz.scheduler.threadsInheritContextClassLoaderOfInitializer=true > org.quartz.scheduler.makeSchedulerThreadDaemon=true > org.quartz.jobStore.makeThreadsDaemons=true > org.quartz.threadPool.threadCount = 10 > > org.quartz.jobStore.tablePrefix = QRTZ_ > > org.quartz.jobStore.driverDelegateClass = > org.quartz.impl.jdbcjobstore.StdJDBCDelegate > org.quartz.dataSource.quartzDS.jndiURL=openejb:Resource/jdbc/quartzDS > org.quartz.dataSource.quartzDS2.jndiURL=openejb:Resource/jdbc/quartzDS2 > > as you know, application.properties goes into > /YourApp/WebContent/WEB-INF/application.properties > > and the quartz datastore may be configured at tomee.xml as > > > <Resource id="jdbc/quartzDS" type="DataSource"> > JdbcDriver com.mysql.jdbc.Driver > JdbcUrl jdbc:mysql://localhost:3306/quartz > UserName xxx > Password xxx > JtaManaged true > </Resource> > > <Resource id="jdbc/quartzDS2" type="DataSource"> > JdbcDriver com.mysql.jdbc.Driver > JdbcUrl jdbc:mysql://localhost:3306/quartz > UserName xxx > Password xxx > JtaManaged false > </Resource> > > [] > > Leo > > > On Tue, Jul 30, 2013 at 10:09 AM, tschuler <[hidden > email]</user/SendEmail.jtp?type=node&node=4664428&i=0>> wrote: > > > Hi! > > > > We use a scheduled bean, the added timers are persisted in a database > table. > > After server restart the timers still work and the scheduled bean is > > triggered as expected. > > > > But we get no access to the timers any more and therefore cannot cancel > > them. > > The injected TimerService on the scheduled bean does not provide the > timers > > added before server restart within its getTimers() method. > > > > Is there another way to get access to the timers for a scheduled bean > after > > server restart? > > > > Best regards, > > Thomas > > > > > > > > -- > > View this message in context: > http://openejb.979440.n4.nabble.com/No-access-to-timers-after-server-restart-tp4664425.html > > Sent from the OpenEJB User mailing list archive at Nabble.com. > > ________________________________ > If you reply to this email, your message will be added to the discussion > below: > > http://openejb.979440.n4.nabble.com/No-access-to-timers-after-server-restart-tp4664425p4664428.html > To unsubscribe from No access to timers after server restart, click here< > http://openejb.979440.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4664425&code=dGhvbWFzLnNjaHVsZXJAb3BlbnRleHQuY29tfDQ2NjQ0MjV8LTE4NTIyNTQ0OTI= > >. > NAML< > http://openejb.979440.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml > > > > > > > -- > View this message in context: > http://openejb.979440.n4.nabble.com/No-access-to-timers-after-server-restart-tp4664425p4664430.html > Sent from the OpenEJB User mailing list archive at Nabble.com. >
