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
+ *
+ *
+ * @author Erik Brakkee
*/
public class Application implements ServletContextListener {
private static final Log LOG = LogFactory.getLog(Application.class);
+
+ @Resource(name = "MythtvConnectionFactory")
+ private ConnectionFactory connectionFactory;
+
+ @Resource(name = "MythtvTimer")
+ private Queue timerQueue;
/*
* (non-Javadoc)
*/
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);
+ LOG.info("Message sent");
+ } catch (Exception e) {
+ LOG.fatal("Error sending message", e);
}
+
}
/*
*/
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.
}
}