1 package org.jmage.pool; 2 3 import org.apache.log4j.Logger; 4 import org.apache.log4j.Priority; 5 6 import java.util.Date; 7 8 9 /*** 10 * A Worker object is a managed resource that is distributed through a pool 11 */ 12 public class Worker { 13 protected static Logger log = Logger.getLogger(Worker.class.getName()); 14 15 protected Object object; 16 protected int jobCount; 17 protected Date lastReport; 18 private static final String JOBCOUNT_ERROR = "unable to calculate proper job count, reset to 0"; 19 20 public Worker() { 21 lastReport = new Date(0); 22 jobCount = 0; 23 } 24 25 public Object getObject() { 26 return object; 27 } 28 29 public void setObject(Object object) { 30 this.object = object; 31 } 32 33 public int getJobCount() { 34 return jobCount; 35 } 36 37 protected void setJobCount(int jobCount) { 38 this.jobCount = jobCount; 39 } 40 41 public void incJobCount() { 42 this.jobCount++; 43 } 44 45 public void decJobCount() { 46 int newCount = this.jobCount - 1; 47 if (newCount >= 0) { 48 this.jobCount = newCount; 49 } else { 50 this.jobCount = 0; 51 if (log.isEnabledFor(Priority.WARN)) log.warn(JOBCOUNT_ERROR); 52 } 53 } 54 55 public Date getLastReport() { 56 return lastReport; 57 } 58 59 public void setLastReport(Date lastReport) { 60 this.lastReport = lastReport; 61 } 62 63 public String toString() { 64 return "[" + this.getClass().getName() + "#" + this.hashCode() + 65 ":object=" + object + 66 ":jobCount=" + jobCount + 67 ":lastReport=" + lastReport + "]"; 68 } 69 }