| 1 24 package org.riotfamily.riot.job.support; 25 26 import org.riotfamily.riot.job.Job; 27 import org.riotfamily.riot.job.JobContext; 28 import org.riotfamily.riot.job.JobDescription; 29 30 public class TestJob implements Job { 31 32 private String name = "Test Job"; 33 34 private String description; 35 36 private int steps = 50; 37 38 private long delay = 1000; 39 40 private int errorAfter = 0; 41 42 private boolean reportProgress = true; 43 44 private int step = 1; 45 46 public void setName(String name) { 47 this.name = name; 48 } 49 50 public void setDescription(String description) { 51 this.description = description; 52 } 53 54 public void setSteps(int steps) { 55 this.steps = steps; 56 } 57 58 public void setDelay(long delay) { 59 this.delay = delay; 60 } 61 62 public void setReportProgress(boolean reportProgress) { 63 this.reportProgress = reportProgress; 64 } 65 66 public void setErrorAfter(int errorAfter) { 67 this.errorAfter = errorAfter; 68 } 69 70 public JobDescription setup(String objectId) { 71 return new JobDescription(name, description, reportProgress ? steps : 0); 72 } 73 74 public void execute(JobContext context) { 75 while (step <= steps) { 76 context.logInfo("Performing step " + step++); 77 if (errorAfter > 0 && step % errorAfter == 0) { 78 context.logError("A random error occured in step " + step); 79 } 80 try { 81 Thread.sleep(delay); 82 } 83 catch (InterruptedException e) { 84 } 85 context.stepCompleted(); 86 } 87 } 88 89 public boolean isConcurrent() { 90 return false; 91 } 92 93 public boolean isRepeatable() { 94 return true; 95 } 96 97 public void tearDown(String objectId) { 98 step = 1; 99 } 100 101 } 102 | Popular Tags |