File Source: WorkerThread.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  import org.apache.roller.weblogger.business.Weblogger;
    24  import org.apache.roller.weblogger.business.WebloggerFactory;
    25  
    26  
    27  /**
    28   * A generic worker thread that knows how execute a Job.
    29   */
    30  public class WorkerThread extends Thread {
    31      
             /* 
    P/P       *  Method: org.apache.roller.weblogger.business.runnable.WorkerThread__static_init
              * 
              *  Postconditions:
              *    init'ed(log)
              */
    32      private static Log log = LogFactory.getLog(WorkerThread.class);
    33      
    34      String id = null;
    35      Job job = null;
    36      
    37      
    38      /**
    39       * A simple worker.
    40       */
    41      public WorkerThread(String id) {
                 /* 
    P/P           *  Method: void org.apache.roller.weblogger.business.runnable.WorkerThread(String)
                  * 
                  *  Postconditions:
                  *    this.id == id
                  *    init'ed(this.id)
                  *    this.job == null
                  */
    42          super(id);
    43          this.id = id;
    44      }
    45      
    46      
    47      /**
    48       * Start off with a job to do.
    49       */
    50      public WorkerThread(String id, Job job) {
                 /* 
    P/P           *  Method: void org.apache.roller.weblogger.business.runnable.WorkerThread(String, Job)
                  * 
                  *  Postconditions:
                  *    this.id == id
                  *    init'ed(this.id)
                  *    this.job == job
                  *    init'ed(this.job)
                  */
    51          super(id);
    52          this.id = id;
    53          this.job = job;
    54      }
    55      
    56      
    57      /**
    58       * Thread execution.
    59       *
    60       * We just execute the job we were given if it's non-null.
    61       */
    62      public void run() {
    63          
    64          // we only run once
                 /* 
    P/P           *  Method: void run()
                  * 
                  *  Preconditions:
                  *    init'ed(this.job)
                  *    (soft) log != null
                  *    (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) init'ed(this.id)
                  * 
                  *  Presumptions:
                  *    java.lang.Object:getClass(...)@71 != null
                  *    roller.autoPingManager != null
                  *    roller.bookmarkManager != null
                  *    roller.fileManager != null
                  *    roller.pingQueueManager != null
                  *    ...
                  * 
                  *  Postconditions:
                  *    org/apache/roller/weblogger/business/HitCountQueue.instance.queue == old org/apache/roller/weblogger/business/HitCountQueue.instance.queue
                  *    this.job.referrer == old this.job.referrer
                  * 
                  *  Test Vectors:
                  *    this.job: Addr_Set{null}, Inverse{null}
                  */
    65          if (this.job != null) {
    66              // process job
    67              try {
    68                  this.job.execute();
    69              } catch(Throwable t) {
    70                  // oops
    71                  log.error("Error executing job. "+
    72                          "Worker = "+this.id+", "+
    73                          "Job = "+this.job.getClass().getName(), t);
    74              }
    75              
    76              // since this is a thread we have to make sure that we tidy up ourselves
    77              Weblogger roller = WebloggerFactory.getWeblogger();
    78              roller.release();
    79          }
    80          
    81      }
    82      
    83      
    84      /**
    85       * Set the job for this worker.
    86       */
    87      public void setJob(Job newJob) {
                 /* 
    P/P           *  Method: void setJob(Job)
                  * 
                  *  Preconditions:
                  *    log != null
                  *    newJob != null
                  * 
                  *  Presumptions:
                  *    java.lang.Object:getClass(...)@88 != null
                  * 
                  *  Postconditions:
                  *    this.job == newJob
                  *    this.job != null
                  */
    88          log.debug("NEW JOB: "+newJob.getClass().getName());
    89          
    90          // set the job
    91          this.job = newJob;
    92      }
    93      
    94  }








SofCheck Inspector Build Version : 2.18479
WorkerThread.java 2009-Jan-02 14:24:46
WorkerThread.class 2009-Sep-04 03:12:30