package org.glassfish.grizzly;
public class ProcessorResult {
private static final ProcessorResult NOT_RUN_RESULT = new ProcessorResult(Status.NOT_RUN, null);
private static final ProcessorResult COMPLETE_RESULT = new ProcessorResult(Status.COMPLETE, null);
private static final ProcessorResult LEAVE_RESULT = new ProcessorResult(Status.LEAVE, null);
private static final ProcessorResult REREGISTER_RESULT = new ProcessorResult(Status.REREGISTER, null);
private static final ProcessorResult ERROR_RESULT = new ProcessorResult(Status.ERROR, null);
private static final ProcessorResult TERMINATE_RESULT = new ProcessorResult(Status.TERMINATE, null);
private static ProcessorResult create() {
return new ProcessorResult();
}
public enum Status {
COMPLETE, LEAVE, REREGISTER, RERUN, ERROR, TERMINATE, NOT_RUN
}
private Status status;
private Object data;
public static ProcessorResult createComplete() {
return COMPLETE_RESULT;
}
public static ProcessorResult createComplete(final Object data) {
return create().setStatus(Status.COMPLETE).setData(data);
}
public static ProcessorResult createLeave() {
return LEAVE_RESULT;
}
public static ProcessorResult createReregister(final Context context) {
return create().setStatus(Status.REREGISTER).setData(context);
}
public static ProcessorResult createError() {
return ERROR_RESULT;
}
public static ProcessorResult createError(final Object description) {
return create().setStatus(Status.ERROR).setData(description);
}
public static ProcessorResult createRerun(final Context context) {
return create().setStatus(Status.RERUN).setData(context);
}
public static ProcessorResult createTerminate() {
return TERMINATE_RESULT;
}
public static ProcessorResult createNotRun() {
return NOT_RUN_RESULT;
}
private ProcessorResult() {
this(null, null);
}
private ProcessorResult(final Status status) {
this(status, null);
}
private ProcessorResult(final Status status, final Object context) {
this.status = status;
this.data = context;
}
public Status getStatus() {
return status;
}
protected ProcessorResult setStatus(Status status) {
this.status = status;
return this;
}
public Object getData() {
return data;
}
protected ProcessorResult setData(Object context) {
this.data = context;
return this;
}
}