VIVO-778 Let the listener hold the change set.
This commit is contained in:
parent
24bce9ff67
commit
0c46f1d14e
4 changed files with 26 additions and 51 deletions
|
@ -8,7 +8,6 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
@ -17,11 +16,8 @@ import com.hp.hpl.jena.ontology.OntModel;
|
|||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||
import com.hp.hpl.jena.rdf.model.Resource;
|
||||
import com.hp.hpl.jena.rdf.model.Statement;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.InferenceModelUpdater;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.PatternListBuilder;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.jena.criticalsection.LockableModel;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.jena.criticalsection.LockableOntModel;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.jena.criticalsection.LockedOntModel;
|
||||
|
@ -41,7 +37,6 @@ public class BasicTBoxReasonerDriver implements TBoxReasonerDriver {
|
|||
|
||||
private final ConfiguredReasonerListener listener;
|
||||
|
||||
private final AtomicReference<TBoxChanges> currentChangeSet;
|
||||
private final Set<TBoxChanges> pendingChangeSets;
|
||||
|
||||
private final ExecutorService executorService;
|
||||
|
@ -62,7 +57,6 @@ public class BasicTBoxReasonerDriver implements TBoxReasonerDriver {
|
|||
this.listener = new ConfiguredReasonerListener(reasonerConfiguration,
|
||||
this);
|
||||
|
||||
this.currentChangeSet = new AtomicReference<>(new TBoxChanges());
|
||||
this.pendingChangeSets = Collections.synchronizedSet(new HashSet<TBoxChanges>());
|
||||
|
||||
this.executorService = Executors.newFixedThreadPool(1);
|
||||
|
@ -97,32 +91,10 @@ public class BasicTBoxReasonerDriver implements TBoxReasonerDriver {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void addStatement(Statement stmt) {
|
||||
currentChangeSet.get().addStatement(stmt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeStatement(Statement stmt) {
|
||||
currentChangeSet.get().removeStatement(stmt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDataProperty(Statement stmt) {
|
||||
currentChangeSet.get().deleteDataProperty(stmt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteObjectProperty(Statement stmt) {
|
||||
currentChangeSet.get().deleteObjectProperty(stmt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runSynchronizer() {
|
||||
TBoxChanges changes = currentChangeSet.getAndSet(new TBoxChanges());
|
||||
if (changes.isEmpty()) {
|
||||
return;
|
||||
public void runSynchronizer(TBoxChanges changeSet) {
|
||||
if (!changeSet.isEmpty()) {
|
||||
executorService.execute(new ReasoningTask(changeSet));
|
||||
}
|
||||
executorService.execute(new ReasoningTask(changes));
|
||||
}
|
||||
|
||||
private class ReasoningTask implements Runnable {
|
||||
|
@ -139,6 +111,7 @@ public class BasicTBoxReasonerDriver implements TBoxReasonerDriver {
|
|||
try {
|
||||
reasoner.updateReasonerModel(changes);
|
||||
status = reasoner.performReasoning();
|
||||
|
||||
buildPatternList();
|
||||
updateInferencesModel();
|
||||
} finally {
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.util.LinkedList;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
@ -23,8 +24,11 @@ import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
|||
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
|
||||
|
||||
/**
|
||||
* Listens for changes on a model. When a change is announced, it is passed
|
||||
* along to the reasoner driver, if the configuration says that it is worthy.
|
||||
* Listens for changes on a model. When a change is announced, it is checked for
|
||||
* worthiness. If worthy, it is added to a change set.
|
||||
*
|
||||
* When an ending EditEvent is received, the current change set is passed along
|
||||
* to the reasoner driver, and a new change set is begun.
|
||||
*
|
||||
* Among the criteria for deciding on worthiness is the driving pattern set. In
|
||||
* the constructor, a map is made from this set, to reduce the number of tests
|
||||
|
@ -41,9 +45,11 @@ public class ConfiguredReasonerListener implements ModelChangedListener {
|
|||
|
||||
private final ReasonerConfiguration reasonerConfiguration;
|
||||
private final TBoxReasonerDriver reasonerDriver;
|
||||
|
||||
private final DrivingPatternMap drivingPatternMap;
|
||||
|
||||
private final AtomicBoolean suspended = new AtomicBoolean();
|
||||
private final AtomicReference<TBoxChanges> changeSet;
|
||||
private final AtomicBoolean suspended;
|
||||
|
||||
public ConfiguredReasonerListener(
|
||||
ReasonerConfiguration reasonerConfiguration,
|
||||
|
@ -53,6 +59,9 @@ public class ConfiguredReasonerListener implements ModelChangedListener {
|
|||
|
||||
this.drivingPatternMap = new DrivingPatternMap(
|
||||
reasonerConfiguration.getInferenceDrivingPatternAllowSet());
|
||||
|
||||
this.changeSet = new AtomicReference<>(new TBoxChanges());
|
||||
this.suspended = new AtomicBoolean();
|
||||
}
|
||||
|
||||
public Suspension suspend() {
|
||||
|
@ -167,7 +176,8 @@ public class ConfiguredReasonerListener implements ModelChangedListener {
|
|||
if (event instanceof EditEvent) {
|
||||
EditEvent ee = (EditEvent) event;
|
||||
if (!ee.getBegin()) {
|
||||
this.reasonerDriver.runSynchronizer();
|
||||
TBoxChanges changes = changeSet.getAndSet(new TBoxChanges());
|
||||
this.reasonerDriver.runSynchronizer(changes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -310,19 +320,19 @@ public class ConfiguredReasonerListener implements ModelChangedListener {
|
|||
}
|
||||
|
||||
private void addIt(Statement stmt) {
|
||||
this.reasonerDriver.addStatement(stmt);
|
||||
changeSet.get().addStatement(stmt);
|
||||
}
|
||||
|
||||
private void removeIt(Statement stmt) {
|
||||
this.reasonerDriver.removeStatement(stmt);
|
||||
changeSet.get().removeStatement(stmt);
|
||||
}
|
||||
|
||||
private void deleteObjectProperty(Statement stmt) {
|
||||
this.reasonerDriver.deleteObjectProperty(stmt);
|
||||
changeSet.get().deleteObjectProperty(stmt);
|
||||
}
|
||||
|
||||
private void deleteDataProperty(Statement stmt) {
|
||||
this.reasonerDriver.deleteDataProperty(stmt);
|
||||
changeSet.get().deleteDataProperty(stmt);
|
||||
}
|
||||
|
||||
// The pattern matching stuff needs to get reworked.
|
||||
|
|
|
@ -22,6 +22,7 @@ public class TBoxChanges {
|
|||
|
||||
private final List<String> deletedDataPropertyUris = Collections
|
||||
.synchronizedList(new ArrayList<String>());
|
||||
|
||||
private final List<String> deletedObjectPropertyUris = Collections
|
||||
.synchronizedList(new ArrayList<String>());
|
||||
|
||||
|
@ -53,8 +54,8 @@ public class TBoxChanges {
|
|||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// These methods are called when processing the changeSet. By then, it is
|
||||
// owned and accessed by a single thread.
|
||||
// These methods are called when processing the changeSet. By that time, it
|
||||
// is owned and accessed by a single thread.
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public boolean isEmpty() {
|
||||
|
|
|
@ -2,22 +2,14 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.tboxreasoner;
|
||||
|
||||
import com.hp.hpl.jena.rdf.model.Statement;
|
||||
|
||||
/**
|
||||
* What calls can the ConfiguredReasonerListener make to drive the TBox
|
||||
* reasoner?
|
||||
*/
|
||||
public interface TBoxReasonerDriver {
|
||||
void runSynchronizer();
|
||||
|
||||
void addStatement(Statement stmt);
|
||||
|
||||
void removeStatement(Statement stmt);
|
||||
|
||||
void deleteDataProperty(Statement stmt);
|
||||
|
||||
void deleteObjectProperty(Statement stmt);
|
||||
void runSynchronizer(TBoxChanges changeSet);
|
||||
|
||||
boolean isReasoning();
|
||||
|
||||
|
@ -55,5 +47,4 @@ public interface TBoxReasonerDriver {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue