(no commit message)
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Tue, 5 Feb 2008 22:11:12 +0000 (22:11 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Tue, 5 Feb 2008 22:11:12 +0000 (22:11 +0000)
14 files changed:
trunk/mythtv/ear/pom.xml
trunk/mythtv/monitor/pom.xml
trunk/mythtv/monitor/src/main/java/org/wamblee/mythtv/Application.java
trunk/mythtv/monitor/src/main/java/org/wamblee/mythtv/MonitorScheduler.java [deleted file]
trunk/mythtv/monitor/src/main/java/org/wamblee/mythtv/PollDirectoryJob.java [deleted file]
trunk/mythtv/monitor/src/main/java/org/wamblee/mythtv/ScheduleConfig.java [new file with mode: 0644]
trunk/mythtv/pom.xml
trunk/mythtv/timer/pom.xml [new file with mode: 0644]
trunk/mythtv/timer/src/main/java/org/wamblee/timer/TimerBean.java [new file with mode: 0644]
trunk/mythtv/timer/src/main/resources/META-INF/ejb-jar.xml [new file with mode: 0644]
trunk/mythtv/war/pom.xml
trunk/mythtv/war/src/main/resources/org.wamblee.mythtv.application.xml
trunk/mythtv/war/src/webapp/WEB-INF/sun-web.xml [new file with mode: 0644]
trunk/mythtv/war/src/webapp/WEB-INF/web.xml

index da812ad3ff3710a955d9c7f53ff0e67afb616633..8174614155b1d1336d7fa7d9bf51e44415a4bfcb 100644 (file)
         <artifactId>wamblee-mythtv-monitor</artifactId>
         <version>${project.version}</version>
     </dependency>
+    <dependency>
+        <groupId>org.wamblee</groupId>
+        <artifactId>wamblee-mythtv-timer</artifactId>
+        <version>${project.version}</version>
+        <type>ejb</type>
+    </dependency>
   </dependencies>
 
   <build>
index 658d67240a9fec7f220184ad1ac01944f0d7c7c1..52333044dfc63826303fcc45569362afdc177c3e 100644 (file)
         <groupId>org.wamblee</groupId>
         <artifactId>wamblee-support</artifactId>
     </dependency>
-       <dependency>
-         <groupId>quartz</groupId>
-         <artifactId>quartz</artifactId>
-       </dependency>
        <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>servlet-api</artifactId>
       <artifactId>log4j</artifactId>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>javaee</groupId>
+      <artifactId>javaee-api</artifactId>
+    </dependency>
   </dependencies>
 
 </project>
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. 
     }
 }
