clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r959662 - in /incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.typerendering/org.apache.clerezza.platform.typerendering.core/src: main/java/org/apache/clerezza/platform/typerendering/ test/java/org/apache/cle...
Date Thu, 01 Jul 2010 13:49:05 GMT
Author: reto
Date: Thu Jul  1 13:49:05 2010
New Revision: 959662

URL: http://svn.apache.org/viewvc?rev=959662&view=rev
Log:
added missing lock on config-graph

Modified:
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.typerendering/org.apache.clerezza.platform.typerendering.core/src/main/java/org/apache/clerezza/platform/typerendering/RenderletRendererFactoryImpl.java
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.typerendering/org.apache.clerezza.platform.typerendering.core/src/test/java/org/apache/clerezza/platform/typerendering/RendereringManagerTest.java

Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.typerendering/org.apache.clerezza.platform.typerendering.core/src/main/java/org/apache/clerezza/platform/typerendering/RenderletRendererFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.typerendering/org.apache.clerezza.platform.typerendering.core/src/main/java/org/apache/clerezza/platform/typerendering/RenderletRendererFactoryImpl.java?rev=959662&r1=959661&r2=959662&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.typerendering/org.apache.clerezza.platform.typerendering.core/src/main/java/org/apache/clerezza/platform/typerendering/RenderletRendererFactoryImpl.java
(original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.typerendering/org.apache.clerezza.platform.typerendering.core/src/main/java/org/apache/clerezza/platform/typerendering/RenderletRendererFactoryImpl.java
Thu Jul  1 13:49:05 2010
@@ -28,6 +28,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
+import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 import java.util.regex.Pattern;
 import javax.ws.rs.core.MediaType;
@@ -50,6 +51,7 @@ import org.apache.clerezza.rdf.core.Reso
 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.core.event.FilterTriple;
 import org.apache.clerezza.rdf.core.event.GraphListener;
 import org.apache.clerezza.rdf.core.impl.TripleImpl;
@@ -79,7 +81,7 @@ public class RenderletRendererFactoryImp
 	private Logger logger = LoggerFactory.getLogger(RenderletRendererFactoryImpl.class);
 	
 	@Reference(target = PlatformConfig.CONFIG_GRAPH_FILTER)
-	private MGraph configGraph;
+	private LockableMGraph configGraph;
 
 	private static final String RDF_TYPE_PRIO_LIST_URI =
 			"http://tpf.localhost/rdfTypePriorityList";
@@ -168,43 +170,49 @@ public class RenderletRendererFactoryImp
 			UriRef rdfType,
 			String mode,
 			MediaType mediaType, boolean builtIn) {
-		removeExisting(rdfType, mode, mediaType, builtIn);
-		BNode renderletDefinition = new BNode();
-		GraphNode renderletDefinitionNode = new GraphNode(renderletDefinition, configGraph);
-		configGraph.add(new TripleImpl(renderletDefinition,
-				TYPERENDERING.renderlet, LiteralFactory.getInstance().createTypedLiteral(renderlet)));
-		if (renderingSpecification != null) {
+		Lock l = configLock.writeLock();
+		l.lock();
+		try {
+			removeExisting(rdfType, mode, mediaType, builtIn);
+			BNode renderletDefinition = new BNode();
+			GraphNode renderletDefinitionNode = new GraphNode(renderletDefinition, configGraph);
 			configGraph.add(new TripleImpl(renderletDefinition,
-					TYPERENDERING.renderingSpecification, renderingSpecification));
-		}
-		configGraph.add(new TripleImpl(renderletDefinition,
-				TYPERENDERING.renderedType, rdfType));
-
-		configGraph.add(new TripleImpl(renderletDefinition,
-				TYPERENDERING.mediaType, LiteralFactory.getInstance().createTypedLiteral(mediaType.toString())));
-		renderletDefinitionNode.addProperty(RDF.type, TYPERENDERING.RenderletDefinition);
-
-		if (builtIn) {
-			renderletDefinitionNode.addProperty(RDF.type,
-					TYPERENDERING.BuiltInRenderletDefinition);
-		} else {
-			renderletDefinitionNode.addProperty(RDF.type,
-					TYPERENDERING.CustomRenderletDefinition);
-		}
+					TYPERENDERING.renderlet, LiteralFactory.getInstance().createTypedLiteral(renderlet)));
+			if (renderingSpecification != null) {
+				configGraph.add(new TripleImpl(renderletDefinition,
+						TYPERENDERING.renderingSpecification, renderingSpecification));
+			}
+			configGraph.add(new TripleImpl(renderletDefinition,
+					TYPERENDERING.renderedType, rdfType));
 
-		if (mode != null) {
 			configGraph.add(new TripleImpl(renderletDefinition,
-					TYPERENDERING.renderingMode, LiteralFactory.getInstance().createTypedLiteral(mode)));
-		}
+					TYPERENDERING.mediaType, LiteralFactory.getInstance().createTypedLiteral(mediaType.toString())));
+			renderletDefinitionNode.addProperty(RDF.type, TYPERENDERING.RenderletDefinition);
 
