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.Set;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
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.Model;
|
||||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||||
import com.hp.hpl.jena.rdf.model.Resource;
|
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.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.LockableModel;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.jena.criticalsection.LockableOntModel;
|
import edu.cornell.mannlib.vitro.webapp.utils.jena.criticalsection.LockableOntModel;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.jena.criticalsection.LockedOntModel;
|
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 ConfiguredReasonerListener listener;
|
||||||
|
|
||||||
private final AtomicReference<TBoxChanges> currentChangeSet;
|
|
||||||
private final Set<TBoxChanges> pendingChangeSets;
|
private final Set<TBoxChanges> pendingChangeSets;
|
||||||
|
|
||||||
private final ExecutorService executorService;
|
private final ExecutorService executorService;
|
||||||
|
@ -62,7 +57,6 @@ public class BasicTBoxReasonerDriver implements TBoxReasonerDriver {
|
||||||
this.listener = new ConfiguredReasonerListener(reasonerConfiguration,
|
this.listener = new ConfiguredReasonerListener(reasonerConfiguration,
|
||||||
this);
|
this);
|
||||||
|
|
||||||
this.currentChangeSet = new AtomicReference<>(new TBoxChanges());
|
|
||||||
this.pendingChangeSets = Collections.synchronizedSet(new HashSet<TBoxChanges>());
|
this.pendingChangeSets = Collections.synchronizedSet(new HashSet<TBoxChanges>());
|
||||||
|
|
||||||
this.executorService = Executors.newFixedThreadPool(1);
|
this.executorService = Executors.newFixedThreadPool(1);
|
||||||
|
@ -97,32 +91,10 @@ public class BasicTBoxReasonerDriver implements TBoxReasonerDriver {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addStatement(Statement stmt) {
|
public void runSynchronizer(TBoxChanges changeSet) {
|
||||||
currentChangeSet.get().addStatement(stmt);
|
if (!changeSet.isEmpty()) {
|
||||||
|
executorService.execute(new ReasoningTask(changeSet));
|
||||||
}
|
}
|
||||||
|
|
||||||
@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;
|
|
||||||
}
|
|
||||||
executorService.execute(new ReasoningTask(changes));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ReasoningTask implements Runnable {
|
private class ReasoningTask implements Runnable {
|
||||||
|
@ -139,6 +111,7 @@ public class BasicTBoxReasonerDriver implements TBoxReasonerDriver {
|
||||||
try {
|
try {
|
||||||
reasoner.updateReasonerModel(changes);
|
reasoner.updateReasonerModel(changes);
|
||||||
status = reasoner.performReasoning();
|
status = reasoner.performReasoning();
|
||||||
|
|
||||||
buildPatternList();
|
buildPatternList();
|
||||||
updateInferencesModel();
|
updateInferencesModel();
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
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;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listens for changes on a model. When a change is announced, it is passed
|
* Listens for changes on a model. When a change is announced, it is checked for
|
||||||
* along to the reasoner driver, if the configuration says that it is worthy.
|
* 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
|
* 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
|
* 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 ReasonerConfiguration reasonerConfiguration;
|
||||||
private final TBoxReasonerDriver reasonerDriver;
|
private final TBoxReasonerDriver reasonerDriver;
|
||||||
|
|
||||||
private final DrivingPatternMap drivingPatternMap;
|
private final DrivingPatternMap drivingPatternMap;
|
||||||
|
|
||||||
private final AtomicBoolean suspended = new AtomicBoolean();
|
private final AtomicReference<TBoxChanges> changeSet;
|
||||||
|
private final AtomicBoolean suspended;
|
||||||
|
|
||||||
public ConfiguredReasonerListener(
|
public ConfiguredReasonerListener(
|
||||||
ReasonerConfiguration reasonerConfiguration,
|
ReasonerConfiguration reasonerConfiguration,
|
||||||
|
@ -53,6 +59,9 @@ public class ConfiguredReasonerListener implements ModelChangedListener {
|
||||||
|
|
||||||
this.drivingPatternMap = new DrivingPatternMap(
|
this.drivingPatternMap = new DrivingPatternMap(
|
||||||
reasonerConfiguration.getInferenceDrivingPatternAllowSet());
|
reasonerConfiguration.getInferenceDrivingPatternAllowSet());
|
||||||
|
|
||||||
|
this.changeSet = new AtomicReference<>(new TBoxChanges());
|
||||||
|
this.suspended = new AtomicBoolean();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Suspension suspend() {
|
public Suspension suspend() {
|
||||||
|
@ -167,7 +176,8 @@ public class ConfiguredReasonerListener implements ModelChangedListener {
|
||||||
if (event instanceof EditEvent) {
|
if (event instanceof EditEvent) {
|
||||||
EditEvent ee = (EditEvent) event;
|
EditEvent ee = (EditEvent) event;
|
||||||
if (!ee.getBegin()) {
|
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) {
|
private void addIt(Statement stmt) {
|
||||||
this.reasonerDriver.addStatement(stmt);
|
changeSet.get().addStatement(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeIt(Statement stmt) {
|
private void removeIt(Statement stmt) {
|
||||||
this.reasonerDriver.removeStatement(stmt);
|
changeSet.get().removeStatement(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteObjectProperty(Statement stmt) {
|
private void deleteObjectProperty(Statement stmt) {
|
||||||
this.reasonerDriver.deleteObjectProperty(stmt);
|
changeSet.get().deleteObjectProperty(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteDataProperty(Statement stmt) {
|
private void deleteDataProperty(Statement stmt) {
|
||||||
this.reasonerDriver.deleteDataProperty(stmt);
|
changeSet.get().deleteDataProperty(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The pattern matching stuff needs to get reworked.
|
// The pattern matching stuff needs to get reworked.
|
||||||
|
|
|
@ -22,6 +22,7 @@ public class TBoxChanges {
|
||||||
|
|
||||||
private final List<String> deletedDataPropertyUris = Collections
|
private final List<String> deletedDataPropertyUris = Collections
|
||||||
.synchronizedList(new ArrayList<String>());
|
.synchronizedList(new ArrayList<String>());
|
||||||
|
|
||||||
private final List<String> deletedObjectPropertyUris = Collections
|
private final List<String> deletedObjectPropertyUris = Collections
|
||||||
.synchronizedList(new ArrayList<String>());
|
.synchronizedList(new ArrayList<String>());
|
||||||
|
|
||||||
|
@ -53,8 +54,8 @@ public class TBoxChanges {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// These methods are called when processing the changeSet. By then, it is
|
// These methods are called when processing the changeSet. By that time, it
|
||||||
// owned and accessed by a single thread.
|
// is owned and accessed by a single thread.
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
|
|
|
@ -2,22 +2,14 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.tboxreasoner;
|
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
|
* What calls can the ConfiguredReasonerListener make to drive the TBox
|
||||||
* reasoner?
|
* reasoner?
|
||||||
*/
|
*/
|
||||||
public interface TBoxReasonerDriver {
|
public interface TBoxReasonerDriver {
|
||||||
void runSynchronizer();
|
|
||||||
|
|
||||||
void addStatement(Statement stmt);
|
void runSynchronizer(TBoxChanges changeSet);
|
||||||
|
|
||||||
void removeStatement(Statement stmt);
|
|
||||||
|
|
||||||
void deleteDataProperty(Statement stmt);
|
|
||||||
|
|
||||||
void deleteObjectProperty(Statement stmt);
|
|
||||||
|
|
||||||
boolean isReasoning();
|
boolean isReasoning();
|
||||||
|
|
||||||
|
@ -55,5 +47,4 @@ public interface TBoxReasonerDriver {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue