Author: jmarino
Date: Sat May 13 16:05:09 2006
New Revision: 406160
URL: http://svn.apache.org/viewcvs?rev=406160&view=rev
Log:
fix for TUSCANY-367
Modified:
incubator/tuscany/java/sca/common/src/main/java/org/apache/tuscany/common/resource/impl/ResourceLoaderImpl.java
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/CompositeContext.java
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractCompositeContext.java
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/impl/WSDLDefinitionRegistryImpl.java
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeContextImpl.java
incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyContextListener.java
Modified:
incubator/tuscany/java/sca/common/src/main/java/org/apache/tuscany/common/resource/impl/ResourceLoaderImpl.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/common/src/main/java/org/apache/tuscany/common/resource/impl/ResourceLoaderImpl.java?rev=406160&r1=406159&r2=406160&view=diff
==============================================================================
---
incubator/tuscany/java/sca/common/src/main/java/org/apache/tuscany/common/resource/impl/ResourceLoaderImpl.java
(original)
+++
incubator/tuscany/java/sca/common/src/main/java/org/apache/tuscany/common/resource/impl/ResourceLoaderImpl.java
Sat May 13 16:05:09 2006
@@ -28,7 +28,7 @@
import org.apache.tuscany.common.resource.ResourceLoader;
/**
- * Default implementation of the ResourceLoader interface.
+ * Default implementation of the ResourceLoader interface
*
* @version $Rev: 369102 $ $Date: 2006-01-14 13:48:56 -0800 (Sat, 14 Jan 2006)
$
*/
Modified:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/CompositeContext.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/CompositeContext.java?rev=406160&r1=406159&r2=406160&view=diff
==============================================================================
---
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/CompositeContext.java
(original)
+++
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/CompositeContext.java
Sat May 13 16:05:09 2006
@@ -69,5 +69,7 @@
*/
@Deprecated
public Composite getComposite();
-
+
+ public void removeContext(String name);
+
}
Modified:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractCompositeContext.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractCompositeContext.java?rev=406160&r1=406159&r2=406160&view=diff
==============================================================================
---
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractCompositeContext.java
(original)
+++
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractCompositeContext.java
Sat May 13 16:05:09 2006
@@ -839,4 +839,14 @@
}
}
}
+
+
+ public void removeContext(String name){
+ configurations.remove(name);
+ ScopeContext ctx = scopeIndex.remove(name);
+ if (ctx != null){
+ ctx.removeContext(name);
+ }
+
+ }
}
Modified:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/impl/WSDLDefinitionRegistryImpl.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/impl/WSDLDefinitionRegistryImpl.java?rev=406160&r1=406159&r2=406160&view=diff
==============================================================================
---
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/impl/WSDLDefinitionRegistryImpl.java
(original)
+++
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/impl/WSDLDefinitionRegistryImpl.java
Sat May 13 16:05:09 2006
@@ -17,9 +17,9 @@
package org.apache.tuscany.core.loader.impl;
import java.io.IOException;
-import java.net.URL;
import java.net.URI;
import java.net.URISyntaxException;
+import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -38,6 +38,7 @@
import org.osoa.sca.annotations.Scope;
/**
+ * A WSDL definition registry with memory leaks. Keying off classloader as a
temporary hack to avoid WSDL collisions in different classloaders
* @version $Rev$ $Date$
*/
@org.osoa.sca.annotations.Service(interfaces = {WSDLDefinitionRegistry.class})
@@ -46,8 +47,8 @@
private final WSDLFactory wsdlFactory;
private final ExtensionRegistry registry;
- private final Map<URL, Definition> definitionsByLocation = new
HashMap<URL, Definition>();
- private final Map<String, List<Definition>> definitionsByNamespace = new
HashMap<String, List<Definition>>();
+ private final Map<ClassLoader, Map<URL, Definition>> definitionsByLocation
= new HashMap<ClassLoader, Map<URL, Definition>>();// new HashMap<URL,
Definition>();
+ private final Map<ClassLoader, Map<String, List<Definition>>>
definitionsByNamespace = new HashMap<ClassLoader, Map<String,
List<Definition>>>(); //new HashMap<String, List<Definition>>();
private Monitor monitor;
@@ -90,10 +91,17 @@
}
public Definition loadDefinition(String namespace, URL location) throws
IOException, WSDLException {
- Definition definition = definitionsByLocation.get(location);
- if (definition != null) {
- // return cached copy
- return definition;
+ Map<URL, Definition> localCache =
definitionsByLocation.get(Thread.currentThread().getContextClassLoader());
+ Definition definition;
+ if (localCache != null) {
+ definition = localCache.get(location);
+ if (definition != null) {
+ // return cached copy
+ return definition;
+ }
+ } else {
+ localCache = new HashMap<URL, Definition>();
+
definitionsByLocation.put(Thread.currentThread().getContextClassLoader(),
localCache);
}
monitor.readingWSDL(namespace, location);
@@ -108,32 +116,44 @@
}
monitor.cachingDefinition(definitionNamespace, location);
- definitionsByLocation.put(location, definition);
- List<Definition> definitions =
definitionsByNamespace.get(definitionNamespace);
+ localCache.put(location, definition);
+ Map<String, List<Definition>> localNamespaceCache =
definitionsByNamespace.get(Thread.currentThread().getContextClassLoader());
+ if (localNamespaceCache == null) {
+ localNamespaceCache = new HashMap<String, List<Definition>>();
+
definitionsByNamespace.put(Thread.currentThread().getContextClassLoader(),
localNamespaceCache);
+ }
+ List<Definition> definitions =
localNamespaceCache.get(definitionNamespace);
if (definitions == null) {
definitions = new ArrayList<Definition>();
- definitionsByNamespace.put(definitionNamespace, definitions);
+ localNamespaceCache.put(definitionNamespace, definitions);
}
definitions.add(definition);
return definition;
}
-
+
public List<Definition> getDefinitionsForNamespace(String namespace) {
- return definitionsByNamespace.get(namespace);
+ Map<String, List<Definition>> localNamespaceCache =
definitionsByNamespace.get(Thread.currentThread().getContextClassLoader());
+ if (localNamespaceCache != null) {
+ return localNamespaceCache.get(namespace);
+ }
+ return null;
}
-
+
public PortType getPortType(QName name) {
String namespace = name.getNamespaceURI();
- List<Definition> definitions = definitionsByNamespace.get(namespace);
- if (definitions == null) {
- return null;
- }
- for (Definition definition : definitions) {
- PortType portType = definition.getPortType(name);
- if (portType != null) {
- return portType;
+ Map<String, List<Definition>> localNamespaceCache =
definitionsByNamespace.get(Thread.currentThread().getContextClassLoader());
+ if (localNamespaceCache != null) {
+ List<Definition> definitions = localNamespaceCache.get(namespace);
+ if (definitions == null) {
+ return null;
+ }
+ for (Definition definition : definitions) {
+ PortType portType = definition.getPortType(name);
+ if (portType != null) {
+ return portType;
+ }
}
}
return null;
@@ -141,14 +161,18 @@
public Service getService(QName name) {
String namespace = name.getNamespaceURI();
- List<Definition> definitions = definitionsByNamespace.get(namespace);
- if (definitions == null) {
- return null;
- }
- for (Definition definition : definitions) {
- Service service = definition.getService(name);
- if (service != null) {
- return service;
+ Map<String, List<Definition>> localNamespaceCache =
definitionsByNamespace.get(Thread.currentThread().getContextClassLoader());
+ if (localNamespaceCache != null) {
+ List<Definition> definitions = localNamespaceCache.get(namespace);
+ if (definitions == null) {
+ return null;
+ }
+
+ for (Definition definition : definitions) {
+ Service service = definition.getService(name);
+ if (service != null) {
+ return service;
+ }
}
}
return null;
@@ -156,20 +180,19 @@
public static interface Monitor {
/**
- * Monitor event emitted immediately before an attempt is made to
- * read WSDL for the supplied namespace from the supplied location.
+ * Monitor event emitted immediately before an attempt is made to read
WSDL for the supplied namespace
+ * from the supplied location.
*
* @param namespace the target namespace expected in the WSDL; may be
null
- * @param location the location where we will attempt to read the WSDL
definition from
+ * @param location the location where we will attempt to read the
WSDL definition from
*/
void readingWSDL(String namespace, URL location);
/**
- * Monitor event emitted immediately before registering a WSDL
definition
- * in the cache.
+ * Monitor event emitted immediately before registering a WSDL
definition in the cache.
*
* @param namespace the target namespace for the WSDL
- * @param location the location where the WSDL definition was read from
+ * @param location the location where the WSDL definition was read
from
*/
void cachingDefinition(String namespace, URL location);
}
Modified:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeContextImpl.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeContextImpl.java?rev=406160&r1=406159&r2=406160&view=diff
==============================================================================
---
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeContextImpl.java
(original)
+++
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeContextImpl.java
Sat May 13 16:05:09 2006
@@ -208,6 +208,10 @@
return systemContext.getComposite();
}
+ public void removeContext(String name) {
+
+ }
+
private void checkRunning() {
if (lifecycleState != RUNNING) {
throw new IllegalStateException("Context must be in RUNNING
state");
Modified:
incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyContextListener.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyContextListener.java?rev=406160&r1=406159&r2=406160&view=diff
==============================================================================
---
incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyContextListener.java
(original)
+++
incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyContextListener.java
Sat May 13 16:05:09 2006
@@ -98,10 +98,17 @@
throw e;
}
+ // hack for TUSCANY-367
+ Valve[] valves = ctx.getPipeline().getValves();
+ for (Valve valve : valves) {
+ if (valve instanceof TuscanyValve){
+ ctx.getPipeline().removeValve(valve);
+ }
+ }
+
// add a valve to this context's pipeline that will associate the
request with the runtime
Valve valve = new TuscanyValve(moduleContext);
ctx.getPipeline().addValve(valve);
-
// add the RuntimeContext in as a servlet context parameter
ServletContext servletContext = ctx.getServletContext();
servletContext.setAttribute(TUSCANY_RUNTIME_NAME, runtime);
@@ -126,7 +133,6 @@
moduleContext = (CompositeContext)
rootContext.getContext(moduleComponent.getName());
//TODO remove the hack below
moduleContext.setAssemblyContext(modelContext);
-
} finally {
Thread.currentThread().setContextClassLoader(oldCl);
}
@@ -136,6 +142,10 @@
if (moduleContext != null) {
moduleContext.publish(new ModuleStop(this));
}
+ CompositeContext rootContext = runtime.getRootContext();
+ rootContext.removeContext(moduleContext.getName());
+ moduleContext.stop();
+ moduleContext = null;
// todo unload module component from runtime
}