Author: mir
Date: Mon Jun 28 12:39:07 2010
New Revision: 958557
URL: http://svn.apache.org/viewvc?rev=958557&view=rev
Log:
CLEREZZA-248: added locks
Modified:
incubator/clerezza/issues/CLEREZZA-248/org.apache.clerezza.platform.content.representations/org.apache.clerezza.platform.content.representations.core/src/main/java/org/apache/clerezza/platform/content/representations/core/AlternativeRepresentationGenerator.java
incubator/clerezza/issues/CLEREZZA-248/org.apache.clerezza.platform.content.representations/org.apache.clerezza.platform.content.representations.core/src/main/java/org/apache/clerezza/platform/content/representations/core/ThumbnailService.java
Modified:
incubator/clerezza/issues/CLEREZZA-248/org.apache.clerezza.platform.content.representations/org.apache.clerezza.platform.content.representations.core/src/main/java/org/apache/clerezza/platform/content/representations/core/AlternativeRepresentationGenerator.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-248/org.apache.clerezza.platform.content.representations/org.apache.clerezza.platform.content.representations.core/src/main/java/org/apache/clerezza/platform/content/representations/core/AlternativeRepresentationGenerator.java?rev=958557&r1=958556&r2=958557&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-248/org.apache.clerezza.platform.content.representations/org.apache.clerezza.platform.content.representations.core/src/main/java/org/apache/clerezza/platform/content/representations/core/AlternativeRepresentationGenerator.java
(original)
+++
incubator/clerezza/issues/CLEREZZA-248/org.apache.clerezza.platform.content.representations/org.apache.clerezza.platform.content.representations.core/src/main/java/org/apache/clerezza/platform/content/representations/core/AlternativeRepresentationGenerator.java
Mon Jun 28 12:39:07 2010
@@ -22,6 +22,7 @@ import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.util.concurrent.locks.Lock;
import javax.imageio.ImageIO;
import javax.ws.rs.core.MediaType;
import org.apache.clerezza.platform.content.DiscobitsHandler;
@@ -190,10 +191,17 @@ public class AlternativeRepresentationGe
resolution.getWidth(), resolution.getHeight());
byte[] alternativeImageBytes =
bufferedImage2ByteArray(alternativeImage, mediaType);
DiscobitsHandler contentHandler = (DiscobitsHandler)
discobitTracker.getService();
+
UriRef thumbnailUri = createThumbnailUri((UriRef)
node.getNode(), alternativeImage);
contentHandler.put(thumbnailUri, mediaType,
alternativeImageBytes);
- node.addProperty(DISCOBITS.thumbnail, thumbnailUri);
- return thumbnailUri;
+ Lock writeLock = node.writeLock();
+ writeLock.lock();
+ try {
+ node.addProperty(DISCOBITS.thumbnail, thumbnailUri);
+ return thumbnailUri;
+ } finally {
+ writeLock.unlock();
+ }
}
private byte[] bufferedImage2ByteArray(BufferedImage image,
Modified:
incubator/clerezza/issues/CLEREZZA-248/org.apache.clerezza.platform.content.representations/org.apache.clerezza.platform.content.representations.core/src/main/java/org/apache/clerezza/platform/content/representations/core/ThumbnailService.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-248/org.apache.clerezza.platform.content.representations/org.apache.clerezza.platform.content.representations.core/src/main/java/org/apache/clerezza/platform/content/representations/core/ThumbnailService.java?rev=958557&r1=958556&r2=958557&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-248/org.apache.clerezza.platform.content.representations/org.apache.clerezza.platform.content.representations.core/src/main/java/org/apache/clerezza/platform/content/representations/core/ThumbnailService.java
(original)
+++
incubator/clerezza/issues/CLEREZZA-248/org.apache.clerezza.platform.content.representations/org.apache.clerezza.platform.content.representations.core/src/main/java/org/apache/clerezza/platform/content/representations/core/ThumbnailService.java
Mon Jun 28 12:39:07 2010
@@ -25,6 +25,7 @@ import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import java.util.concurrent.locks.Lock;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
@@ -129,8 +130,7 @@ public class ThumbnailService implements
if (thumbnailUri != null) {
return Response.seeOther(
URI.create((thumbnailUri).getUnicodeString())).build();
- }
-
+ }
Iterator<Resource> mediaTypes =
infoBitNode.getObjects(DISCOBITS.mediaType);
if (mediaTypes.hasNext()) {
@@ -203,16 +203,22 @@ public class ThumbnailService implements
}
UriRef resultThumbnailUri = null;
int pixels = 0;
- Iterator<Resource> thumbnails =
infoBitNode.getObjects(DISCOBITS.thumbnail);
- while (thumbnails.hasNext()) {
- UriRef thumbnailUri = (UriRef) thumbnails.next();
- GraphNode thumbnailNode = new GraphNode(thumbnailUri,
- cgProvider.getContentGraph());
- int thumbnailPixels =
getSurfaceSizeIfFitting(thumbnailNode, width, height);
- if (thumbnailPixels > pixels) {
- resultThumbnailUri = thumbnailUri;
- pixels = thumbnailPixels;
+ Lock readLock = infoBitNode.readLock();
+ readLock.lock();
+ try {
+ Iterator<Resource> thumbnails =
infoBitNode.getObjects(DISCOBITS.thumbnail);
+ while (thumbnails.hasNext()) {
+ UriRef thumbnailUri = (UriRef)
thumbnails.next();
+ GraphNode thumbnailNode = new
GraphNode(thumbnailUri,
+ cgProvider.getContentGraph());
+ int thumbnailPixels =
getSurfaceSizeIfFitting(thumbnailNode, width, height);
+ if (thumbnailPixels > pixels) {
+ resultThumbnailUri = thumbnailUri;
+ pixels = thumbnailPixels;
+ }
}
+ } finally {
+ readLock.unlock();
}
return resultThumbnailUri;
}
@@ -225,7 +231,7 @@ public class ThumbnailService implements
Iterator<Resource> exifWidths =
infoBitNode.getObjects(EXIF.width);
Iterator<Resource> exifHeights =
infoBitNode.getObjects(EXIF.height);
if (!exifWidths.hasNext() || !exifHeights.hasNext()) {
- log.warn(infoBitNode.getNode() + " doesn't have
exif:width and exif:heigh");
+ log.warn(infoBitNode.getNode() + " doesn't have
exif:width and exif:height");
return -1;
}
Integer thumbnailWidth =
LiteralFactory.getInstance().createObject(
@@ -242,14 +248,20 @@ public class ThumbnailService implements
* returns true if infoBitNode is an image and fits
*/
private boolean isFittingImage(GraphNode infoBitNode, Integer width,
Integer height) {
- final Iterator<Literal> mediaTypesIter =
infoBitNode.getLiterals(DISCOBITS.mediaType);
- if (!mediaTypesIter.hasNext()) {
- return false;
- }
- if (mediaTypesIter.next().getLexicalForm().startsWith("image"))
{
- return getSurfaceSizeIfFitting(infoBitNode, width,
height) > -1;
- } else {
- return false;
+ Lock readLock = infoBitNode.readLock();
+ readLock.lock();
+ try {
+ final Iterator<Literal> mediaTypesIter =
infoBitNode.getLiterals(DISCOBITS.mediaType);
+ if (!mediaTypesIter.hasNext()) {
+ return false;
+ }
+ if
(mediaTypesIter.next().getLexicalForm().startsWith("image")) {
+ return getSurfaceSizeIfFitting(infoBitNode,
width, height) > -1;
+ } else {
+ return false;
+ }
+ } finally {
+ readLock.unlock();
}
}