Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add logging and synchronization to RdfStream
  • Loading branch information
cbeer committed Sep 18, 2014
1 parent e2a6f16 commit f102dc1
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 6 deletions.
Expand Up @@ -88,6 +88,8 @@ public RdfStreamStreamingOutput(final RdfStream rdfStream,
throw new WebApplicationException(NOT_ACCEPTABLE);
}

LOGGER.trace("Streaming {}", rdfStream);

this.rdfStream = rdfStream;
}

Expand Down
Expand Up @@ -55,6 +55,7 @@ public class ChildrenRdfContext extends NodeRdfContext {
*/
public ChildrenRdfContext(final Node node, final IdentifierTranslator graphSubjects) throws RepositoryException {
super(node, graphSubjects);
LOGGER.debug("Getting {} for node {}", this, node.getPath());

if (node.hasNodes()) {
LOGGER.trace("Found children of this node.");
Expand Down
Expand Up @@ -48,6 +48,7 @@ public class ContainerRdfContext extends NodeRdfContext {
*/
public ContainerRdfContext(final Node node, final IdentifierTranslator graphSubjects) throws RepositoryException {
super(node, graphSubjects);
LOGGER.debug("Getting {} for node {}", this, node.getPath());

concat(containerContext());

Expand Down
Expand Up @@ -30,6 +30,7 @@
import static org.fcrepo.kernel.RdfLexicon.HAS_FIXITY_STATE;
import static org.fcrepo.kernel.RdfLexicon.HAS_CONTENT_LOCATION;
import static org.fcrepo.kernel.RdfLexicon.HAS_CONTENT_LOCATION_VALUE;
import static org.slf4j.LoggerFactory.getLogger;

import java.net.URI;
import java.util.Calendar;
Expand All @@ -45,6 +46,7 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterators;
import com.hp.hpl.jena.graph.Triple;
import org.slf4j.Logger;

/**
* An {@link org.fcrepo.kernel.utils.iterators.RdfStream} containing information about the fixity of a
Expand All @@ -55,6 +57,7 @@
*/
public class FixityRdfContext extends NodeRdfContext {

private static final Logger LOGGER = getLogger(FixityRdfContext.class);
/**
* Ordinary constructor.
*
Expand All @@ -66,6 +69,7 @@ public class FixityRdfContext extends NodeRdfContext {
public FixityRdfContext(final Node node, final IdentifierTranslator graphSubjects,
final Iterable<FixityResult> blobs, final URI digest, final long size) throws RepositoryException {
super(node, graphSubjects);
LOGGER.debug("Getting {} for node {}", this, node.getPath());

concat(Iterators.concat(Iterators.transform(blobs.iterator(),
new Function<FixityResult, Iterator<Triple>>() {
Expand Down
Expand Up @@ -59,6 +59,7 @@ public class NamespaceRdfContext extends RdfStream {
*/
public NamespaceRdfContext(final Session session) throws RepositoryException {
super();
LOGGER.debug("Getting {}", this);
final NamespaceRegistry namespaceRegistry =
session.getWorkspace().getNamespaceRegistry();
checkNotNull(namespaceRegistry,
Expand Down
Expand Up @@ -69,6 +69,7 @@ public class NodeRdfContext extends RdfStream {
*/
public NodeRdfContext(final Node node, final IdentifierTranslator graphSubjects) throws RepositoryException {
super();
LOGGER.debug("Getting {} for node {}", this, node.getPath());
this.node = node;
this.graphSubjects = graphSubjects;
this.subject = graphSubjects.getSubject(node.getPath()).asNode();
Expand Down Expand Up @@ -175,4 +176,9 @@ private void concatWritable() throws RepositoryException {
concat(create(subject(), WRITABLE.asNode(), createLiteral(String.valueOf(writable), XSDboolean)));
}

@Override
public String toString() {
return this.getClass() + "@" + System.identityHashCode(this) + "/" + node;
}

}
Expand Up @@ -72,6 +72,7 @@ public boolean apply(final ItemDefinition input) {
public NodeTypeRdfContext(final NodeTypeManager nodeTypeManager)
throws RepositoryException {
super();
LOGGER.debug("Getting {} for node {}", this);

concat(new NodeTypeRdfContext(new NodeTypeIterator(nodeTypeManager
.getPrimaryNodeTypes())));
Expand Down
Expand Up @@ -46,6 +46,7 @@ public class ParentRdfContext extends NodeRdfContext {
*/
public ParentRdfContext(final Node node, final IdentifierTranslator graphSubjects) throws RepositoryException {
super(node, graphSubjects);
LOGGER.debug("Getting {} for node {}", this, node.getPath());

if (node.getDepth() > 0) {
LOGGER.trace("Determined that this node has a parent.");
Expand Down
Expand Up @@ -65,6 +65,7 @@ public class PropertiesRdfContext extends NodeRdfContext {
public PropertiesRdfContext(final javax.jcr.Node node, final IdentifierTranslator graphSubjects)
throws RepositoryException {
super(node, graphSubjects);
LOGGER.debug("Getting {} for node {}", this, node.getPath());
property2triple = new PropertyToTriple(graphSubjects);
putPropertiesIntoContext();
}
Expand Down
Expand Up @@ -22,6 +22,7 @@
import org.fcrepo.kernel.impl.rdf.impl.mappings.ZippingIterator;
import org.fcrepo.kernel.utils.iterators.PropertyIterator;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.slf4j.Logger;

import javax.jcr.Node;
import javax.jcr.Property;
Expand All @@ -30,6 +31,7 @@
import java.util.Iterator;

import static org.fcrepo.kernel.impl.utils.FedoraTypesUtils.property2values;
import static org.slf4j.LoggerFactory.getLogger;

/**
* Accumulate inbound references to a given node
Expand All @@ -41,6 +43,7 @@ public class ReferencesRdfContext extends RdfStream {
private final Node node;
private PropertyToTriple property2triple;

private static final Logger LOGGER = getLogger(ReferencesRdfContext.class);
/**
* Add the inbound references from other nodes to this node to the {@link RdfStream}
*
Expand All @@ -52,6 +55,7 @@ public class ReferencesRdfContext extends RdfStream {
public ReferencesRdfContext(final javax.jcr.Node node, final IdentifierTranslator graphSubjects)
throws RepositoryException {
super();
LOGGER.debug("Getting {} for node {}", this, node.getPath());
this.node = node;
property2triple = new PropertyToTriple(graphSubjects);
concat(putStrongReferencePropertiesIntoContext());
Expand Down
Expand Up @@ -73,8 +73,7 @@ public class RootRdfContext extends NodeRdfContext {
public RootRdfContext(final Node node, final IdentifierTranslator graphSubjects) throws RepositoryException {

super(node, graphSubjects);

LOGGER.trace("Creating RDF triples for repository description");
LOGGER.debug("Getting {} for node {}", this, node.getPath());
final Repository repository = node().getSession().getRepository();

final ImmutableSet.Builder<Triple> b = builder();
Expand Down
Expand Up @@ -20,6 +20,7 @@
import static com.hp.hpl.jena.graph.Triple.create;
import static org.fcrepo.kernel.RdfLexicon.HAS_VERSION;
import static org.fcrepo.kernel.RdfLexicon.HAS_VERSION_LABEL;
import static org.slf4j.LoggerFactory.getLogger;

import java.util.Iterator;

Expand All @@ -36,6 +37,7 @@
import com.google.common.base.Function;
import com.google.common.collect.Iterators;
import com.hp.hpl.jena.graph.Triple;
import org.slf4j.Logger;


/**
Expand All @@ -47,6 +49,7 @@
*/
public class VersionsRdfContext extends RdfStream {

private static final Logger LOGGER = getLogger(VersionsRdfContext.class);
private final VersionManager versionManager;

private final VersionHistory versionHistory;
Expand All @@ -65,6 +68,7 @@ public class VersionsRdfContext extends RdfStream {
public VersionsRdfContext(final Node node, final IdentifierTranslator graphSubjects)
throws RepositoryException {
super();
LOGGER.debug("Getting {} for node {}", this, node.getPath());
this.graphSubjects = graphSubjects;
this.subject = graphSubjects.getSubject(node.getPath()).asNode();
versionManager = node.getSession().getWorkspace().getVersionManager();
Expand Down
Expand Up @@ -58,6 +58,7 @@ public class WorkspaceRdfContext extends RdfStream {
public WorkspaceRdfContext(final Session session, final IdentifierTranslator subjects)
throws RepositoryException {
super();
LOGGER.debug("Getting {}", this);

final String[] workspaces =
session.getWorkspace().getAccessibleWorkspaceNames();
Expand Down
Expand Up @@ -21,6 +21,7 @@
import static com.google.common.collect.Iterators.singletonIterator;
import static com.hp.hpl.jena.rdf.model.ModelFactory.createDefaultModel;
import static java.util.Objects.hash;
import static org.slf4j.LoggerFactory.getLogger;

import java.util.Collection;
import java.util.HashMap;
Expand All @@ -37,6 +38,7 @@
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.Statement;
import org.slf4j.Logger;

/**
* A stream of RDF triples along with some useful context.
Expand All @@ -46,6 +48,8 @@
*/
public class RdfStream extends ForwardingIterator<Triple> {

private static final Logger LOGGER = getLogger(RdfStream.class);

private Map<String, String> namespaces = new HashMap<>();

protected Iterator<Triple> triples;
Expand All @@ -63,6 +67,7 @@ public class RdfStream extends ForwardingIterator<Triple> {
*/
public <Tr extends Triple, T extends Iterator<Tr>> RdfStream(final T triples) {
super();
LOGGER.trace("Creating new {}: {}", this, triples);
this.triples = Iterators.transform(triples, cast());
}

Expand Down Expand Up @@ -142,12 +147,29 @@ public <Tr extends Triple, T extends Iterable<Tr>> RdfStream withThisContext(fin
return new RdfStream(stream).namespaces(namespaces()).topic(topic());
}

/**
* @param newTriples Triples to add.
* @return This object for continued use.
*/
public RdfStream concat(final RdfStream newTriples) {
LOGGER.trace("Concatenating {} with {}", this, newTriples);

synchronized (this) {
triples = Iterators.concat(newTriples, triples);
}
return this;
}

/**
* @param newTriples Triples to add.
* @return This object for continued use.
*/
public RdfStream concat(final Iterator<? extends Triple> newTriples) {
triples = Iterators.concat(newTriples, triples);
LOGGER.trace("Concatenating {} with {}", this, newTriples);

synchronized (this) {
triples = Iterators.concat(newTriples, triples);
}
return this;
}

Expand All @@ -156,7 +178,10 @@ public RdfStream concat(final Iterator<? extends Triple> newTriples) {
* @return This object for continued use.
*/
public <T extends Triple> RdfStream concat(final T newTriple) {
triples = Iterators.concat(singletonIterator(newTriple), triples);
LOGGER.trace("Concatenating {} with {}", this, newTriple);
synchronized (this) {
triples = Iterators.concat(singletonIterator(newTriple), triples);
}
return this;
}

Expand All @@ -165,7 +190,10 @@ public <T extends Triple> RdfStream concat(final T newTriple) {
* @return This object for continued use.
*/
public <T extends Triple> RdfStream concat(@SuppressWarnings("unchecked") final T... newTriples) {
triples = Iterators.concat(Iterators.forArray(newTriples), triples);
LOGGER.trace("Concatenating {} with {}", this, newTriples);
synchronized (this) {
triples = Iterators.concat(Iterators.forArray(newTriples), triples);
}
return this;
}

Expand All @@ -174,7 +202,11 @@ public <T extends Triple> RdfStream concat(@SuppressWarnings("unchecked") final
* @return This object for continued use.
*/
public RdfStream concat(final Collection<? extends Triple> newTriples) {
triples = Iterators.concat(newTriples.iterator(), triples);
LOGGER.trace("Concatenating {} with {}", this, newTriples);

synchronized (this) {
triples = Iterators.concat(newTriples.iterator(), triples);
}
return this;
}

Expand Down Expand Up @@ -377,4 +409,8 @@ public int hashCode() {
return hash(namespaces(), triples, topic());
}

@Override
public String toString() {
return this.getClass() + "@" + System.identityHashCode(this);
}
}

0 comments on commit f102dc1

Please sign in to comment.