You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2012/05/24 14:51:16 UTC
svn commit: r1342235 - in
/openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest:
RESTService.java RsRegistryImpl.java
Author: rmannibucau
Date: Thu May 24 12:51:16 2012
New Revision: 1342235
URL: http://svn.apache.org/viewvc?rev=1342235&view=rev
Log:
small refactoring on restservice for a better handling of undeployment
Modified:
openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RsRegistryImpl.java
Modified: openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java?rev=1342235&r1=1342234&r2=1342235&view=diff
==============================================================================
--- openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java (original)
+++ openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java Thu May 24 12:51:16 2012
@@ -72,7 +72,7 @@ public abstract class RESTService implem
private Assembler assembler;
private CoreContainerSystem containerSystem;
private RsRegistry rsRegistry;
- private List<String> services = new ArrayList<String>();
+ private List<DeployedService> services = new ArrayList<DeployedService>();
private String virtualHost;
public void afterApplicationCreated(final AppInfo appInfo, final WebAppInfo webApp) {
@@ -243,7 +243,7 @@ public abstract class RESTService implem
final RsHttpListener listener = createHttpListener();
final RsRegistry.AddressInfo address = rsRegistry.createRsHttpListener(contextRoot, listener, classLoader, nopath.substring(NOPATH_PREFIX.length() - 1), virtualHost);
- services.add(address.complete);
+ services.add(new DeployedService(address.complete, contextRoot));
listener.deploySingleton(getFullContext(address.base, contextRoot), o, appInstance);
LOGGER.info("deployed REST singleton: " + o);
@@ -266,7 +266,7 @@ public abstract class RESTService implem
final RsHttpListener listener = createHttpListener();
final RsRegistry.AddressInfo address = rsRegistry.createRsHttpListener(contextRoot, listener, classLoader, nopath.substring(NOPATH_PREFIX.length() - 1), virtualHost);
- services.add(address.complete);
+ services.add(new DeployedService(address.complete, contextRoot));
listener.deployPojo(getFullContext(address.base, contextRoot), loadedClazz, app, injections, context, owbCtx);
LOGGER.info("REST Service: " + address.complete + " -> Pojo " + loadedClazz.getName());
@@ -277,7 +277,7 @@ public abstract class RESTService implem
final RsHttpListener listener = createHttpListener();
final RsRegistry.AddressInfo address = rsRegistry.createRsHttpListener(context, listener, beanContext.getClassLoader(), nopath.substring(NOPATH_PREFIX.length() - 1), virtualHost);
- services.add(address.complete);
+ services.add(new DeployedService(address.complete, context));
listener.deployEJB(getFullContext(address.base, context), beanContext);
LOGGER.info("REST Service: " + address.complete + " -> EJB " + beanContext.getEjbName());
@@ -351,14 +351,18 @@ public abstract class RESTService implem
return cl;
}
- @Override public void beforeApplicationDestroyed(AppInfo appInfo) {
+ @Override
+ public void beforeApplicationDestroyed(AppInfo appInfo) {
if (deployedApplications.contains(appInfo)) {
for (WebAppInfo webApp : appInfo.webApps) {
- for (String address : services) {
- if (address.endsWith(webApp.contextRoot)) {
- undeployRestObject(address);
+ final List<DeployedService> toRemove = new ArrayList<DeployedService>();
+ for (DeployedService service : services) {
+ if (service.isInWebApp(webApp)) {
+ undeployRestObject(service.address);
+ toRemove.add(service);
}
}
+ services.removeAll(toRemove);
deployedWebApps.remove(webApp);
}
}
@@ -387,16 +391,16 @@ public abstract class RESTService implem
}
@Override public void stop() throws ServiceException {
- for (String address : services) {
- undeployRestObject(address);
- }
-
if (assembler != null) {
assembler.removeDeploymentListener(this);
for (AppInfo appInfo : new ArrayList<AppInfo>(deployedApplications)) {
beforeApplicationDestroyed(appInfo);
}
}
+
+ for (DeployedService service : services) {
+ undeployRestObject(service.address);
+ }
}
@Override public void service(InputStream in, OutputStream out) throws ServiceException, IOException {
@@ -440,4 +444,18 @@ public abstract class RESTService implem
this.context = context;
}
}
+
+ public static class DeployedService {
+ public String address;
+ public String webapp;
+
+ public DeployedService(String address, String webapp) {
+ this.address = address;
+ this.webapp = webapp;
+ }
+
+ public boolean isInWebApp(final WebAppInfo webApp) {
+ return webApp.contextRoot == webapp || (webapp != null && webapp.startsWith(webApp.contextRoot));
+ }
+ }
}
Modified: openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RsRegistryImpl.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RsRegistryImpl.java?rev=1342235&r1=1342234&r2=1342235&view=diff
==============================================================================
--- openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RsRegistryImpl.java (original)
+++ openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RsRegistryImpl.java Thu May 24 12:51:16 2012
@@ -38,8 +38,9 @@ public class RsRegistryImpl extends Open
String regex = addresses.get(context);
if (regex != null) {
HttpListener listener = registry.removeHttpListener(regex);
- if (listener instanceof ClassLoaderHttpListener)
- return ((ClassLoaderHttpListener) listener).getDelegate();
+ if (listener instanceof ClassLoaderHttpListener) {
+ return ((ClassLoaderHttpListener) listener).getDelegate();
+ }
}
return null;
}