moved socketproxy to https://wamblee.org/svn/public/socketproxy
[utils] / mythtv / monitor / src / main / java / org / wamblee / mythtv / Application.java
index 01d030262d5bb1791e8d2865b4ebde4c42e7b084..7cc13f87d3b6b27045528aac070e5ba562118834 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
+ * 
+ *
+ * @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)
@@ -37,12 +51,24 @@ 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);
+            LOG.info("Message sent");
+        } catch (Exception e) {
+            LOG.fatal("Error sending message", e);
         }
+        
     }
 
     /*
@@ -52,11 +78,7 @@ 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);
-        }
+        
+        // Empty. 
     }
 }