跳至主要內容

BatchStatus详解


BatchStatus详解

BatchStatus源代码详解

从BatchStatus可以看出,BatchStatus有COMPLETED, STARTING, STARTED, STOPPING, STOPPED, FAILED, ABANDONED, UNKNOWN这几个状态。

package org.springframework.batch.core;

public enum BatchStatus {
    COMPLETED,
    STARTING,
    STARTED,
    STOPPING,
    STOPPED,
    FAILED,
    ABANDONED,
    UNKNOWN;

    private BatchStatus() {
    }

    public static BatchStatus max(BatchStatus status1, BatchStatus status2) {
        return status1.isGreaterThan(status2) ? status1 : status2;
    }

    public boolean isRunning() {
        return this == STARTING || this == STARTED;
    }

    public boolean isUnsuccessful() {
        return this == FAILED || this.isGreaterThan(FAILED);
    }

    public BatchStatus upgradeTo(BatchStatus other) {
        if (!this.isGreaterThan(STARTED) && !other.isGreaterThan(STARTED)) {
            return this != COMPLETED && other != COMPLETED ? max(this, other) : COMPLETED;
        } else {
            return max(this, other);
        }
    }

    public boolean isGreaterThan(BatchStatus other) {
        return this.compareTo(other) > 0;
    }

    public boolean isLessThan(BatchStatus other) {
        return this.compareTo(other) < 0;
    }

    public boolean isLessThanOrEqualTo(BatchStatus other) {
        return this.compareTo(other) <= 0;
    }

    public static BatchStatus match(String value) {
        BatchStatus[] arr$ = values();
        int len$ = arr$.length;

        for(int i$ = 0; i$ < len$; ++i$) {
            BatchStatus status = arr$[i$];
            if (value.startsWith(status.toString())) {
                return status;
            }
        }

        return COMPLETED;
    }
}
上次编辑于:
贡献者: Neil