return createDatastoreServiceConfigPrototype(persistenceConfig, PropertyNames.PROPERTY_DATASTORE_WRITE_TIMEOUT);
}
private DatastoreServiceConfig createDatastoreServiceConfigPrototype(
PersistenceConfiguration persistenceConfiguration, String... timeoutProps) {
DatastoreServiceConfig datastoreServiceConfig = DatastoreServiceConfig.Builder.withDefaults();
for (String timeoutProp : timeoutProps) {
int defaultDeadline = persistenceConfiguration.getIntProperty(timeoutProp);
if (defaultDeadline > 0) {
datastoreServiceConfig.deadline(defaultDeadline / 1000d);
}
}
String defaultReadConsistencyStr = persistenceConfiguration.getStringProperty(
DATASTORE_READ_CONSISTENCY_PROPERTY);
if (defaultReadConsistencyStr != null) {
try {
datastoreServiceConfig.readPolicy(new ReadPolicy(Consistency.valueOf(defaultReadConsistencyStr)));
} catch (IllegalArgumentException iae) {
throw new NucleusFatalUserException(
"Illegal value for " + DATASTORE_READ_CONSISTENCY_PROPERTY +
". Valid values are " + Arrays.toString(Consistency.values()));
}