merged from trunk

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/branches/common/common-gcore-stubs/1.0@96087 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
fabio.simeoni 2014-05-25 21:30:29 +00:00
parent b0c584b977
commit 074b7b34ba
4 changed files with 20 additions and 18 deletions

View File

@ -6,7 +6,10 @@
<Change>Modular handler discovery and delegation</Change>
<Change>Fix: WSDL cache now releases the lock it acquires when clearing</Change>
</Changeset>
<Changeset component="${build.finalName}" date="2013-11-06">
<Changeset component="common-gcore-stubs-1.1.1" date="2013-11-06">
<Change>Moved tests to separate suite</Change>
</Changeset>
<Changeset component="${build.finalName}" date="2014-05-25">
<Change>Stub cache can be safely used across multiple classloaders</Change>
</Changeset>
</ReleaseNotes>

View File

@ -8,7 +8,7 @@
</parent>
<groupId>org.gcube.core</groupId>
<artifactId>common-gcore-stubs</artifactId>
<version>1.1.1-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
<name>GCore Stubs</name>
<description>JAXWS Stub Support for gCore Service</description>

View File

@ -6,7 +6,6 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import org.slf4j.Logger;
@ -28,9 +27,9 @@ class StubCache {
private volatile LRUCache cache = new LRUCache();
//holds key locks for LRU map
private ConcurrentHashMap<QName,Lock> nameLocks = new ConcurrentHashMap<QName, Lock>();
private ConcurrentHashMap<Class<?>,Lock> nameLocks = new ConcurrentHashMap<Class<?>, Lock>();
void clear(QName name) {
void clear(Class<?> name) {
//obtain a lock for current key
Lock nameLock = lockFor(name);
@ -47,28 +46,28 @@ class StubCache {
}
Service get(QName name,Callable<Service> task) {
Service get(Class<?> type,Callable<Service> task) {
//obtain a lock for current key
Lock nameLock = lockFor(name);
Lock nameLock = lockFor(type);
nameLock.lock();
try {
Service service = cache.get(name);
Service service = cache.get(type);
if (service==null)
try {
service= task.call();
log.trace("caching stub for "+name);
cache.put(name,service);
log.info("caching stub for "+type);
cache.put(type,service);
}
catch(Exception e) {
throw new RuntimeException("could not build service",e);
}
else {
log.trace("using cached stub for "+name);
log.info("using cached stub for "+type);
}
return service;
@ -79,7 +78,7 @@ class StubCache {
}
//helper
private Lock lockFor(QName name) {
private Lock lockFor(Class<?> name) {
Lock nameLock = nameLocks.get(name);
@ -99,7 +98,7 @@ class StubCache {
return nameLock;
}
private class LRUCache extends LinkedHashMap<QName,Service> {
private class LRUCache extends LinkedHashMap<Class<?>,Service> {
private static final long serialVersionUID = 1L;
@ -111,7 +110,7 @@ class StubCache {
}
@Override
protected boolean removeEldestEntry(java.util.Map.Entry<QName, Service> eldest) {
protected boolean removeEldestEntry(java.util.Map.Entry<Class<?>, Service> eldest) {
if (size()>=max) {
nameLocks.remove(eldest.getKey());
return true;

View File

@ -102,7 +102,7 @@ public class StubFactory<T> implements StubFactoryDSL.AtClause<T> {
try {
// get JAXWS service from endpoint address
Service service = buildService(endpointAddress+"?wsdl", target.qName());
Service service = buildService(endpointAddress+"?wsdl", target.type(),target.qName());
// get JAXWS stub
T stub = service.getPort(reference,target.type(),features);
@ -116,7 +116,7 @@ public class StubFactory<T> implements StubFactoryDSL.AtClause<T> {
} catch (Error e) { //bad stubs/wsdls cause java.lang.Errors
cache.clear(target.qName()); //clear cache
cache.clear(target.type()); //clear cache
throw new RuntimeException("could not configure discovery service", e);
@ -136,7 +136,7 @@ public class StubFactory<T> implements StubFactoryDSL.AtClause<T> {
}
// helper
private synchronized Service buildService(final String wsdlAddress, final QName name) throws Exception {
private synchronized Service buildService(final String wsdlAddress, final Class<?> type, final QName name) throws Exception {
Callable<Service> task = new Callable<Service>() {
@Override
@ -146,7 +146,7 @@ public class StubFactory<T> implements StubFactoryDSL.AtClause<T> {
}
};
Service service = cache.get(name,task);
Service service = cache.get(type,task);
return service;
}