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 * @author Erik Brakkee
38 public class Application implements ServletContextListener {
39 private static final Log LOG = LogFactory.getLog(Application.class);
41 @Resource(name = "MythtvConnectionFactory")
42 private ConnectionFactory connectionFactory;
44 @Resource(name = "MythtvTimer")
45 private Queue timerQueue;
50 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
52 public void contextInitialized(ServletContextEvent arg0) {
53 LOG.info("initializing");
55 // Get application configuration.
56 ScheduleConfig config = BeanKernel.getBeanFactory().find(
57 ScheduleConfig.class);
59 // Send object message to the timer with the timer interval.
61 Connection connection = connectionFactory.createConnection();
62 Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
63 ObjectMessage msg = session.createObjectMessage();
64 msg.setObject(config.getIntervalSeconds());
65 MessageProducer producer = session.createProducer(timerQueue);
67 LOG.info("Message sent");
68 } catch (Exception e) {
69 LOG.fatal("Error sending message", e);
77 * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
79 public void contextDestroyed(ServletContextEvent arg0) {
80 LOG.info("terminating");