Removing obsolete namespace listener to avoid memory leak if WebappDaoFactories are unclosed
This commit is contained in:
parent
f516750e91
commit
25e8d41e52
1 changed files with 1 additions and 34 deletions
|
@ -7,14 +7,11 @@ import java.util.List;
|
||||||
|
|
||||||
import com.hp.hpl.jena.ontology.Individual;
|
import com.hp.hpl.jena.ontology.Individual;
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
import com.hp.hpl.jena.rdf.listeners.StatementListener;
|
|
||||||
import com.hp.hpl.jena.rdf.model.Literal;
|
import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
import com.hp.hpl.jena.rdf.model.ModelChangedListener;
|
|
||||||
import com.hp.hpl.jena.rdf.model.NodeIterator;
|
import com.hp.hpl.jena.rdf.model.NodeIterator;
|
||||||
import com.hp.hpl.jena.rdf.model.Property;
|
import com.hp.hpl.jena.rdf.model.Property;
|
||||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||||
import com.hp.hpl.jena.rdf.model.Statement;
|
|
||||||
import com.hp.hpl.jena.shared.Lock;
|
import com.hp.hpl.jena.shared.Lock;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
|
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
|
||||||
|
@ -29,12 +26,9 @@ public class ApplicationDaoJena extends JenaBaseDao implements ApplicationDao {
|
||||||
|
|
||||||
Integer portalCount = null;
|
Integer portalCount = null;
|
||||||
List<String> externallyLinkedNamespaces = null;
|
List<String> externallyLinkedNamespaces = null;
|
||||||
ModelChangedListener externalNamespaceChangeListener = null;
|
|
||||||
|
|
||||||
public ApplicationDaoJena(WebappDaoFactoryJena wadf) {
|
public ApplicationDaoJena(WebappDaoFactoryJena wadf) {
|
||||||
super(wadf);
|
super(wadf);
|
||||||
externalNamespaceChangeListener = new ExternalNamespacesChangeListener();
|
|
||||||
getOntModelSelector().getDisplayModel().register(externalNamespaceChangeListener);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getApplicationResourceURI() {
|
private String getApplicationResourceURI() {
|
||||||
|
@ -119,9 +113,7 @@ public class ApplicationDaoJena extends JenaBaseDao implements ApplicationDao {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
if (externalNamespaceChangeListener != null) {
|
// nothing to do right now
|
||||||
getOntModelSelector().getDisplayModel().unregister(externalNamespaceChangeListener);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final boolean CLEAR_CACHE = true;
|
private static final boolean CLEAR_CACHE = true;
|
||||||
|
@ -158,29 +150,4 @@ public class ApplicationDaoJena extends JenaBaseDao implements ApplicationDao {
|
||||||
return namespaces.contains(namespace);
|
return namespaces.contains(namespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ExternalNamespacesChangeListener extends StatementListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addedStatement(Statement stmt) {
|
|
||||||
process(stmt);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removedStatement(Statement stmt) {
|
|
||||||
process(stmt);
|
|
||||||
}
|
|
||||||
|
|
||||||
//We could also listen for end-of-edit events,
|
|
||||||
//but there should be so few of these statments that
|
|
||||||
//it won't be very expensive to run this method multiple
|
|
||||||
//times when the model is updated.
|
|
||||||
|
|
||||||
private void process(Statement stmt) {
|
|
||||||
if (stmt.getPredicate().equals(LINKED_NAMESPACE_PROP)) {
|
|
||||||
getExternallyLinkedNamespaces(CLEAR_CACHE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue