io.bdeploy.bhive.op.ObjectSizeOperation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of api Show documentation
Show all versions of api Show documentation
Public API including dependencies, ready to be used for integrations and plugins.
package io.bdeploy.bhive.op;
import java.util.Collection;
import java.util.SortedSet;
import java.util.TreeSet;
import io.bdeploy.bhive.BHive;
import io.bdeploy.bhive.ReadOnlyOperation;
import io.bdeploy.bhive.audit.AuditParameterExtractor.AuditStrategy;
import io.bdeploy.bhive.audit.AuditParameterExtractor.AuditWith;
import io.bdeploy.bhive.model.ObjectId;
import io.bdeploy.common.ActivityReporter.Activity;
import io.bdeploy.common.util.RuntimeAssert;
/**
* Measures the disc usage of all {@link ObjectId}s given and returns the sum.
*/
@ReadOnlyOperation
public class ObjectSizeOperation extends BHive.Operation {
@AuditWith(AuditStrategy.COLLECTION_SIZE)
private final SortedSet objects = new TreeSet<>();
@Override
public Long call() throws Exception {
RuntimeAssert.assertFalse(objects.isEmpty(), "No objects to measure");
try (Activity activity = getActivityReporter().start("Calculating Object Sizes", -1)) {
return objects.stream().mapToLong(id -> getObjectManager().db(x -> x.getObjectSize(id))).sum();
}
}
/**
* Add an object to measure
*/
public ObjectSizeOperation addObject(Collection object) {
this.objects.addAll(object);
return this;
}
/**
* Add an object to measure
*/
public ObjectSizeOperation addObject(ObjectId object) {
objects.add(object);
return this;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy