00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 package de.picana.control;
00014
00015 import de.picana.logging.*;
00016
00017 import java.util.*;
00018
00019
00026 public abstract class Task {
00027
00028 protected static final Integer ONE = new Integer(1);
00029 protected static final Random rand = new Random();
00030
00032 protected String LOGSRC;
00034 protected ParameterSet params;
00036 protected Logger logger;
00037
00038
00040 public Task() {
00041 }
00042
00049 public void init(ParameterSet params, Logger logger) {
00050 this.LOGSRC = getLogName();
00051 this.params = params;
00052 this.logger = logger;
00053 logger.info(LOGSRC, "Initialized.");
00054 };
00055
00057 public abstract void start() throws TaskException;
00058
00060 public abstract void stop();
00061
00063 public abstract void pause();
00064
00066 public abstract void resume();
00067
00068 public String getLogName() {
00069 String clname = this.getClass().getName();
00070 return clname.substring(10, clname.length());
00071 }
00072
00073 public static String getTimeString(long millis) {
00074
00075 long days = millis / 86400000;
00076 long days_rest = millis % 86400000;
00077 long hours = days_rest / 3600000;
00078 long hours_rest = days_rest % 3600000;
00079 long minutes = hours_rest / 60000;
00080 long minutes_rest = hours_rest % 60000;
00081 long seconds = minutes_rest / 1000;
00082 long millisecs = minutes_rest % 1000;
00083
00084 String timestr = "";
00085
00086 timestr += days + "d " + hours + "h " + minutes + "m " + seconds + "s " + millisecs + "ms";
00087
00088 return timestr;
00089 }
00090 }