-		synchronized(this) {
-			if (!rdfTypePrioList.contains(rdfType)) {
-				if (rdfType.equals(RDFS.Resource)) {
-					rdfTypePrioList.add(RDFS.Resource);
-				} else {
-					rdfTypePrioList.add(0, rdfType);
+			if (builtIn) {
+				renderletDefinitionNode.addProperty(RDF.type,
+						TYPERENDERING.BuiltInRenderletDefinition);
+			} else {
+				renderletDefinitionNode.addProperty(RDF.type,
+						TYPERENDERING.CustomRenderletDefinition);
+			}
+
+			if (mode != null) {
+				configGraph.add(new TripleImpl(renderletDefinition,
+						TYPERENDERING.renderingMode, LiteralFactory.getInstance().createTypedLiteral(mode)));
+			}
+
+			synchronized(this) {
+				if (!rdfTypePrioList.contains(rdfType)) {
+					if (rdfType.equals(RDFS.Resource)) {
+						rdfTypePrioList.add(RDFS.Resource);
+					} else {
+						rdfTypePrioList.add(0, rdfType);
+					}
 				}
 			}
+		} finally {
+			l.unlock();
 		}
 		type2DefinitionMap = null;
 	}
@@ -230,12 +238,18 @@ public class RenderletRendererFactoryImp
 
 		//keeping this independent of typedefinitionmap to allow better performance
 		List<RenderletDefinition> definitionList = new ArrayList<RenderletDefinition>();
-		Iterator<Triple> renderletDefsTriple =
-				configGraph.filter(null, TYPERENDERING.renderedType, rdfType);
-		while (renderletDefsTriple.hasNext()) {
-			definitionList.add(
-					new RenderletDefinition((BNode) renderletDefsTriple.next().getSubject(),
-					configGraph));
+		Lock l = configGraph.getLock().readLock();
+		l.lock();
+		try {
+			Iterator<Triple> renderletDefsTriple =
+					configGraph.filter(null, TYPERENDERING.renderedType, rdfType);
+			while (renderletDefsTriple.hasNext()) {
+				definitionList.add(
+						new RenderletDefinition((BNode) renderletDefsTriple.next().getSubject(),
+						configGraph));
+			}
+		} finally {
+			l.unlock();
 		}
 		for (RenderletDefinition renderletDef : definitionList) {
 
@@ -286,7 +300,8 @@ public class RenderletRendererFactoryImp
 
 	protected void unbindRenderlet(ServiceReference renderletRef) {
 		logger.info("Unbind renderlet of bundle {}", renderletRef.getBundle().getSymbolicName());
-		configLock.writeLock().lock();
+		Lock l = configLock.writeLock();
+		l.unlock();
 		try {
 			if (!renderletRefStore.remove(renderletRef)) {
 				String servicePid = (String) renderletRef.getProperty(Constants.SERVICE_PID);
@@ -294,7 +309,7 @@ public class RenderletRendererFactoryImp
 				unregisterRenderletService(servicePid, renderlet);
 			}
 		} finally {
-			configLock.writeLock().unlock();
+			l.unlock();
 		}
 	}
 
@@ -374,11 +389,11 @@ public class RenderletRendererFactoryImp
 		}
 	}
 
-	protected void bindConfigGraph(MGraph configGraph) {
+	protected void bindConfigGraph(LockableMGraph configGraph) {
 		this.configGraph = configGraph;
 	}
 
-	protected void unbindConfigGraph(MGraph configGraph) {
+	protected void unbindConfigGraph(LockableMGraph configGraph) {
 		this.configGraph = null;
 	}
 }

Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.typerendering/org.apache.clerezza.platform.typerendering.core/src/test/java/org/apache/clerezza/platform/typerendering/RendereringManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.typerendering/org.apache.clerezza.platform.typerendering.core/src/test/java/org/apache/clerezza/platform/typerendering/RendereringManagerTest.java?rev=959662&r1=959661&r2=959662&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.typerendering/org.apache.clerezza.platform.typerendering.core/src/test/java/org/apache/clerezza/platform/typerendering/RendereringManagerTest.java
(original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.typerendering/org.apache.clerezza.platform.typerendering.core/src/test/java/org/apache/clerezza/platform/typerendering/RendereringManagerTest.java
Thu Jul  1 13:49:05 2010
@@ -21,6 +21,7 @@ package org.apache.clerezza.platform.typ
 import java.util.ArrayList;
 import javax.ws.rs.ext.RuntimeDelegate;
 import org.apache.clerezza.rdf.core.Resource;
+import org.apache.clerezza.rdf.core.access.LockableMGraphWrapper;
 import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
 import org.apache.clerezza.triaxrs.delegate.RuntimeDelegateImpl;
 
@@ -38,7 +39,7 @@ public class RendereringManagerTest exte
 		manager = renderer;
 		renderer.rdfTypePrioList = new ArrayList<Resource>();		
 		RuntimeDelegate.setInstance(new RuntimeDelegateImpl());
-		renderer.bindConfigGraph(new SimpleMGraph());
+		renderer.bindConfigGraph(new LockableMGraphWrapper(new SimpleMGraph()));
 		renderer.registerRenderletService(renderletMockA.pid, renderletMockA);
 		renderer.registerRenderletService(renderletMockB.pid, renderletMockB);
 		return renderer;



Mime
View raw message