synchronization and threading tweaks
This commit is contained in:
parent
1ec9a67db3
commit
7da1f47b62
3 changed files with 15 additions and 36 deletions
|
@ -3,8 +3,9 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.rdfservice.impl;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
@ -32,7 +33,7 @@ public abstract class RDFServiceImpl implements RDFService {
|
|||
|
||||
private static final Log log = LogFactory.getLog(RDFServiceImpl.class);
|
||||
protected String defaultWriteGraphURI;
|
||||
protected ArrayList<ChangeListener> registeredListeners = new ArrayList<ChangeListener>();
|
||||
protected List<ChangeListener> registeredListeners = new CopyOnWriteArrayList<ChangeListener>();
|
||||
|
||||
/**
|
||||
* If the given individual already exists in the default graph, throws an
|
||||
|
@ -131,8 +132,7 @@ public abstract class RDFServiceImpl implements RDFService {
|
|||
return new ChangeSetImpl();
|
||||
}
|
||||
|
||||
public synchronized void notifyListeners(Triple triple, ModelChange.Operation operation, String graphURI) {
|
||||
|
||||
protected void notifyListeners(Triple triple, ModelChange.Operation operation, String graphURI) {
|
||||
Iterator<ChangeListener> iter = registeredListeners.iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
|
@ -145,7 +145,7 @@ public abstract class RDFServiceImpl implements RDFService {
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized void notifyListenersOfEvent(Object event) {
|
||||
protected void notifyListenersOfEvent(Object event) {
|
||||
|
||||
Iterator<ChangeListener> iter = registeredListeners.iterator();
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@ import com.hp.hpl.jena.query.QueryFactory;
|
|||
import com.hp.hpl.jena.query.QuerySolution;
|
||||
import com.hp.hpl.jena.query.ResultSet;
|
||||
import com.hp.hpl.jena.query.ResultSetFormatter;
|
||||
import com.hp.hpl.jena.rdf.listeners.StatementListener;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||
|
@ -37,7 +36,6 @@ import com.hp.hpl.jena.sdb.Store;
|
|||
import com.hp.hpl.jena.sdb.StoreDesc;
|
||||
import com.hp.hpl.jena.sdb.sql.SDBConnection;
|
||||
import com.hp.hpl.jena.shared.Lock;
|
||||
import com.hp.hpl.jena.vocabulary.OWL;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.DatasetWrapper;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.SparqlGraph;
|
||||
|
@ -443,24 +441,9 @@ public class RDFServiceSDB extends RDFServiceImpl implements RDFService {
|
|||
// nothing
|
||||
}
|
||||
|
||||
private class ModelListener extends StatementListener {
|
||||
|
||||
private String graphURI;
|
||||
private RDFServiceImpl s;
|
||||
|
||||
public ModelListener(String graphURI, RDFServiceImpl s) {
|
||||
this.graphURI = graphURI;
|
||||
this.s = s;
|
||||
}
|
||||
|
||||
public void addedStatement(Statement stmt) {
|
||||
s.notifyListeners(stmt.asTriple(), ModelChange.Operation.ADD, graphURI);
|
||||
}
|
||||
|
||||
public void removedStatement(Statement stmt) {
|
||||
s.notifyListeners(stmt.asTriple(), ModelChange.Operation.REMOVE, graphURI);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyListeners(Triple triple, ModelChange.Operation operation, String graphURI) {
|
||||
super.notifyListeners(triple, operation, graphURI);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.ArrayList;
|
|||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
@ -58,7 +59,6 @@ public class SimpleReasoner extends StatementListener {
|
|||
|
||||
private static final Log log = LogFactory.getLog(SimpleReasoner.class);
|
||||
|
||||
private RDFService rdfService;
|
||||
private OntModel tboxModel; // asserted and inferred TBox axioms
|
||||
private OntModel aboxModel; // ABox assertions
|
||||
private Model inferenceModel; // ABox inferences
|
||||
|
@ -75,19 +75,18 @@ public class SimpleReasoner extends StatementListener {
|
|||
private volatile boolean batchMode2 = false;
|
||||
private boolean stopRequested = false;
|
||||
|
||||
//TODO check this for thread safety
|
||||
private List<ReasonerPlugin> pluginList = new ArrayList<ReasonerPlugin>();
|
||||
private List<ReasonerPlugin> pluginList = new CopyOnWriteArrayList<ReasonerPlugin>();
|
||||
|
||||
/**
|
||||
* @param tboxModel - input. This model contains both asserted and inferred TBox axioms
|
||||
* @param aboxModel - input. This model contains asserted ABox statements
|
||||
* @param inferenceModel - output. This is the model in which inferred (materialized) ABox statements are maintained (added or retracted).
|
||||
* @param inferenceRebuildModel - output. This the model temporarily used when the whole ABox inference model is rebuilt
|
||||
* @param inferenceScratchpadModel - output. This the model temporarily used when the whole ABox inference model is rebuilt
|
||||
* @param inferenceRebuildModel - output. This the model is temporarily used when the whole ABox inference model is rebuilt
|
||||
* @param inferenceScratchpadModel - output. This the model is temporarily used when the whole ABox inference model is rebuilt
|
||||
*/
|
||||
public SimpleReasoner(OntModel tboxModel, RDFService rdfService, Model inferenceModel,
|
||||
Model inferenceRebuildModel, Model scratchpadModel) {
|
||||
this.rdfService = rdfService;
|
||||
|
||||
this.tboxModel = tboxModel;
|
||||
this.aboxModel = ModelFactory.createOntologyModel(
|
||||
OntModelSpec.OWL_MEM, ModelFactory.createModelForGraph(
|
||||
|
@ -986,9 +985,6 @@ public class SimpleReasoner extends StatementListener {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Returns a list of properties that are inverses of the property
|
||||
* in the given statement.
|
||||
|
@ -1569,10 +1565,10 @@ public class SimpleReasoner extends StatementListener {
|
|||
// in the recomputed inference model
|
||||
int num = 0;
|
||||
scratchpadModel.enterCriticalSection(Lock.WRITE);
|
||||
scratchpadModel.removeAll();
|
||||
try {
|
||||
inferenceModel.enterCriticalSection(Lock.READ);
|
||||
try {
|
||||
scratchpadModel.removeAll();
|
||||
iter = inferenceModel.listStatements();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
|
|
Loading…
Add table
Reference in a new issue