X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=mythtv%2Fmonitor%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fmythtv%2FApplication.java;h=539557516fac667fb932507d563db5bd834197a8;hb=9e0f847646d5700547a751f96fad5ef018e2f829;hp=01d030262d5bb1791e8d2865b4ebde4c42e7b084;hpb=c26786cd41376f29d1f391644f77f27a9b197245;p=utils diff --git a/mythtv/monitor/src/main/java/org/wamblee/mythtv/Application.java b/mythtv/monitor/src/main/java/org/wamblee/mythtv/Application.java index 01d03026..53955751 100644 --- a/mythtv/monitor/src/main/java/org/wamblee/mythtv/Application.java +++ b/mythtv/monitor/src/main/java/org/wamblee/mythtv/Application.java @@ -16,19 +16,31 @@ package org.wamblee.mythtv; +import javax.annotation.Resource; +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.MessageProducer; +import javax.jms.ObjectMessage; +import javax.jms.Queue; +import javax.jms.Session; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.quartz.SchedulerException; import org.wamblee.general.BeanKernel; /** - * f + * */ public class Application implements ServletContextListener { private static final Log LOG = LogFactory.getLog(Application.class); + + @Resource(mappedName = "jms/MythtvConnectionFactory") + private ConnectionFactory connectionFactory; + + @Resource(mappedName = "jms/MythtvTimer") + private Queue timerQueue; /* * (non-Javadoc) @@ -37,12 +49,23 @@ public class Application implements ServletContextListener { */ public void contextInitialized(ServletContextEvent arg0) { LOG.info("initializing"); + + // Get application configuration. + ScheduleConfig config = BeanKernel.getBeanFactory().find( + ScheduleConfig.class); + + // Send object message to the timer with the timer interval. try { - BeanKernel.getBeanFactory().find(MonitorScheduler.class) - .initialize(); - } catch (SchedulerException e) { - LOG.error("Error starting scheduler", e); + Connection connection = connectionFactory.createConnection(); + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + ObjectMessage msg = session.createObjectMessage(); + msg.setObject(config.getIntervalSeconds()); + MessageProducer producer = session.createProducer(timerQueue); + producer.send(msg); + } catch (Exception e) { + LOG.fatal("Error sending message", e); } + } /* @@ -52,11 +75,8 @@ public class Application implements ServletContextListener { */ public void contextDestroyed(ServletContextEvent arg0) { LOG.info("terminating"); - try { - BeanKernel.getBeanFactory().find(MonitorScheduler.class) - .shutdown(); - } catch (SchedulerException e) { - LOG.error("Error stopping scheduler", e); - } + + // TODO check if timer will be automatically stopped. + // Empty. } }