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

com.emc.ecs.tool.BucketWipeResult Maven / Gradle / Ivy

Go to download

The purpose of the bucket-wipe tool is to enumerate a bucket and delete its contents in parallel threads. At the end the bucket is optionally deleted.

There is a newer version: 2.2.0
Show newest version
package com.emc.ecs.tool;

import org.apache.http.annotation.GuardedBy;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;

/**
 * An Async Result of a BucketWipe Operation
 *
 * Clients can use {@link #getCompletedFuture()} which will be completed when the bucket wipe has completed
 */
public class BucketWipeResult {
    private final AtomicLong actionsOutstanding = new AtomicLong();
    private final AtomicLong deletedObjects = new AtomicLong();
    private final AtomicBoolean allActionsSubmitted = new AtomicBoolean();
    private final CompletableFuture completedFuture = new CompletableFuture<>();
    private final List errors = Collections.synchronizedList(new ArrayList<>());

    @GuardedBy("this")
    private String lastKey;

    public CompletableFuture getCompletedFuture() {
        return completedFuture;
    }

    public String getLastKey() {
        synchronized (this) {
            return lastKey;
        }
    }

    public long getDeletedObjects() {
        return deletedObjects.get();
    }


    public void addError(String error) {
        errors.add(error);
    }

    public List getErrors() {
        return errors;
    }

    public void actionOutstanding() {
        actionsOutstanding.incrementAndGet();
    }

    public void actionComplete() {
        deletedObjects.incrementAndGet();
        actionsOutstanding.decrementAndGet();

        completeFutureIfComplete();
    }

    public void allActionsSubmitted() {
        allActionsSubmitted.set(true);

        completeFutureIfComplete();
    }


    protected void setLastKey(String lastKey) {
        synchronized (this) {
            this.lastKey = lastKey;
        }
    }

    /**
     * The operation is complete when all actions have been submitted and there are no outstanding issues
     */
    private void completeFutureIfComplete() {
        if (allActionsSubmitted.get() && actionsOutstanding.get() == 0) {
            completedFuture.complete(errors.isEmpty());
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy