File Source: ContinuousWorkerThread.java
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.weblogger.business.runnable;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24
25 /**
26 * A worker that performs a given job continuously.
27 */
28 public class ContinuousWorkerThread extends WorkerThread {
29
/*
P/P * Method: org.apache.roller.weblogger.business.runnable.ContinuousWorkerThread__static_init
*
* Postconditions:
* init'ed(mLogger)
*/
30 private static Log mLogger = LogFactory.getLog(ContinuousWorkerThread.class);
31
32 // default sleep time is 10 seconds
33 long sleepTime = 10000;
34
35
36 public ContinuousWorkerThread(String id) {
/*
P/P * Method: void org.apache.roller.weblogger.business.runnable.ContinuousWorkerThread(String)
*
* Postconditions:
* this.id == id
* init'ed(this.id)
* this.job == null
* this.sleepTime == 10_000
*/
37 super(id);
38 }
39
40
41 public ContinuousWorkerThread(String id, long sleep) {
/*
P/P * Method: void org.apache.roller.weblogger.business.runnable.ContinuousWorkerThread(String, long)
*
* Postconditions:
* this.id == id
* init'ed(this.id)
* this.job == null
* this.sleepTime == sleep
* init'ed(this.sleepTime)
*/
42 super(id);
43
44 this.sleepTime = sleep;
45 }
46
47
48 public ContinuousWorkerThread(String id, Job job) {
/*
P/P * Method: void org.apache.roller.weblogger.business.runnable.ContinuousWorkerThread(String, Job)
*
* Postconditions:
* this.id == id
* init'ed(this.id)
* this.job == job
* init'ed(this.job)
* this.sleepTime == 10_000
*/
49 super(id, job);
50 }
51
52
53 public ContinuousWorkerThread(String id, Job job, long sleep) {
/*
P/P * Method: void org.apache.roller.weblogger.business.runnable.ContinuousWorkerThread(String, Job, long)
*
* Postconditions:
* this.id == id
* init'ed(this.id)
* this.job == job
* init'ed(this.job)
* this.sleepTime == sleep
* init'ed(this.sleepTime)
*/
54 super(id, job);
55
56 this.sleepTime = sleep;
57 }
58
59
60 /**
61 * Thread execution.
62 *
63 * We run forever. Each time a job completes we sleep for
64 * some amount of time before trying again.
65 *
66 * If we ever get interrupted then we quit.
67 */
68 public void run() {
69
/*
P/P * Method: void run()
*
* Preconditions:
* mLogger != null
* init'ed(this.id)
* (soft) org/apache/roller/weblogger/business/WebloggerFactory.webloggerProvider != null
* (soft) org/apache/roller/weblogger/business/WebloggerFactory.webloggerProvider.webloggerInstance != null
* (soft) org/apache/roller/weblogger/business/WebloggerImpl.log != null
* (soft) org/apache/roller/weblogger/business/runnable/WorkerThread.log != null
* (soft) init'ed(this.job)
* (soft) init'ed(this.sleepTime)
*
* Postconditions:
* possibly_updated(org/apache/roller/weblogger/business/HitCountQueue.instance.queue)
* possibly_updated(this.job.referrer)
*/
70 mLogger.info(this.id+" Started.");
71
72 // run forever
73 while(true) {
74
75 // execute our job
76 super.run();
77
78 // job is done, lets sleep it off for a bit
79 try {
80 mLogger.debug(this.id+" SLEEPING for "+this.sleepTime+" milliseconds ...");
81 this.sleep(this.sleepTime);
82 } catch (InterruptedException e) {
83 mLogger.info(this.id+" INTERRUPT: "+e.getMessage());
84 break;
85 }
86 }
87 }
88
89 }
SofCheck Inspector Build Version : 2.18479
| ContinuousWorkerThread.java |
2009-Jan-02 14:25:24 |
| ContinuousWorkerThread.class |
2009-Sep-04 03:12:31 |