clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@apache.org
Subject svn commit: r1004304 - /incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/
Date Mon, 04 Oct 2010 16:10:59 GMT
Author: mir
Date: Mon Oct  4 16:10:59 2010
New Revision: 1004304

URL: http://svn.apache.org/viewvc?rev=1004304&view=rev
Log:
CLEREZZA-313: added missing locks

Modified:
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/AbstractDiscobitsHandler.java
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/ContentPostSupport.java
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/DiscobitsTypeHandler.java
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/InfoDiscobit.java
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/WebDavUtils.java

Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/AbstractDiscobitsHandler.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/AbstractDiscobitsHandler.java?rev=1004304&r1=1004303&r2=1004304&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/AbstractDiscobitsHandler.java
(original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/AbstractDiscobitsHandler.java
Mon Oct  4 16:10:59 2010
@@ -23,6 +23,7 @@ import java.util.HashSet;
 import java.util.Iterator;
 
 import java.util.Set;
+import java.util.concurrent.locks.Lock;
 import javax.ws.rs.core.MediaType;
 import org.apache.clerezza.platform.content.collections.CollectionCreator;
 
@@ -32,6 +33,7 @@ import org.apache.clerezza.rdf.core.NonL
 import org.apache.clerezza.rdf.core.Triple;
 import org.apache.clerezza.rdf.core.TypedLiteral;
 import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.LockableMGraph;
 import org.apache.clerezza.rdf.ontologies.DISCOBITS;
 import org.apache.clerezza.rdf.ontologies.RDF;
 import org.apache.clerezza.rdf.utils.GraphNode;
@@ -66,17 +68,23 @@ public abstract class AbstractDiscobitsH
 			byte[] data) {
 
 		GraphNode infoDiscoBitNode;
-		final MGraph mGraph = getMGraph();
+		final LockableMGraph mGraph = (LockableMGraph) getMGraph();
 		infoDiscoBitNode = new GraphNode(infoDiscoBitUri, mGraph);
 		CollectionCreator collectionCreator = new CollectionCreator(mGraph);
 		collectionCreator.createContainingCollections(infoDiscoBitUri);
-		infoDiscoBitNode.addProperty(RDF.type, DISCOBITS.InfoDiscoBit);
-		TypedLiteral dataLiteral = LiteralFactory.getInstance().createTypedLiteral(data);
-		infoDiscoBitNode.deleteProperties(DISCOBITS.infoBit);
-		infoDiscoBitNode.addProperty(DISCOBITS.infoBit, dataLiteral);
-		TypedLiteral mediaTypeLiteral = LiteralFactory.getInstance().createTypedLiteral(mediaType.toString());
-		infoDiscoBitNode.deleteProperties(DISCOBITS.mediaType);
-		infoDiscoBitNode.addProperty(DISCOBITS.mediaType,mediaTypeLiteral);
+		Lock writeLock = mGraph.getLock().writeLock();
+		writeLock.lock();
+		try {
+			infoDiscoBitNode.addProperty(RDF.type, DISCOBITS.InfoDiscoBit);
+			TypedLiteral dataLiteral = LiteralFactory.getInstance().createTypedLiteral(data);
+			infoDiscoBitNode.deleteProperties(DISCOBITS.infoBit);
+			infoDiscoBitNode.addProperty(DISCOBITS.infoBit, dataLiteral);
+			TypedLiteral mediaTypeLiteral = LiteralFactory.getInstance().createTypedLiteral(mediaType.toString());
+			infoDiscoBitNode.deleteProperties(DISCOBITS.mediaType);
+			infoDiscoBitNode.addProperty(DISCOBITS.mediaType,mediaTypeLiteral);
+		} finally {
+			writeLock.unlock();
+		}
 		Set<MetaDataGenerator> metaDataGenerators = getMetaDataGenerators();
 		synchronized(metaDataGenerators) {
 			for(MetaDataGenerator generator : metaDataGenerators) {

Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/ContentPostSupport.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/ContentPostSupport.java?rev=1004304&r1=1004303&r2=1004304&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/ContentPostSupport.java
(original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/ContentPostSupport.java
Mon Oct  4 16:10:59 2010
@@ -20,6 +20,7 @@ package org.apache.clerezza.platform.con
 
 
 import java.net.URI;
+import java.util.concurrent.locks.Lock;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.POST;
 import javax.ws.rs.Path;
@@ -30,6 +31,7 @@ import org.apache.clerezza.jaxrs.utils.f
 import org.apache.clerezza.jaxrs.utils.form.MultiPartBody;
 import org.apache.clerezza.platform.graphprovider.content.ContentGraphProvider;
 import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.LockableMGraph;
 import org.apache.clerezza.rdf.ontologies.RDF;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Property;
@@ -77,10 +79,17 @@ public class ContentPostSupport {
 			return Response.status(400).entity("Required form field is missing").
 					type(MediaType.TEXT_PLAIN_TYPE).build();
 		}
-		if (cgProvider.getContentGraph().filter(new UriRef(uri), RDF.type, null).hasNext()) {
-			return Response.status(Response.Status.CONFLICT).
-					entity("A resource with the specified URI already exists").
-					type(MediaType.TEXT_PLAIN_TYPE).build();
+		LockableMGraph contentGraph = cgProvider.getContentGraph();
+		Lock readLock = contentGraph.getLock().readLock();
+		readLock.lock();
+		try {
+			if (contentGraph.filter(new UriRef(uri), RDF.type, null).hasNext()) {
+				return Response.status(Response.Status.CONFLICT).
+						entity("A resource with the specified URI already exists").
+						type(MediaType.TEXT_PLAIN_TYPE).build();
+			}
+		} finally {
+			readLock.unlock();
 		}
 		handler.put(new UriRef(uri), formFile.getMediaType(), content);
 		return Response.created(URI.create(uri)).build();

Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/DiscobitsTypeHandler.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/DiscobitsTypeHandler.java?rev=1004304&r1=1004303&r2=1004304&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/DiscobitsTypeHandler.java
(original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/DiscobitsTypeHandler.java
Mon Oct  4 16:10:59 2010
@@ -142,7 +142,6 @@ public class DiscobitsTypeHandler extend
 	@GET
 	@Produces({"*/*"})
 	public Object getResource(@Context UriInfo uriInfo) {
-		final MGraph mGraph = cgProvider.getContentGraph();
 		final UriRef uri = new UriRef(uriInfo.getAbsolutePath().toString());
 		final GraphNode graphNode = getResourceAsGraphNode(uriInfo);
 		if (graphNode == null) {
@@ -418,7 +417,13 @@ public class DiscobitsTypeHandler extend
 				logger.error("more than one parent statement: "+oldParentTripleIter.next());
 				oldParentTripleIter.remove();
 			}
-			node.replaceWith(targetUri);
+			Lock writeLock = node.writeLock();
+			writeLock.lock();
+			try {
+				node.replaceWith(targetUri);
+			} finally {
+				writeLock.unlock();
+			}
 			new CollectionCreator(mGraph).createContainingCollections(targetUri);
 			try {
 				return Response.created(new java.net.URI(targetUri.getUnicodeString())).build();
@@ -492,7 +497,7 @@ public class DiscobitsTypeHandler extend
 				}
 				builder.header(HeaderName.ALLOW.toString(), buffer.toString());
 			}
-			return builder.build();
+		return builder.build();
 	}
 
 	protected void bindMetaDataGenerator(MetaDataGenerator generator) {
@@ -516,9 +521,15 @@ public class DiscobitsTypeHandler extend
 	
 
 	private boolean nodeAtUriExists(UriRef nodeUri) {
-		MGraph mGraph = getMGraph();
-		return mGraph.filter(nodeUri, null, null).hasNext()
-				|| mGraph.filter(null, null, nodeUri).hasNext();
+		LockableMGraph mGraph = (LockableMGraph) getMGraph();
+		Lock readLock = mGraph.getLock().readLock();
+		readLock.lock();
+		try {
+			return mGraph.filter(nodeUri, null, null).hasNext()
+					|| mGraph.filter(null, null, nodeUri).hasNext();
+		} finally {
+			readLock.unlock();
+		}
 	}
 
 	private Response resourceUnavailable(UriRef nodeUri,

Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/InfoDiscobit.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/InfoDiscobit.java?rev=1004304&r1=1004303&r2=1004304&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/InfoDiscobit.java
(original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/InfoDiscobit.java
Mon Oct  4 16:10:59 2010
@@ -65,24 +65,35 @@ public class InfoDiscobit {
 	}
 
 	public String getContentType() {
-		Iterator<Literal> mediaTypeLits = infoBit.getLiterals(DISCOBITS.mediaType);
-		if (mediaTypeLits.hasNext()) {
-			return mediaTypeLits.next().getLexicalForm();
+		Lock readLock = infoBit.readLock();
+		readLock.lock();
+		try {
+			Iterator<Literal> mediaTypeLits = infoBit.getLiterals(DISCOBITS.mediaType);
+			if (mediaTypeLits.hasNext()) {
+				return mediaTypeLits.next().getLexicalForm();
+			}
+		} finally {
+			readLock.unlock();
 		}
 		return null;
 	}
 	
 	public byte[] getData() {
 		byte[] result = null;
-		Iterator<Literal> mediaTypeLits = infoBit.getLiterals(DISCOBITS.infoBit);
-		if (mediaTypeLits.hasNext()) {
-			final Literal literalValue = mediaTypeLits.next();
-			if (literalValue instanceof TypedLiteral) {
-				result = LiteralFactory.getInstance().createObject(
-						(new byte[0]).getClass(),(TypedLiteral)literalValue);
+		Lock readLock = infoBit.readLock();
+		readLock.lock();
+		try {
+			Iterator<Literal> mediaTypeLits = infoBit.getLiterals(DISCOBITS.infoBit);
+			if (mediaTypeLits.hasNext()) {
+				final Literal literalValue = mediaTypeLits.next();
+				if (literalValue instanceof TypedLiteral) {
+					result = LiteralFactory.getInstance().createObject(
+							(new byte[0]).getClass(), (TypedLiteral) literalValue);
+				}
 			}
-		}
-		
+		} finally {
+			readLock.unlock();
+		}		
 		return result;	
 	};
 

Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/WebDavUtils.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/WebDavUtils.java?rev=1004304&r1=1004303&r2=1004304&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/WebDavUtils.java
(original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/WebDavUtils.java
Mon Oct  4 16:10:59 2010
@@ -29,6 +29,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.locks.Lock;
 import javax.ws.rs.HttpMethod;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.Response;
@@ -43,6 +44,7 @@ import javax.xml.transform.dom.DOMResult
 import org.apache.clerezza.rdf.core.Literal;
 import org.apache.clerezza.rdf.core.LiteralFactory;
 import org.apache.clerezza.rdf.core.Resource;
+import org.apache.clerezza.rdf.core.Triple;
 import org.apache.clerezza.rdf.core.TripleCollection;
 import org.apache.clerezza.rdf.core.UriRef;
 import org.apache.clerezza.rdf.core.impl.TripleImpl;
@@ -370,7 +372,14 @@ class WebDavUtils {
 
 	private static void addUserProps(GraphNode node, PropertyMap propertyMap,
 			List<Property> requestedProps) {
-		Iterator<UriRef> userPropsIter = node.getProperties();
+		Iterator<UriRef> userPropsIter;
+		Lock readLock = node.readLock();
+		readLock.lock(); 
+		try {
+			userPropsIter = node.getProperties();
+		} finally {
+			readLock.unlock();
+		}
 		Set<UriRef> userProps = new HashSet<UriRef>();
 		while (userPropsIter.hasNext()) {
 			userProps.add(userPropsIter.next());
@@ -380,11 +389,16 @@ class WebDavUtils {
 			for (Property requestedProp : requestedProps) {
 				UriRef predicate = new UriRef(requestedProp.value());
 				if (userProps.contains(predicate)) {
-					Iterator<Resource> value = node.getObjects(predicate);
-					if (value.hasNext()) {
-						propertyMap.put(requestedProp, getValue(value.next()));
-					} else {
-						propertyMap.put(requestedProp, "");
+					readLock.lock();
+					try {
+						Iterator<Resource> value = node.getObjects(predicate);
+						if (value.hasNext()) {
+							propertyMap.put(requestedProp, getValue(value.next()));
+						} else {
+							propertyMap.put(requestedProp, "");
+						}
+					} finally {
+						readLock.unlock();
 					}
 				} else {
 					propertyMap.put(requestedProp, null);
@@ -401,10 +415,15 @@ class WebDavUtils {
 						userProp.substring(index + 1));
 
 				Iterator<Resource> value = node.getObjects(uri);
-				if (value.hasNext()) {
-					propertyMap.put(property, getValue(value.next()));
-				} else {
-					propertyMap.put(property, "");
+				readLock.lock();
+				try {
+					if (value.hasNext()) {
+						propertyMap.put(property, getValue(value.next()));
+					} else {
+						propertyMap.put(property, "");
+					}
+				} finally {
+					readLock.unlock();
 				}
 			}
 		}
@@ -412,7 +431,14 @@ class WebDavUtils {
 
 	private static void addUserPropsWithoutValues(GraphNode node,
 			PropertyMap propertyMap) {
-		Iterator<UriRef> userPropsIter = node.getProperties();
+		Iterator<UriRef> userPropsIter;
+		Lock readLock = node.readLock();
+		readLock.lock();
+		try {
+			userPropsIter = node.getProperties();
+		} finally {
+			readLock.unlock();
+		}
 		Set<UriRef> userProps = new HashSet<UriRef>();
 		while (userPropsIter.hasNext()) {
 			userProps.add(userPropsIter.next());
@@ -465,28 +491,46 @@ class WebDavUtils {
 						propertyMap.put(property, "");
 					}
 				} else if(property.prop.equalsIgnoreCase(creationdate)){
-					Iterator<Resource> date = node.getObjects(DCTERMS.dateSubmitted);
-					if(date.hasNext()){
-						String st = getValue(date.next());
-						propertyMap.put(property, st);
-					}else{
-						propertyMap.put(property, "");
+					Lock readLock = node.readLock();
+					readLock.lock();
+					try {
+						Iterator<Resource> date = node.getObjects(DCTERMS.dateSubmitted);
+						if (date.hasNext()) {
+							String st = getValue(date.next());
+							propertyMap.put(property, st);
+						} else {
+							propertyMap.put(property, "");
+						}
+					} finally {
+						readLock.unlock();
 					}
 				} else if(property.prop.equalsIgnoreCase(getlastmodified)){
-					Iterator<Resource> date = node.getObjects(DCTERMS.modified);
-					if(date.hasNext()){
-						String st = getValue(date.next());
-						propertyMap.put(property, st);
-					}else{
-						propertyMap.put(property, "");
+					Lock readLock = node.readLock();
+					readLock.lock();
+					try {
+						Iterator<Resource> date = node.getObjects(DCTERMS.modified);
+						if (date.hasNext()) {
+							String st = getValue(date.next());
+							propertyMap.put(property, st);
+						} else {
+							propertyMap.put(property, "");
+						}
+					} finally {
+						readLock.unlock();
 					}
 				} else if(property.prop.equalsIgnoreCase(getcontenttype)){
-					Iterator<Resource> mediaType = node.getObjects(DCTERMS.MediaType);
-					if(mediaType.hasNext()){
-						String st = getValue(mediaType.next());
-						propertyMap.put(property, st);
-					}else{
-						propertyMap.put(property, "");
+					Lock readLock = node.readLock();
+					readLock.lock();
+					try {
+						Iterator<Resource> mediaType = node.getObjects(DCTERMS.MediaType);
+						if (mediaType.hasNext()) {
+							String st = getValue(mediaType.next());
+							propertyMap.put(property, st);
+						} else {
+							propertyMap.put(property, "");
+						}
+					} finally {
+						readLock.unlock();
 					}
 				} else {
 					propertyMap.put(property, "");
@@ -534,15 +578,26 @@ class WebDavUtils {
 							.createElementNS(davUri, property.prop));
 				} else {
 					UriRef predicate = new UriRef(property.value());
-					Iterator<Resource> valIter = hierarchyNode.getObjects(predicate);
-					replaceProp(subject, predicate, valIter, contentGraph, entry);
+					Lock writeLock = hierarchyNode.writeLock();
+					writeLock.lock();
+					try {
+						Iterator<Resource> valIter = hierarchyNode.getObjects(predicate);
+						replaceProp(subject, predicate, valIter, contentGraph, entry);
+					} finally {
+						writeLock.unlock();
+					}
 					propOk.appendChild(responseDoc.createElementNS(davUri, property.prop));
 				}
-			}else{
-				
+			} else {
 				UriRef predicate = new UriRef(property.value());
-				Iterator<Resource> valIter = hierarchyNode.getObjects(predicate);
-				replaceProp(subject, predicate, valIter, contentGraph, entry);
+				Lock writeLock = hierarchyNode.writeLock();
+				writeLock.lock();
+				try {
+					Iterator<Resource> valIter = hierarchyNode.getObjects(predicate);
+					replaceProp(subject, predicate, valIter, contentGraph, entry);
+				} finally {
+					writeLock.unlock();
+				}
 				propOk.appendChild(responseDoc.createElementNS(property.ns, "R:" + property.prop));
 			}
 		}
@@ -554,9 +609,17 @@ class WebDavUtils {
 							.createElementNS(davUri, property.prop));
 			} else {
 				UriRef predicate = new UriRef(property.value());
-				Iterator<Resource> valIter = hierarchyNode.getObjects(predicate);
-				while(valIter.hasNext()){
-					contentGraph.remove(new TripleImpl(subject, predicate, valIter.next()));
+				Lock writeLock = hierarchyNode.writeLock();
+				writeLock.lock();
+				try {
+					Iterator<Resource> valIter = hierarchyNode.getObjects(predicate);
+					Set<Triple> triplesToBeRemoved = new HashSet<Triple>();
+					while (valIter.hasNext()) {
+						triplesToBeRemoved.add(new TripleImpl(subject, predicate, valIter.next()));
+					}
+					contentGraph.removeAll(triplesToBeRemoved);
+				} finally {
+					writeLock.unlock();
 				}
 				propOk.appendChild(responseDoc.createElementNS(property.ns, property.prop));
 
@@ -603,9 +666,11 @@ class WebDavUtils {
 			Iterator<Resource> valIter, TripleCollection contentGraph,
 			Map.Entry<Property, String> entry) {
 		LiteralFactory fac = LiteralFactory.getInstance();
+		Set<Triple> triplesToBeRemoved = new HashSet<Triple>();
 		if (valIter.hasNext()) {
-			contentGraph.remove(new TripleImpl(subject, predicate, valIter.next()));
+			triplesToBeRemoved.add(new TripleImpl(subject, predicate, valIter.next()));
 		}
+		contentGraph.removeAll(triplesToBeRemoved);
 		contentGraph.add(new TripleImpl(subject, predicate,
 				fac.createTypedLiteral(entry.getValue())));
 	}



Mime
View raw message