All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.instaclustr.operations.GlobalOperationProgressTracker Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
package com.instaclustr.operations;

public class GlobalOperationProgressTracker {

    private final Operation operation;
    private final int operations;

    private float partialUpdate = 0.0f;

    public GlobalOperationProgressTracker(final Operation operation,
                                          final int operations) {
        if (operations <= 0) {
            throw new IllegalArgumentException("Events to complete has to be greater than 0.");
        }

        this.operation = operation;
        this.operations = operations;
    }

    public synchronized void update(final float operationProgress) {
        partialUpdate += operationProgress;
        this.operation.progress = partialUpdate / (float) operations;
    }

    public void complete() {
        this.operation.progress = 1.0f;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy