KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ui > core > tasks > TurnoverReferersTask


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */

18 /*
19  * Created on Aug 16, 2003
20  */

21 package org.apache.roller.ui.core.tasks;
22
23 import java.util.TimerTask JavaDoc;
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.roller.RollerException;
27 import org.apache.roller.model.RefererManager;
28 import org.apache.roller.model.Roller;
29 import org.apache.roller.model.RollerFactory;
30 import org.apache.roller.model.ScheduledTask;
31
32
33 /**
34  * Reset referer counts.
35  *
36  * @author Allen Gilliland
37  */

38 public class TurnoverReferersTask extends TimerTask JavaDoc implements ScheduledTask {
39     
40     private static Log mLogger = LogFactory.getLog(TurnoverReferersTask.class);
41     
42     
43     /**
44      * Task init.
45      */

46     public void init(Roller roller, String JavaDoc realPath) throws RollerException {
47         mLogger.debug("initing");
48     }
49     
50     
51     /**
52      * Execute the task.
53      */

54     public void run() {
55         
56         mLogger.info("task started");
57         
58         try {
59             Roller roller = RollerFactory.getRoller();
60             roller.getRefererManager().clearReferrers();
61             roller.flush();
62             roller.release();
63             mLogger.info("task completed");
64             
65         } catch (RollerException e) {
66             mLogger.error("Error while checking for referer turnover", e);
67         } catch (Exception JavaDoc ee) {
68             mLogger.error("unexpected exception", ee);
69         }
70
71
72     }
73     
74     
75     /**
76      * Main method so that this task may be run from outside the webapp.
77      */

78     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
79         try {
80             TurnoverReferersTask task = new TurnoverReferersTask();
81             task.init(null, null);
82             task.run();
83             System.exit(0);
84         } catch (RollerException ex) {
85             ex.printStackTrace();
86             System.exit(-1);
87         }
88     }
89     
90 }
Popular Tags