ArbitraryDataBuildQueueItem now extends ArbitraryDataResource

This is the start of a refactor to use ArbitraryDataResource objects rather than passing around separate resourceId, service and identifier, or other duplicate objects. Most of this will need to be done after the initial release due to time constraints.
This commit is contained in:
CalDescent 2021-12-24 12:05:03 +00:00
parent 357946388c
commit e1e44d35bb
2 changed files with 32 additions and 39 deletions

View File

@ -8,12 +8,8 @@ import org.qortal.utils.NTP;
import java.io.IOException;
public class ArbitraryDataBuildQueueItem {
public class ArbitraryDataBuildQueueItem extends ArbitraryDataResource {
private final String resourceId;
private final ResourceIdType resourceIdType;
private final Service service;
private final String identifier;
private final Long creationTimestamp;
private Long buildStartTimestamp = null;
private Long buildEndTimestamp = null;
@ -26,10 +22,8 @@ public class ArbitraryDataBuildQueueItem {
public static long FAILURE_TIMEOUT = 5*60*1000L; // 5 minutes
public ArbitraryDataBuildQueueItem(String resourceId, ResourceIdType resourceIdType, Service service, String identifier) {
this.resourceId = resourceId.toLowerCase();
this.resourceIdType = resourceIdType;
this.service = service;
this.identifier = identifier;
super(resourceId, resourceIdType, service, identifier);
this.creationTimestamp = NTP.getTime();
}
@ -72,18 +66,6 @@ public class ArbitraryDataBuildQueueItem {
return now - this.buildStartTimestamp > FAILURE_TIMEOUT;
}
public String getResourceId() {
return this.resourceId;
}
/**
* @return unique key used to identify this queue item
*/
public String getUniqueKey() {
return String.format("%s-%s-%s", this.service, this.resourceId, this.identifier).toLowerCase();
}
public Long getBuildStartTimestamp() {
return this.buildStartTimestamp;
}
@ -91,14 +73,4 @@ public class ArbitraryDataBuildQueueItem {
public void setFailed(boolean failed) {
this.failed = failed;
}
@Override
public String toString() {
if (this.identifier == null) {
return String.format("%s %s", this.service, this.resourceId);
}
return String.format("%s %s %s", this.service, this.resourceId, this.identifier);
}
}

View File

@ -19,17 +19,17 @@ import java.util.List;
public class ArbitraryDataResource {
private final String resourceId;
private final ResourceIdType resourceIdType;
private final Service service;
private final String identifier;
protected final String resourceId;
protected final ResourceIdType resourceIdType;
protected final Service service;
protected final String identifier;
private List<ArbitraryTransactionData> transactions;
private ArbitraryTransactionData latestPutTransaction;
private int layerCount;
public ArbitraryDataResource(String resourceId, ResourceIdType resourceIdType, Service service, String identifier) {
this.resourceId = resourceId;
this.resourceId = resourceId.toLowerCase();
this.resourceIdType = resourceIdType;
this.service = service;
this.identifier = identifier;
@ -57,12 +57,12 @@ public class ArbitraryDataResource {
// Next check if there's a build in progress
ArbitraryDataBuildQueueItem queueItem =
new ArbitraryDataBuildQueueItem(resourceId, resourceIdType, service, identifier);
if (ArbitraryDataBuildManager.getInstance().isInBuildQueue(queueItem)) { // TODO: currently keyed by name only
if (ArbitraryDataBuildManager.getInstance().isInBuildQueue(queueItem)) {
return new ArbitraryResourceSummary(ArbitraryResourceStatus.BUILDING);
}
// Check if a build has failed
if (ArbitraryDataBuildManager.getInstance().isInFailedBuildsList(queueItem)) { // TODO: currently keyed by name only
if (ArbitraryDataBuildManager.getInstance().isInFailedBuildsList(queueItem)) {
return new ArbitraryResourceSummary(ArbitraryResourceStatus.BUILD_FAILED);
}
@ -227,7 +227,28 @@ public class ArbitraryDataResource {
return identifier != null ? identifier : "";
}
@Override
public String toString() {
return String.format("%s-%s-%s-%s", resourceIdString(), resourceIdTypeString(), serviceString(), identifierString());
return String.format("%s %s %s %s", this.serviceString(), this.resourceIdString(), this.resourceIdTypeString(), this.identifierString());
}
/**
* @return unique key used to identify this resource
*/
public String getUniqueKey() {
return String.format("%s-%s-%s", this.service, this.resourceId, this.identifier).toLowerCase();
}
public String getResourceId() {
return this.resourceId;
}
public Service getService() {
return this.service;
}
public String getIdentifier() {
return this.identifier;
}
}