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.timer;
19 import javax.annotation.Resource;
20 import javax.ejb.MessageDriven;
21 import javax.ejb.Timeout;
22 import javax.ejb.Timer;
23 import javax.ejb.TimerService;
24 import javax.jms.JMSException;
25 import javax.jms.Message;
26 import javax.jms.MessageListener;
27 import javax.jms.ObjectMessage;
28 import javax.jms.StreamMessage;
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32 import org.wamblee.general.BeanKernel;
33 import org.wamblee.io.DirectoryMonitor;
38 @MessageDriven(name = "MythtvTimer")
39 public class TimerBean implements MessageListener {
41 private static final Log LOG = LogFactory.getLog(TimerBean.class);
44 private TimerService _timerService;
47 * Initialization of the time interval. The initialization is done through a
48 * StreamMessage with a single integer containing the time interval to use.
50 public void onMessage(Message aInitMessage) {
51 ObjectMessage msg = (ObjectMessage) aInitMessage;
53 int interval = (Integer)msg.getObject();
54 LOG.info("Initializing timer with interval " + interval + " seconds");
55 _timerService.createTimer(interval*1000, interval*1000, null);
56 } catch (JMSException e) {
57 throw new RuntimeException(e.getMessage());
62 private void timeout(Timer aTimer) {
63 LOG.debug("Timer expired!!!");
65 DirectoryMonitor monitor = BeanKernel.getBeanFactory().find(
66 DirectoryMonitor.class);
68 } catch (Throwable t) {
71 "something terrible happend, ignoring it and hoping for the best",