Project cleanup pre merge.
This commit is contained in:
+107
-105
@@ -17,135 +17,137 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
* Provides mandatory base implementation for all 'Job's'.
|
||||
*
|
||||
* @author
|
||||
*
|
||||
* @author
|
||||
*/
|
||||
public abstract class AbstractJob implements Runnable {
|
||||
|
||||
public enum JobRunStatus {
|
||||
CREATED, RUNNING, FINISHED;
|
||||
};
|
||||
private static final String DEFAULT_WORKERID = "UNPROCESSED_JOB";
|
||||
|
||||
public enum JobCompletionStatus {
|
||||
NOTCOMPLETEDYET, SUCCESS, SUCCESSWITHERRORS, FAIL;
|
||||
};
|
||||
;
|
||||
private final AtomicReference<String> workerID;
|
||||
|
||||
/**
|
||||
* Keep fields private. All access through getters n setters for Thread
|
||||
* Safety.
|
||||
*/
|
||||
private JobRunStatus runStatus;
|
||||
private JobCompletionStatus completeStatus;
|
||||
private UUID uuid = null;
|
||||
;
|
||||
/**
|
||||
* Keep fields private. All access through getters n setters for Thread
|
||||
* Safety.
|
||||
*/
|
||||
private JobRunStatus runStatus;
|
||||
private JobCompletionStatus completeStatus;
|
||||
private UUID uuid = null;
|
||||
private long submitTime = 0L;
|
||||
private long startTime = 0L;
|
||||
private long stopTime = 0L;
|
||||
|
||||
private final AtomicReference<String> workerID;
|
||||
private static final String DEFAULT_WORKERID = "UNPROCESSED_JOB";
|
||||
public AbstractJob() {
|
||||
//Tests against DEFAULT_WORKERID to ensure single execution
|
||||
this.workerID = new AtomicReference<>(DEFAULT_WORKERID);
|
||||
this.runStatus = JobRunStatus.RUNNING;
|
||||
this.completeStatus = JobCompletionStatus.NOTCOMPLETEDYET;
|
||||
this.uuid = UUID.randomUUID();
|
||||
}
|
||||
|
||||
private long submitTime = 0L;
|
||||
private long startTime = 0L;
|
||||
private long stopTime = 0L;
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
public AbstractJob() {
|
||||
//Tests against DEFAULT_WORKERID to ensure single execution
|
||||
this.workerID = new AtomicReference<>(DEFAULT_WORKERID);
|
||||
this.runStatus = JobRunStatus.RUNNING;
|
||||
this.completeStatus = JobCompletionStatus.NOTCOMPLETEDYET;
|
||||
this.uuid = UUID.randomUUID();
|
||||
}
|
||||
if (workerID.get().equals(DEFAULT_WORKERID)) {
|
||||
Logger.warn("FIX ME! Job ran through 'run()' directly. Use executeJob(String) instead.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
this.markStartRunTime();
|
||||
|
||||
if(workerID.get().equals(DEFAULT_WORKERID)) {
|
||||
Logger.warn("FIX ME! Job ran through 'run()' directly. Use executeJob(String) instead.");
|
||||
}
|
||||
|
||||
this.markStartRunTime();
|
||||
this.setRunStatus(JobRunStatus.RUNNING);
|
||||
try {
|
||||
this.doJob();
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
this.setRunStatus(JobRunStatus.RUNNING);
|
||||
try {
|
||||
this.doJob();
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
this.setRunStatus(JobRunStatus.FINISHED);
|
||||
this.setRunStatus(JobRunStatus.FINISHED);
|
||||
|
||||
this.markStopRunTime();
|
||||
}
|
||||
this.markStopRunTime();
|
||||
}
|
||||
|
||||
protected abstract void doJob();
|
||||
protected abstract void doJob();
|
||||
|
||||
public void executeJob(String threadName) {
|
||||
this.workerID.set(threadName);
|
||||
this.run();
|
||||
}
|
||||
|
||||
protected void setRunStatus(JobRunStatus status) {
|
||||
synchronized (this.runStatus) {
|
||||
this.runStatus = status;
|
||||
}
|
||||
}
|
||||
public void executeJob(String threadName) {
|
||||
this.workerID.set(threadName);
|
||||
this.run();
|
||||
}
|
||||
|
||||
public JobRunStatus getRunStatus() {
|
||||
synchronized (this.runStatus) {
|
||||
return runStatus;
|
||||
}
|
||||
}
|
||||
public JobRunStatus getRunStatus() {
|
||||
synchronized (this.runStatus) {
|
||||
return runStatus;
|
||||
}
|
||||
}
|
||||
|
||||
protected void setCompletionStatus(JobCompletionStatus status) {
|
||||
synchronized (this.completeStatus) {
|
||||
this.completeStatus = status;
|
||||
}
|
||||
}
|
||||
protected void setRunStatus(JobRunStatus status) {
|
||||
synchronized (this.runStatus) {
|
||||
this.runStatus = status;
|
||||
}
|
||||
}
|
||||
|
||||
public JobCompletionStatus getCompletionStatus() {
|
||||
synchronized (this.completeStatus) {
|
||||
return completeStatus;
|
||||
}
|
||||
}
|
||||
public JobCompletionStatus getCompletionStatus() {
|
||||
synchronized (this.completeStatus) {
|
||||
return completeStatus;
|
||||
}
|
||||
}
|
||||
|
||||
protected void setJobId(UUID id) {
|
||||
synchronized (this.uuid) {
|
||||
this.uuid = id;
|
||||
}
|
||||
}
|
||||
protected void setCompletionStatus(JobCompletionStatus status) {
|
||||
synchronized (this.completeStatus) {
|
||||
this.completeStatus = status;
|
||||
}
|
||||
}
|
||||
|
||||
public UUID getJobId() {
|
||||
synchronized (this.uuid) {
|
||||
return uuid;
|
||||
}
|
||||
}
|
||||
|
||||
public String getWorkerID() {
|
||||
return workerID.get();
|
||||
}
|
||||
public UUID getJobId() {
|
||||
synchronized (this.uuid) {
|
||||
return uuid;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Time markers
|
||||
*/
|
||||
protected void setJobId(UUID id) {
|
||||
synchronized (this.uuid) {
|
||||
this.uuid = id;
|
||||
}
|
||||
}
|
||||
|
||||
protected void markSubmitTime() {
|
||||
this.submitTime = System.currentTimeMillis()-2;
|
||||
}
|
||||
public String getWorkerID() {
|
||||
return workerID.get();
|
||||
}
|
||||
|
||||
protected void markStartRunTime() {
|
||||
this.startTime = System.currentTimeMillis()-1;
|
||||
}
|
||||
protected void markSubmitTime() {
|
||||
this.submitTime = System.currentTimeMillis() - 2;
|
||||
}
|
||||
|
||||
protected void markStopRunTime() {
|
||||
this.stopTime = System.currentTimeMillis();
|
||||
}
|
||||
protected void markStartRunTime() {
|
||||
this.startTime = System.currentTimeMillis() - 1;
|
||||
}
|
||||
|
||||
public final long getSubmitTime() {
|
||||
return submitTime;
|
||||
}
|
||||
/*
|
||||
* Time markers
|
||||
*/
|
||||
|
||||
public final long getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
protected void markStopRunTime() {
|
||||
this.stopTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public final long getStopTime() {
|
||||
return stopTime;
|
||||
}
|
||||
public final long getSubmitTime() {
|
||||
return submitTime;
|
||||
}
|
||||
|
||||
public final long getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public final long getStopTime() {
|
||||
return stopTime;
|
||||
}
|
||||
|
||||
public enum JobRunStatus {
|
||||
CREATED, RUNNING, FINISHED;
|
||||
}
|
||||
|
||||
public enum JobCompletionStatus {
|
||||
NOTCOMPLETEDYET, SUCCESS, SUCCESSWITHERRORS, FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user