(no commit message)
[utils] / mythtv / monitor / src / main / java / org / wamblee / mythtv / Application.java
index 01d030262d5bb1791e8d2865b4ebde4c42e7b084..539557516fac667fb932507d563db5bd834197a8 100644 (file)
 
 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. 
     }
 }