diff --git a/trunk/mythtv/monitor/src/main/java/org/wamblee/mythtv/MonitorScheduler.java b/trunk/mythtv/monitor/src/main/java/org/wamblee/mythtv/MonitorScheduler.java
deleted file mode 100644 (file)
index 321a1c2..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright 2006 the original author or authors.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */ 
-
-package org.wamblee.mythtv;
-
-import java.io.File;
-import java.util.Date;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.quartz.JobDetail;
-import org.quartz.Scheduler;
-import org.quartz.SchedulerException;
-import org.quartz.SchedulerFactory;
-import org.quartz.Trigger;
-import org.quartz.TriggerUtils;
-import org.quartz.impl.StdSchedulerFactory;
-
-/**
- * 
- */
-public class MonitorScheduler {
-    
-    private static final Log LOG = LogFactory.getLog(MonitorScheduler.class);
-    private static final String JOB_NAME = "vcrmonitor";
-    private static final String TRIGGER_NAME = "trigger";
-    
-    private Scheduler _scheduler; 
-    private int _intervalSeconds;
-
-    public MonitorScheduler(int aInterval) throws SchedulerException { 
-        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
-        _scheduler = schedulerFactory.getScheduler();
-        _intervalSeconds = aInterval; 
-    }
-    
-    public void initialize() throws SchedulerException {
-        LOG.info("Starting scheduler");
-        _scheduler.start();
-
-        JobDetail jobDetail = new JobDetail(JOB_NAME, null, PollDirectoryJob.class);
-        Trigger trigger = TriggerUtils.makeSecondlyTrigger(_intervalSeconds);
-        //trigger.setStartTime(TriggerUtils.getEvenHourDate(new Date()));
-        trigger.setStartTime(new Date());
-        trigger.setName(TRIGGER_NAME);
-
-        _scheduler.scheduleJob(jobDetail, trigger);
-    }
-    
-    public void shutdown() throws SchedulerException {
-        LOG.info("Stopping scheduler");
-        _scheduler.shutdown(); 
-    }
-}
diff --git a/trunk/mythtv/monitor/src/main/java/org/wamblee/mythtv/PollDirectoryJob.java b/trunk/mythtv/monitor/src/main/java/org/wamblee/mythtv/PollDirectoryJob.java
deleted file mode 100644 (file)
index e75ed11..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright 2006 the original author or authors.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.wamblee.mythtv;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.quartz.JobExecutionContext;
-import org.quartz.JobExecutionException;
-import org.quartz.StatefulJob;
-import org.wamblee.general.BeanKernel;
-import org.wamblee.io.DirectoryMonitor;
-
-/**
- * 
- */
-public class PollDirectoryJob implements StatefulJob {
-
-    private static final Log LOG = LogFactory.getLog(PollDirectoryJob.class);
-
-    public PollDirectoryJob() {
-        // Empty
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.quartz.Job#execute(org.quartz.JobExecutionContext)
-     */
-    public void execute(JobExecutionContext aContext)
-            throws JobExecutionException {
-        try {
-            DirectoryMonitor monitor = BeanKernel.getBeanFactory().find(
-                    DirectoryMonitor.class);
-            monitor.poll();
-        } catch (Throwable t) {
-            LOG
-                    .error(
-                            "something terrible happend, ignoring it and hoping for the best",
-                            t);
-        }
-    }
-
-}
diff --git a/trunk/mythtv/monitor/src/main/java/org/wamblee/mythtv/ScheduleConfig.java b/trunk/mythtv/monitor/src/main/java/org/wamblee/mythtv/ScheduleConfig.java
new file mode 100644 (file)
index 0000000..3478ff4
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2006 the original author or authors.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+
+package org.wamblee.mythtv;
+
+/**
+ * 
+ */
+public class ScheduleConfig {
+    
+    private int _intervalSeconds; 
+    
+    public ScheduleConfig(int aIntervalSeconds) { 
+        _intervalSeconds = aIntervalSeconds; 
+    }
+    
+    /**
+     * @return the intervalSeconds
+     */
+    public int getIntervalSeconds() {
+        return _intervalSeconds;
+    }
+
+}
index 8765147d7bcb21c10cecbcd9a94c1a6cab66fe06..fd3ed9a1e26f1e83dec7a9c0b909fc9a2f4c533a 100644 (file)
@@ -18,6 +18,7 @@
   <modules>
     <module>monitor</module>
     <module>war</module>
+    <module>timer</module>
     <module>ear</module>
   </modules>
   
diff --git a/trunk/mythtv/timer/pom.xml b/trunk/mythtv/timer/pom.xml
new file mode 100644 (file)
index 0000000..bcd1ef8
--- /dev/null
@@ -0,0 +1,30 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <parent>
+    <groupId>org.wamblee</groupId>
+    <artifactId>wamblee-mythtv</artifactId>
+    <version>0.2-SNAPSHOT</version>
+  </parent>
+
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.wamblee</groupId>
+  <artifactId>wamblee-mythtv-timer</artifactId>
+  <packaging>jar</packaging>
+  <name>wamblee.org mythtv directory monitor TIMER</name>
+  <url>http://wamblee.org</url>
+  
+  <dependencies>
+    <dependency>
+        <groupId>org.wamblee</groupId>
+        <artifactId>wamblee-mythtv-monitor</artifactId>
+        <version>${project.version}</version>
+    </dependency>
+    <dependency>
+        <groupId>javaee</groupId>
+        <artifactId>javaee-api</artifactId>
+    </dependency>
+  </dependencies>
+
+</project>
diff --git a/trunk/mythtv/timer/src/main/java/org/wamblee/timer/TimerBean.java b/trunk/mythtv/timer/src/main/java/org/wamblee/timer/TimerBean.java
new file mode 100644 (file)
index 0000000..b7ee2bf
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2006 the original author or authors.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.wamblee.timer;
+
+import javax.annotation.Resource;
+import javax.ejb.MessageDriven;
+import javax.ejb.Timeout;
+import javax.ejb.Timer;
+import javax.ejb.TimerService;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.ObjectMessage;
+import javax.jms.StreamMessage;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wamblee.general.BeanKernel;
+import org.wamblee.io.DirectoryMonitor;
+
+/**
+ * 
+ */
+@MessageDriven(mappedName = "jms/MythtvTimer")
+public class TimerBean implements MessageListener {
+    
+    private static final Log LOG = LogFactory.getLog(TimerBean.class);
+    
+    @Resource
+    private TimerService _timerService; 
+
+    /**
+     * Initialization of the time interval. The initialization is done through a
+     * StreamMessage with a single integer containing the time interval to use.
+     */
+    public void onMessage(Message aInitMessage) {
+        ObjectMessage msg = (ObjectMessage) aInitMessage;
+        try {
+            int interval = (Integer)msg.getObject();
+            LOG.info("Initializing timer with interval " + interval + " seconds");
+            _timerService.createTimer(interval*1000, interval*1000, null);
+        } catch (JMSException e) {
+            throw new RuntimeException(e.getMessage());
+        }
+    }
+  
+    @Timeout
+    private void timeout(Timer aTimer) {
+        LOG.debug("Timer expired!!!");
+        try {
+            DirectoryMonitor monitor = BeanKernel.getBeanFactory().find(
+                    DirectoryMonitor.class);
+            monitor.poll();
+        } catch (Throwable t) {
+            LOG
+                    .error(
+                            "something terrible happend, ignoring it and hoping for the best",
+                            t);
+        }
+    }
+}
diff --git a/trunk/mythtv/timer/src/main/resources/META-INF/ejb-jar.xml b/trunk/mythtv/timer/src/main/resources/META-INF/ejb-jar.xml
new file mode 100644 (file)
index 0000000..b3c04cf
--- /dev/null
@@ -0,0 +1,21 @@
+<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+    http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
+    version="3.0">
+    
+    <!-- enterprise-beans>
+        <message-driven>
+           <ejb-name>TimerBean</ejb-name>
+            <ejb-class>org.wamblee.timer.TimerBean</ejb-class>
+            <message-destination-link>jms/MythtvTimer</message-destination-link>
+        </message-driven>
+    </enterprise-beans>
+    <assembly-descriptor>
+        <message-destination>
+            <message-destination-name>jms/MythtvTimer</message-destination-name>
+            <mapped-name>jms/MythtvTimer</mapped-name>
+        </message-destination>
+    </assembly-descriptor -->
+    
+</ejb-jar>
\ No newline at end of file
index 30c9c477619da42dd7b792370ec786861ca7abac..d34be6585b18fa6e44934cc8b53278f3f7d1fe3e 100644 (file)
         <artifactId>wamblee-mythtv-monitor</artifactId>
         <version>${project.version}</version>
     </dependency>
+    <dependency>
+      <groupId>javaee</groupId>
+      <artifactId>javaee-api</artifactId>
+    </dependency>
   </dependencies>
 
   <build>
index 35681dc7cac616ba77c083329372eb088ce5db42..1017fffaece98c48766287cb24f1c536523c0666 100644 (file)
@@ -33,8 +33,8 @@
         <constructor-arg><ref local="org.wamblee.mythtv.LinkStructure"/></constructor-arg>
     </bean>
     
-    <bean id="org.wamblee.mythtv.MonitorScheduler" class="org.wamblee.mythtv.MonitorScheduler">
-        <constructor-arg><value>${org.wamblee.mythtv.pollinterval}</value></constructor-arg>    
+    <bean id="org.wamblee.mythtv.ScheduleConfig" class="org.wamblee.mythtv.ScheduleConfig">
+        <constructor-arg><value>${org.wamblee.mythtv.pollinterval}</value></constructor-arg>
     </bean>
 
 </beans> 
diff --git a/trunk/mythtv/war/src/webapp/WEB-INF/sun-web.xml b/trunk/mythtv/war/src/webapp/WEB-INF/sun-web.xml
new file mode 100644 (file)
index 0000000..e7b2c10
--- /dev/null
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 
+Servlet 2.5//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd">
+
+
+<sun-web-app>
+    
+    <!-- resource-ref>
+        <res-ref-name>MythtvConnectionFactory</res-ref-name>
+        <jndi-name>jms/MythtvConnectionFactory</jndi-name>
+    </resource-ref>
+    
+    <resource-ref>
+        <res-ref-name>MythtvTimer</res-ref-name>
+        <jndi-name>jms/MythtvTimer</jndi-name>
+    </resource-ref -->
+  
+</sun-web-app>
\ No newline at end of file
index d6961ea784461de4313444d528b4374ceae140a2..eb64edc6f6cd121800bc07d79de84136ca05e048 100644 (file)
@@ -1,12 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<web-app version="2.4
-       xmlns="http://java.sun.com/xml/ns/j2ee" 
+<web-app version="2.5
+       xmlns="http://java.sun.com/xml/ns/javaee" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
-       xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
-       http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
+       http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 
     <listener>
         <listener-class>org.wamblee.mythtv.Application</listener-class>
     </listener>
+    
+    <!-- resource-ref>
+        <res-ref-name>MythtvConnectionFactory</res-ref-name>
+        <res-type>javax.jms.ConnectionFactory</res-type>
+        <res-auth>Container</res-auth>
+        <res-sharing-scope>Shareable</res-sharing-scope>
+    </resource-ref -->
+    
+    <!-- message-destination-ref>
+        <message-destination-ref-name>jms/MythtvTimer</message-destination-ref-name>
+        <message-destination-type>javax.jms.Queue</message-destination-type>
+        <message-destination-usage>Produces</message-destination-usage>
+        <message-destination-link>Timer</message-destination-link>
+    </message-destination-ref -->
    
 </web-app>