1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.mobility.weather.dao;
17
18 import org.kuali.mobility.weather.service.WeatherService;
19
20 public class WeatherInitBean {
21
22 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(WeatherInitBean.class);
23
24 private WeatherService weatherService;
25 private int minutesToRefresh;
26
27 private static Thread backgroundThread = null;
28
29 public void init() {
30 backgroundThread = new Thread(new BackgroundThread());
31 backgroundThread.setDaemon(true);
32 backgroundThread.start();
33 }
34
35 public void cleanup() {
36 LOG.info("Cleaning up weather.");
37 }
38
39 public WeatherService getWeatherService() {
40 return weatherService;
41 }
42
43 public void setWeatherService(WeatherService weatherService) {
44 this.weatherService = weatherService;
45 }
46
47 public int getMinutesToRefresh() {
48 return minutesToRefresh;
49 }
50
51 public void setMinutesToRefresh(int minutesToRefresh) {
52 this.minutesToRefresh = minutesToRefresh;
53 }
54
55 private class BackgroundThread implements Runnable {
56
57 public void run() {
58 while (true) {
59 try {
60 weatherService.refreshWeather();
61 try {
62 Thread.sleep(1000 * 60 * getMinutesToRefresh());
63 } catch (InterruptedException e) {
64 LOG.error(e.getMessage(), e);
65 }
66 } catch (Exception e) {
67 LOG.error(e.getMessage(), e);
68 }
69 }
70 }
71
72 }
73
74 }