File Source: TaskLock.java

         /* 
    P/P   *  Method: void readObject(ObjectInputStream)
          * 
          *  Preconditions:
          *    Param_1 != null
          * 
          *  Presumptions:
          *    init'ed(org.apache.openjpa.enhance.PersistenceCapable.DESERIALIZED)
          * 
          *  Postconditions:
          *    Param_0.pcDetachedState == org.apache.openjpa.enhance.PersistenceCapable.DESERIALIZED
          *    (soft) init'ed(Param_0.pcDetachedState)
          */
     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.pojos;
    20  
    21  import java.io.Serializable;
    22  import java.util.Calendar;
    23  import java.util.Date;
    24  import org.apache.roller.util.UUIDGenerator;
    25  
    26  
    27  /**
    28   * Represents locking information about a specific RollerTask.
    29   */
    30  public class TaskLock implements Serializable {
    31      
    32      private String id = UUIDGenerator.generateUUID();
    33      private String name = null;
    34      private Date timeAquired = null;
    35      private int timeLeased = 0;
    36      private Date lastRun = null;
    37      private String clientId = null;
    38      
    39      
             /* 
    P/P       *  Method: void org.apache.roller.weblogger.pojos.TaskLock()
              * 
              *  Postconditions:
              *    this.clientId == null
              *    this.lastRun == null
              *    this.name == null
              *    this.timeAquired == null
              *    init'ed(this.id)
              *    this.timeLeased == 0
              */
    40      public TaskLock() {}
    41      
    42      
    43      /**
    44       * Calculate the next allowed time this task is allowed to run allowed to run.  
    45       * i.e. lastRun + interval
    46       */
    47      public Date getNextAllowedRun(int interval) {
    48          
                 /* 
    P/P           *  Method: Date getNextAllowedRun(int)
                  * 
                  *  Preconditions:
                  *    init'ed(this.lastRun)
                  *    init'ed(this.pcStateManager)
                  *    (soft) pcInheritedFieldCount <= 232-3
                  * 
                  *  Presumptions:
                  *    java.util.Calendar:getInstance(...)@55 != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  *    new Date(getNextAllowedRun#1) num objects <= 1
                  * 
                  *  Test Vectors:
                  *    this.lastRun: Inverse{null}, Addr_Set{null}
                  */
    49          Date previousRun = getLastRun();
    50          if(previousRun == null) {
    51              return new Date(0);
    52          }
    53          
    54          // calculate next run time
    55          Calendar cal = Calendar.getInstance();
    56          cal.setTime(previousRun);
    57          cal.add(Calendar.MINUTE, interval);
    58          
    59          return cal.getTime();
    60      }
    61      
    62      
    63      /**
    64       * Get the time the last/current lease for this lock expires.
    65       * 
    66       * expireTime = timeAcquired + (timeLeased * 60sec/min) - 1 sec
    67       * we remove 1 second to adjust for precision differences
    68       */
    69      public Date getLeaseExpiration() {
    70          
                 /* 
    P/P           *  Method: Date getLeaseExpiration()
                  * 
                  *  Preconditions:
                  *    init'ed(this.pcStateManager)
                  *    init'ed(this.timeAquired)
                  *    init'ed(this.timeLeased)
                  *    (soft) pcInheritedFieldCount <= 232-5
                  * 
                  *  Presumptions:
                  *    java.util.Calendar:getInstance(...)@77 != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  * 
                  *  Test Vectors:
                  *    this.timeAquired: Addr_Set{null}, Inverse{null}
                  */
    71          Date leaseAcquisitionTime = new Date(0);
    72          if(getTimeAquired() != null) {
    73              leaseAcquisitionTime = getTimeAquired();
    74          }
    75          
    76          // calculate lease expiration time
    77          Calendar cal = Calendar.getInstance();
    78          cal.setTime(leaseAcquisitionTime);
    79          cal.add(Calendar.MINUTE, timeLeased);
    80          
    81          return cal.getTime();
    82      }
    83  
    84      //------------------------------------------------------- Good citizenship
    85  
    86      @Override
    87      public String toString() {
                 /* 
    P/P           *  Method: String toString()
                  * 
                  *  Preconditions:
                  *    init'ed(this.id)
                  *    init'ed(this.name)
                  *    init'ed(this.timeAquired)
                  *    init'ed(this.timeLeased)
                  * 
                  *  Postconditions:
                  *    java.lang.StringBuffer:toString(...)._tainted == this.id._tainted | this.name._tainted
                  *    init'ed(java.lang.StringBuffer:toString(...)._tainted)
                  *    return_value == &java.lang.StringBuffer:toString(...)
                  */
    88          StringBuffer buf = new StringBuffer();
    89          buf.append("{");
    90          buf.append(this.id);
    91          buf.append(", ").append(this.name);
    92          buf.append(", ").append(this.timeAquired);
    93          buf.append(", ").append(this.timeLeased);
    94          buf.append("}");
    95          return buf.toString();
    96      }
    97  
    98      @Override
    99      public boolean equals(Object other) {
   100          
                 /* 
    P/P           *  Method: bool equals(Object)
                  * 
                  *  Preconditions:
                  *    (soft) init'ed(other.name)
                  *    (soft) init'ed(other.pcStateManager)
                  *    (soft) pcInheritedFieldCount <= 232-4
                  *    (soft) this.name != null
                  *    (soft) init'ed(this.pcStateManager)
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  * 
                  *  Test Vectors:
                  *    this == other: {0}, {1}
                  */
   101          if(this == other) return true;
   102          if( !(other instanceof TaskLock) ) return false;
   103          
   104          // our natural key, or business key, is our name
   105          final TaskLock that = (TaskLock) other;
   106          return this.getName().equals(that.getName());
   107      }
   108      
   109      @Override
   110      public int hashCode() {
   111          // our natrual key, or business key, is our name
                 /* 
    P/P           *  Method: int hashCode()
                  * 
                  *  Preconditions:
                  *    this.name != null
                  *    init'ed(this.pcStateManager)
                  *    (soft) pcInheritedFieldCount <= 232-4
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   112          return this.getName().hashCode();
   113      }
   114      
   115      
   116      public String getId() {
                 /* 
    P/P           *  Method: String pcgetId()
                  * 
                  *  Preconditions:
                  *    init'ed(this.id)
                  * 
                  *  Postconditions:
                  *    return_value == this.id
                  *    init'ed(return_value)
                  */
   117          return id;
   118      }
   119  
   120      public void setId(String id) {
                 /* 
    P/P           *  Method: void pcsetId(String)
                  * 
                  *  Postconditions:
                  *    this.id == Param_1
                  *    init'ed(this.id)
                  */
   121          this.id = id;
   122      }
   123  
   124      
   125      public String getName() {
                 /* 
    P/P           *  Method: String pcgetName()
                  * 
                  *  Preconditions:
                  *    init'ed(this.name)
                  * 
                  *  Postconditions:
                  *    return_value == this.name
                  *    init'ed(return_value)
                  */
   126          return name;
   127      }
   128  
   129      public void setName(String name) {
                 /* 
    P/P           *  Method: void pcsetName(String)
                  * 
                  *  Postconditions:
                  *    this.name == Param_1
                  *    init'ed(this.name)
                  */
   130          this.name = name;
   131      }
   132  
   133      
   134      public Date getTimeAquired() {
                 /* 
    P/P           *  Method: Date pcgetTimeAquired()
                  * 
                  *  Preconditions:
                  *    init'ed(this.timeAquired)
                  * 
                  *  Postconditions:
                  *    return_value == this.timeAquired
                  *    init'ed(return_value)
                  */
   135          return timeAquired;
   136      }
   137  
   138      public void setTimeAquired(Date timeAquired) {
                 /* 
    P/P           *  Method: void pcsetTimeAquired(Date)
                  * 
                  *  Postconditions:
                  *    this.timeAquired == Param_1
                  *    init'ed(this.timeAquired)
                  */
   139          this.timeAquired = timeAquired;
   140      }
   141  
   142      
   143      public Date getLastRun() {
                 /* 
    P/P           *  Method: Date pcgetLastRun()
                  * 
                  *  Preconditions:
                  *    init'ed(this.lastRun)
                  * 
                  *  Postconditions:
                  *    return_value == this.lastRun
                  *    init'ed(return_value)
                  */
   144          return lastRun;
   145      }
   146  
   147      public void setLastRun(Date lastRun) {
                 /* 
    P/P           *  Method: void pcsetLastRun(Date)
                  * 
                  *  Postconditions:
                  *    this.lastRun == Param_1
                  *    init'ed(this.lastRun)
                  */
   148          this.lastRun = lastRun;
   149      }
   150      
   151      
   152      public int getTimeLeased() {
                 /* 
    P/P           *  Method: int pcgetTimeLeased()
                  * 
                  *  Preconditions:
                  *    init'ed(this.timeLeased)
                  * 
                  *  Postconditions:
                  *    return_value == this.timeLeased
                  *    init'ed(return_value)
                  */
   153          return timeLeased;
   154      }
   155  
   156      public void setTimeLeased(int timeLeased) {
                 /* 
    P/P           *  Method: void pcsetTimeLeased(int)
                  * 
                  *  Postconditions:
                  *    this.timeLeased == Param_1
                  *    init'ed(this.timeLeased)
                  */
   157          this.timeLeased = timeLeased;
   158      }
   159  
   160      
   161      public String getClientId() {
                 /* 
    P/P           *  Method: String pcgetClientId()
                  * 
                  *  Preconditions:
                  *    init'ed(this.clientId)
                  * 
                  *  Postconditions:
                  *    return_value == this.clientId
                  *    init'ed(return_value)
                  */
   162          return clientId;
   163      }
   164  
   165      public void setClientId(String clientId) {
                 /* 
    P/P           *  Method: void pcsetClientId(String)
                  * 
                  *  Postconditions:
                  *    this.clientId == Param_1
                  *    init'ed(this.clientId)
                  */
   166          this.clientId = clientId;
   167      }
   168      
   169  }
+  170  Other Messages








SofCheck Inspector Build Version : 2.18479
TaskLock.java 2009-Jan-02 14:24:52
TaskLock.class 2009-Sep-04 03:12:36