weight = ((Number)value).intValue();
} else if(value != null){
try {
weight = new BigDecimal(value.toString()).intValueExact();
} catch (RuntimeException e) {
throw new ConfigurationException(WEIGHT, "Unable to parse integer weight!", e);
}
} else { //weight not defined
weight = 0;
}
value = config.get(SYNC_INTERVAL);
if(value instanceof Number){
syncInterval = Math.max(((Number)value).intValue(),MIN_SYNC_INTERVAL);
} else if(value != null){
try {
syncInterval = Math.max(new BigDecimal(value.toString()).intValueExact(),MIN_SYNC_INTERVAL);
} catch (RuntimeException e) {
throw new ConfigurationException(SYNC_INTERVAL, "Unable to parse integer weight!", e);
}
} else { //weight not defined
syncInterval = DEFAULT_SYNC_INTERVAL;
}
value = config.get(TDB_DIR);
File dataDir;
if(value != null && !value.toString().isEmpty()){
dataDir = new File(substituteProperty(value.toString(),bc)).getAbsoluteFile();
} else {
value = config.get(Constants.SERVICE_PID);
if(value == null){
throw new ConfigurationException(TDB_DIR, "No Data Directory for "
+ "the Jena TDB store parsed. Also unable to use the "
+ "'service.pid' property as default because this property "
+ "is not present in the parsed configuration.");
}
dataDir = bc.getDataFile("singleTdb"+File.separatorChar+value.toString());
log.info("No TDB directory parsed - use default '{}'",dataDir);
}
//parse the default graph name
value = config.get(DEFAULT_GRAPH_NAME);
if(value != null && !value.toString().isEmpty()){
try {
new URI(value.toString());
defaultGraphName = new UriRef(value.toString());
} catch (URISyntaxException e) {
throw new ConfigurationException(DEFAULT_GRAPH_NAME, "The parsed name '"
+ value + "'for the default graph (union over all "
+ "named graphs managed by this Jena TDB dataset) MUST BE "
+ "an valid URI or NULL do deactivate this feature!",e);
}
} else {
defaultGraphName = null; //deactivate the default graph name
}
//validate the parsed directory!
if(!dataDir.exists()){
if(dataDir.mkdirs()){
log.info("Created Jena TDB data directory {}",dataDir);
} else {
throw new ConfigurationException(TDB_DIR, "Unable to create Jena TDB data directory '"+dataDir+"'!");
}
} else if(!dataDir.isDirectory()){
throw new ConfigurationException("tdb.dir", "Configured jena TDB data directory '"
+ dataDir+"' already exists, but is not a Directory!");
} //else exists and is a directory ... nothing to do
TDB.getContext().set(TDB.symUnionDefaultGraph, true);
setDataset(TDBFactory.createDataset(dataDir.getAbsolutePath()));
//init the read/write lock
//init the graph config (stores the graph and mgraph names in a config file)
initGraphConfigs(dataDir,config);
//finally ensure the the defaultGraphName is not also used as a graph/mgraph name
if(graphNames.contains(defaultGraphName)){
throw new ConfigurationException(DEFAULT_GRAPH_NAME, "The configured default graph name '"
+defaultGraphName+"' is also used as a Graph name!");
}
if(mGraphNames.contains(defaultGraphName)){
throw new ConfigurationException(DEFAULT_GRAPH_NAME, "The configured default graph name '"
+defaultGraphName+"' is also used as a MGraph name!");
}
syncThread = new SyncThread();
syncThread.setDaemon(true);