mirror of
https://github.com/Qortal/qortal.git
synced 2025-04-23 19:37:51 +00:00
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:
parent
357946388c
commit
e1e44d35bb
@ -8,12 +8,8 @@ import org.qortal.utils.NTP;
|
|||||||
|
|
||||||
import java.io.IOException;
|
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 final Long creationTimestamp;
|
||||||
private Long buildStartTimestamp = null;
|
private Long buildStartTimestamp = null;
|
||||||
private Long buildEndTimestamp = null;
|
private Long buildEndTimestamp = null;
|
||||||
@ -26,10 +22,8 @@ public class ArbitraryDataBuildQueueItem {
|
|||||||
public static long FAILURE_TIMEOUT = 5*60*1000L; // 5 minutes
|
public static long FAILURE_TIMEOUT = 5*60*1000L; // 5 minutes
|
||||||
|
|
||||||
public ArbitraryDataBuildQueueItem(String resourceId, ResourceIdType resourceIdType, Service service, String identifier) {
|
public ArbitraryDataBuildQueueItem(String resourceId, ResourceIdType resourceIdType, Service service, String identifier) {
|
||||||
this.resourceId = resourceId.toLowerCase();
|
super(resourceId, resourceIdType, service, identifier);
|
||||||
this.resourceIdType = resourceIdType;
|
|
||||||
this.service = service;
|
|
||||||
this.identifier = identifier;
|
|
||||||
this.creationTimestamp = NTP.getTime();
|
this.creationTimestamp = NTP.getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,18 +66,6 @@ public class ArbitraryDataBuildQueueItem {
|
|||||||
return now - this.buildStartTimestamp > FAILURE_TIMEOUT;
|
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() {
|
public Long getBuildStartTimestamp() {
|
||||||
return this.buildStartTimestamp;
|
return this.buildStartTimestamp;
|
||||||
}
|
}
|
||||||
@ -91,14 +73,4 @@ public class ArbitraryDataBuildQueueItem {
|
|||||||
public void setFailed(boolean failed) {
|
public void setFailed(boolean failed) {
|
||||||
this.failed = 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,17 +19,17 @@ import java.util.List;
|
|||||||
|
|
||||||
public class ArbitraryDataResource {
|
public class ArbitraryDataResource {
|
||||||
|
|
||||||
private final String resourceId;
|
protected final String resourceId;
|
||||||
private final ResourceIdType resourceIdType;
|
protected final ResourceIdType resourceIdType;
|
||||||
private final Service service;
|
protected final Service service;
|
||||||
private final String identifier;
|
protected final String identifier;
|
||||||
|
|
||||||
private List<ArbitraryTransactionData> transactions;
|
private List<ArbitraryTransactionData> transactions;
|
||||||
private ArbitraryTransactionData latestPutTransaction;
|
private ArbitraryTransactionData latestPutTransaction;
|
||||||
private int layerCount;
|
private int layerCount;
|
||||||
|
|
||||||
public ArbitraryDataResource(String resourceId, ResourceIdType resourceIdType, Service service, String identifier) {
|
public ArbitraryDataResource(String resourceId, ResourceIdType resourceIdType, Service service, String identifier) {
|
||||||
this.resourceId = resourceId;
|
this.resourceId = resourceId.toLowerCase();
|
||||||
this.resourceIdType = resourceIdType;
|
this.resourceIdType = resourceIdType;
|
||||||
this.service = service;
|
this.service = service;
|
||||||
this.identifier = identifier;
|
this.identifier = identifier;
|
||||||
@ -57,12 +57,12 @@ public class ArbitraryDataResource {
|
|||||||
// Next check if there's a build in progress
|
// Next check if there's a build in progress
|
||||||
ArbitraryDataBuildQueueItem queueItem =
|
ArbitraryDataBuildQueueItem queueItem =
|
||||||
new ArbitraryDataBuildQueueItem(resourceId, resourceIdType, service, identifier);
|
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);
|
return new ArbitraryResourceSummary(ArbitraryResourceStatus.BUILDING);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if a build has failed
|
// 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);
|
return new ArbitraryResourceSummary(ArbitraryResourceStatus.BUILD_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,7 +227,28 @@ public class ArbitraryDataResource {
|
|||||||
return identifier != null ? identifier : "";
|
return identifier != null ? identifier : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user