return createDatastoreServiceConfigPrototype(persistenceConfig, WRITE_TIMEOUT_PROPERTY);
}
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 FatalNucleusUserException(
"Illegal value for " + DATASTORE_READ_CONSISTENCY_PROPERTY +
". Valid values are " + Arrays.toString(Consistency.values()));
}