KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ui > core > pings > PingQueueTask


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 package org.apache.roller.ui.core.pings;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.apache.roller.RollerException;
24 import org.apache.roller.model.Roller;
25 import org.apache.roller.model.RollerFactory;
26
27 import java.util.TimerTask JavaDoc;
28
29 /**
30  * Task for processing the ping queue at fixed intervals. This is set up during context initialization by {@link
31  * RollerContext}. The queue processing interval is currently set from the configuration {@link
32  * org.apache.roller.config.PingConfig} at startup time only.
33  *
34  * @author <a HREF="mailto:anil@busybuddha.org">Anil Gangolli</a>
35  */

36 public class PingQueueTask extends TimerTask JavaDoc {
37     private static final Log logger = LogFactory.getLog(PingQueueTask.class);
38
39     // The periodic interval (in minutes) at which we are configured to run
40
long intervalMins;
41
42     /**
43      * Initialize the task.
44      *
45      * @throws RollerException
46      */

47     public void init(long intervalMins) throws RollerException {
48         PingQueueProcessor.init();
49         this.intervalMins = intervalMins;
50     }
51
52     /**
53      * Get the task's configured interval (in minutes).
54      *
55      * @return the tasks configured interval (in minutes).
56      */

57     public long getIntervalMins() {
58         return intervalMins;
59     }
60
61     /**
62      * Run the task once.
63      */

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