Lucio Lelii 9 years ago
parent 54d9fcf300
commit 3d5467032e

@ -1,4 +1,3 @@
#Mon Dec 03 17:40:30 CET 2012
eclipse.preferences.version=1 eclipse.preferences.version=1
encoding//src/main/java=UTF-8 encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8 encoding//src/main/resources=UTF-8

@ -19,4 +19,7 @@
<Changeset component="common-gcore-resources-1.3.0" date="2015-04-27"> <Changeset component="common-gcore-resources-1.3.0" date="2015-04-27">
<Change>Deprecated localAvailableStorage() methods and added replacements localAvailableSpace()</Change> <Change>Deprecated localAvailableStorage() methods and added replacements localAvailableSpace()</Change>
</Changeset> </Changeset>
<Changeset component="common-gcore-resources-1.3.1" date="2015-06-30">
<Change>Added lock on resource unmashalling</Change>
</Changeset>
</ReleaseNotes> </ReleaseNotes>

@ -8,7 +8,7 @@
</parent> </parent>
<groupId>org.gcube.resources</groupId> <groupId>org.gcube.resources</groupId>
<artifactId>common-gcore-resources</artifactId> <artifactId>common-gcore-resources</artifactId>
<version>1.3.0-SNAPSHOT</version> <version>1.3.1-SNAPSHOT</version>
<scm> <scm>
<connection>scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/${project.artifactId}</connection> <connection>scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/${project.artifactId}</connection>

@ -5,6 +5,8 @@ import java.util.LinkedHashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import javax.xml.bind.Marshaller; import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlAttribute;
@ -22,6 +24,9 @@ public abstract class Resource {
//default resource type version //default resource type version
private static String CURRENT_VERSION = "0.4.x"; private static String CURRENT_VERSION = "0.4.x";
protected transient Lock lock = new ReentrantLock();
/** /**
* The type of the resource * The type of the resource
*/ */

@ -147,6 +147,8 @@ public class Resources {
*/ */
public static <T extends Result> T marshal(Object resource,T result) { public static <T extends Result> T marshal(Object resource,T result) {
if (resource instanceof Resource)
((Resource) resource).lock.lock();
try { try {
JAXBContext context = context(resource.getClass()); JAXBContext context = context(resource.getClass());
Marshaller m = context.createMarshaller(); Marshaller m = context.createMarshaller();
@ -158,6 +160,9 @@ public class Resources {
} }
catch(Exception e) { catch(Exception e) {
throw new RuntimeException("serialisation error",e); throw new RuntimeException("serialisation error",e);
} finally{
if (resource instanceof Resource)
((Resource) resource).lock.unlock();
} }
} }

Loading…
Cancel
Save