2 * Copyright 2006 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.wamblee.mythtv;
19 import javax.annotation.Resource;
20 import javax.jms.Connection;
21 import javax.jms.ConnectionFactory;
22 import javax.jms.MessageProducer;
23 import javax.jms.ObjectMessage;
24 import javax.jms.Queue;
25 import javax.jms.Session;
26 import javax.servlet.ServletContextEvent;
27 import javax.servlet.ServletContextListener;
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.wamblee.general.BeanKernel;
36 public class Application implements ServletContextListener {
37 private static final Log LOG = LogFactory.getLog(Application.class);
39 @Resource(name = "MythtvConnectionFactory")
40 private ConnectionFactory connectionFactory;
42 @Resource(name = "MythtvTimer")
43 private Queue timerQueue;
48 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
50 public void contextInitialized(ServletContextEvent arg0) {
51 LOG.info("initializing");
53 // Get application configuration.
54 ScheduleConfig config = BeanKernel.getBeanFactory().find(
55 ScheduleConfig.class);
57 // Send object message to the timer with the timer interval.
59 Connection connection = connectionFactory.createConnection();
60 Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
61 ObjectMessage msg = session.createObjectMessage();
62 msg.setObject(config.getIntervalSeconds());
63 MessageProducer producer = session.createProducer(timerQueue);
65 } catch (Exception e) {
66 LOG.fatal("Error sending message", e);
74 * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
76 public void contextDestroyed(ServletContextEvent arg0) {
77 LOG.info("terminating");
79 // TODO check if timer will be automatically stopped.