KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > presentation > pings > PingQueueTask


1 /*
2  * Copyright (c) 2005
3  * Anil R. Gangolli. All rights reserved.
4  *
5  * Distributed with the Roller Weblogger Project under the terms of the Roller Software
6  * License
7  */

8
9 package org.roller.presentation.pings;
10
11 import org.apache.commons.logging.Log;
12 import org.apache.commons.logging.LogFactory;
13 import org.roller.RollerException;
14 import org.roller.model.Roller;
15 import org.roller.model.RollerFactory;
16 import org.roller.presentation.RollerContext;
17
18 import java.util.TimerTask JavaDoc;
19
20 /**
21  * Task for processing the ping queue at fixed intervals. This is set up during context initialization by {@link
22  * RollerContext}. The queue processing interval is currently set from the configuration {@link
23  * org.roller.config.PingConfig} at startup time only.
24  */

25 public class PingQueueTask extends TimerTask JavaDoc
26 {
27     private static final Log logger = LogFactory.getLog(PingQueueTask.class);
28
29     // The periodic interval (in minutes) at which we are configured to run
30
long intervalMins;
31
32     /**
33      * Initialize the task.
34      *
35      * @param rc the Roller context.
36      * @throws RollerException
37      */

38     public void init(RollerContext rc, long intervalMins) throws RollerException
39     {
40         PingQueueProcessor.init(rc);
41         this.intervalMins = intervalMins;
42     }
43
44     /**
45      * Get the task's configured interval (in minutes).
46      *
47      * @return the tasks configured interval (in minutes).
48      */

49     public long getIntervalMins()
50     {
51         return intervalMins;
52     }
53
54     /**
55      * Run the task once.
56      */

57     public void run()
58     {
59         // Call the ping queue processor to process the queue
60
Roller roller = null;
61         try
62         {
63             roller = RollerFactory.getRoller();
64             roller.begin();
65             PingQueueProcessor.getInstance().processQueue();
66             roller.commit();
67         }
68         catch (RollerException e)
69         {
70             // This is probably duplicate logging. May want to eliminate it, but should be rare.
71
logger.error("Error while processing ping queuer", e);
72         }
73         finally
74         {
75             if (roller != null) roller.release();
76         }
77     }
78 }
79
Popular Tags