forked from Qortal/qortal
Added "storagePolicy" setting, including startup validation.
Possible values are: FOLLOWED_AND_VIEWED (default) FOLLOWED VIEWED ALL NONE Nothing is affected by this setting yet, but this will be added shortly.
This commit is contained in:
parent
90465149e6
commit
28fb11068e
@ -42,6 +42,13 @@ public class ArbitraryDataManager extends Thread {
|
|||||||
|
|
||||||
private volatile boolean isStopping = false;
|
private volatile boolean isStopping = false;
|
||||||
|
|
||||||
|
public enum StoragePolicy {
|
||||||
|
FOLLOWED_AND_VIEWED,
|
||||||
|
FOLLOWED,
|
||||||
|
VIEWED,
|
||||||
|
ALL,
|
||||||
|
NONE
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map of recent requests for ARBITRARY transaction data file lists.
|
* Map of recent requests for ARBITRARY transaction data file lists.
|
||||||
|
@ -5,10 +5,7 @@ import java.io.FileNotFoundException;
|
|||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
@ -24,9 +21,11 @@ import org.eclipse.persistence.exceptions.XMLMarshalException;
|
|||||||
import org.eclipse.persistence.jaxb.JAXBContextFactory;
|
import org.eclipse.persistence.jaxb.JAXBContextFactory;
|
||||||
import org.eclipse.persistence.jaxb.UnmarshallerProperties;
|
import org.eclipse.persistence.jaxb.UnmarshallerProperties;
|
||||||
import org.qortal.block.BlockChain;
|
import org.qortal.block.BlockChain;
|
||||||
|
import org.qortal.controller.arbitrary.ArbitraryDataManager.*;
|
||||||
import org.qortal.crosschain.Bitcoin.BitcoinNet;
|
import org.qortal.crosschain.Bitcoin.BitcoinNet;
|
||||||
import org.qortal.crosschain.Litecoin.LitecoinNet;
|
import org.qortal.crosschain.Litecoin.LitecoinNet;
|
||||||
import org.qortal.crosschain.Dogecoin.DogecoinNet;
|
import org.qortal.crosschain.Dogecoin.DogecoinNet;
|
||||||
|
import org.qortal.utils.EnumUtils;
|
||||||
|
|
||||||
// All properties to be converted to JSON via JAXB
|
// All properties to be converted to JSON via JAXB
|
||||||
@XmlAccessorType(XmlAccessType.FIELD)
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
@ -263,6 +262,9 @@ public class Settings {
|
|||||||
/** Data storage path (for temporary data). */
|
/** Data storage path (for temporary data). */
|
||||||
private String tempDataPath = "data/_temp";
|
private String tempDataPath = "data/_temp";
|
||||||
|
|
||||||
|
/** Storage policy to indicate which data should be hosted */
|
||||||
|
private String storagePolicy = "FOLLOWED_AND_VIEWED";
|
||||||
|
|
||||||
/** Whether to validate every layer when building arbitrary data, or just the final layer */
|
/** Whether to validate every layer when building arbitrary data, or just the final layer */
|
||||||
private boolean validateAllDataLayers = false;
|
private boolean validateAllDataLayers = false;
|
||||||
|
|
||||||
@ -417,6 +419,13 @@ public class Settings {
|
|||||||
|
|
||||||
if (this.apiKey != null && this.apiKey.trim().length() < 8)
|
if (this.apiKey != null && this.apiKey.trim().length() < 8)
|
||||||
throwValidationError("apiKey must be at least 8 characters");
|
throwValidationError("apiKey must be at least 8 characters");
|
||||||
|
|
||||||
|
try {
|
||||||
|
StoragePolicy.valueOf(this.storagePolicy);
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
String possibleValues = EnumUtils.getNames(StoragePolicy.class, ", ");
|
||||||
|
throwValidationError(String.format("storagePolicy must be one of: %s", possibleValues));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters / setters
|
// Getters / setters
|
||||||
@ -766,6 +775,10 @@ public class Settings {
|
|||||||
return this.tempDataPath;
|
return this.tempDataPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StoragePolicy getStoragePolicy() {
|
||||||
|
return StoragePolicy.valueOf(this.storagePolicy);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean shouldValidateAllDataLayers() {
|
public boolean shouldValidateAllDataLayers() {
|
||||||
return this.validateAllDataLayers;
|
return this.validateAllDataLayers;
|
||||||
}
|
}
|
||||||
|
15
src/main/java/org/qortal/utils/EnumUtils.java
Normal file
15
src/main/java/org/qortal/utils/EnumUtils.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package org.qortal.utils;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class EnumUtils {
|
||||||
|
|
||||||
|
public static String[] getNames(Class<? extends Enum<?>> e) {
|
||||||
|
return Arrays.stream(e.getEnumConstants()).map(Enum::name).toArray(String[]::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getNames(Class<? extends Enum<?>> e, String delimiter) {
|
||||||
|
return String.join(delimiter, EnumUtils.getNames(e));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user