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:
parent
b0c584b977
commit
074b7b34ba
|
@ -6,7 +6,10 @@
|
||||||
<Change>Modular handler discovery and delegation</Change>
|
<Change>Modular handler discovery and delegation</Change>
|
||||||
<Change>Fix: WSDL cache now releases the lock it acquires when clearing</Change>
|
<Change>Fix: WSDL cache now releases the lock it acquires when clearing</Change>
|
||||||
</Changeset>
|
</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>
|
<Change>Moved tests to separate suite</Change>
|
||||||
</Changeset>
|
</Changeset>
|
||||||
|
<Changeset component="${build.finalName}" date="2014-05-25">
|
||||||
|
<Change>Stub cache can be safely used across multiple classloaders</Change>
|
||||||
|
</Changeset>
|
||||||
</ReleaseNotes>
|
</ReleaseNotes>
|
2
pom.xml
2
pom.xml
|
@ -8,7 +8,7 @@
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>org.gcube.core</groupId>
|
<groupId>org.gcube.core</groupId>
|
||||||
<artifactId>common-gcore-stubs</artifactId>
|
<artifactId>common-gcore-stubs</artifactId>
|
||||||
<version>1.1.1-SNAPSHOT</version>
|
<version>1.2.0-SNAPSHOT</version>
|
||||||
<name>GCore Stubs</name>
|
<name>GCore Stubs</name>
|
||||||
<description>JAXWS Stub Support for gCore Service</description>
|
<description>JAXWS Stub Support for gCore Service</description>
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
import javax.xml.namespace.QName;
|
|
||||||
import javax.xml.ws.Service;
|
import javax.xml.ws.Service;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -28,9 +27,9 @@ class StubCache {
|
||||||
private volatile LRUCache cache = new LRUCache();
|
private volatile LRUCache cache = new LRUCache();
|
||||||
|
|
||||||
//holds key locks for LRU map
|
//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
|
//obtain a lock for current key
|
||||||
Lock nameLock = lockFor(name);
|
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
|
//obtain a lock for current key
|
||||||
Lock nameLock = lockFor(name);
|
Lock nameLock = lockFor(type);
|
||||||
|
|
||||||
nameLock.lock();
|
nameLock.lock();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
Service service = cache.get(name);
|
Service service = cache.get(type);
|
||||||
|
|
||||||
if (service==null)
|
if (service==null)
|
||||||
try {
|
try {
|
||||||
service= task.call();
|
service= task.call();
|
||||||
log.trace("caching stub for "+name);
|
log.info("caching stub for "+type);
|
||||||
cache.put(name,service);
|
cache.put(type,service);
|
||||||
}
|
}
|
||||||
catch(Exception e) {
|
catch(Exception e) {
|
||||||
throw new RuntimeException("could not build service",e);
|
throw new RuntimeException("could not build service",e);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log.trace("using cached stub for "+name);
|
log.info("using cached stub for "+type);
|
||||||
}
|
}
|
||||||
|
|
||||||
return service;
|
return service;
|
||||||
|
@ -79,7 +78,7 @@ class StubCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
//helper
|
//helper
|
||||||
private Lock lockFor(QName name) {
|
private Lock lockFor(Class<?> name) {
|
||||||
|
|
||||||
Lock nameLock = nameLocks.get(name);
|
Lock nameLock = nameLocks.get(name);
|
||||||
|
|
||||||
|
@ -99,7 +98,7 @@ class StubCache {
|
||||||
return nameLock;
|
return nameLock;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class LRUCache extends LinkedHashMap<QName,Service> {
|
private class LRUCache extends LinkedHashMap<Class<?>,Service> {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@ -111,7 +110,7 @@ class StubCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean removeEldestEntry(java.util.Map.Entry<QName, Service> eldest) {
|
protected boolean removeEldestEntry(java.util.Map.Entry<Class<?>, Service> eldest) {
|
||||||
if (size()>=max) {
|
if (size()>=max) {
|
||||||
nameLocks.remove(eldest.getKey());
|
nameLocks.remove(eldest.getKey());
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -102,7 +102,7 @@ public class StubFactory<T> implements StubFactoryDSL.AtClause<T> {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// get JAXWS service from endpoint address
|
// 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
|
// get JAXWS stub
|
||||||
T stub = service.getPort(reference,target.type(),features);
|
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
|
} 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);
|
throw new RuntimeException("could not configure discovery service", e);
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ public class StubFactory<T> implements StubFactoryDSL.AtClause<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper
|
// 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>() {
|
Callable<Service> task = new Callable<Service>() {
|
||||||
@Override
|
@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;
|
return service;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue