Author: rmannibucau
Date: Fri Oct 12 12:12:49 2012
New Revision: 1397535
URL: http://svn.apache.org/viewvc?rev=1397535&view=rev
Log:
OPENEJB-1920 OPENEJB-1921 aggregating getresources for karafee + limiting
imported services to the visible ones
Modified:
openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/Deployer.java
openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/RegisterOSGIServicesExtension.java
Modified:
openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/Deployer.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/Deployer.java?rev=1397535&r1=1397534&r2=1397535&view=diff
==============================================================================
---
openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/Deployer.java
(original)
+++
openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/Deployer.java
Fri Oct 12 12:12:49 2012
@@ -29,6 +29,7 @@ import org.apache.openejb.config.Deploym
import org.apache.openejb.config.UnknownModuleTypeException;
import org.apache.openejb.core.ivm.IntraVmProxy;
import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.util.ArrayEnumeration;
import org.apache.openejb.util.proxy.ProxyEJB;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -44,6 +45,7 @@ import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
@@ -131,10 +133,14 @@ public class Deployer implements BundleL
final AppModule appModule = new
OSGiDeploymentLoader(bundle).load(bundleDump);
LOGGER.info("deploying bundle #" + bundle.getBundleId() +
" as an EJBModule");
+ RegisterOSGIServicesExtension.current = null;
+
final ConfigurationFactory configurationFactory = new
ConfigurationFactory();
final AppInfo appInfo =
configurationFactory.configureApplication(appModule);
appInfo.appId = "bundle_" + bundle.getBundleId();
+ RegisterOSGIServicesExtension.current = bundle;
+
final Assembler assembler =
SystemInstance.get().getComponent(Assembler.class);
final AppContext appContext =
assembler.createApplication(appInfo, osgiCl);
LOGGER.info("Application deployed: " + appInfo.path);
@@ -152,6 +158,7 @@ public class Deployer implements BundleL
LOGGER.error("can't deploy bundle #" + bundle.getBundleId(),
ex1);
}
} finally {
+ RegisterOSGIServicesExtension.current = null;
Thread.currentThread().setContextClassLoader(oldCl);
}
}
@@ -364,23 +371,24 @@ public class Deployer implements BundleL
@Override
protected Enumeration<URL> findResources(final String name) throws
IOException {
- Enumeration<URL> urls;
+ final Set<URL> urls = new HashSet<URL>();
try {
- urls = fallbackBundle.getResources(name);
- if (urls != null && urls.hasMoreElements()) {
- return urls;
+ final Enumeration<URL> furls =
fallbackBundle.getResources(name);
+ if (furls != null) {
+ while (furls.hasMoreElements()) {
+ urls.add(furls.nextElement());
+ }
}
} catch (IOException ignored) {
// no-op
}
- urls = backingBundle.getResources(name);
- if (urls != null && urls.hasMoreElements()) {
- return urls;
- }
- if (urls != null && urls.hasMoreElements()) {
- return urls;
+ final Enumeration<URL> burls = backingBundle.getResources(name);
+ if (burls != null) {
+ while (burls.hasMoreElements()) {
+ urls.add(burls.nextElement());
+ }
}
- return new EmptyEnumeration<URL>();
+ return new ArrayEnumeration(urls);
}
@Override
Modified:
openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/RegisterOSGIServicesExtension.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/RegisterOSGIServicesExtension.java?rev=1397535&r1=1397534&r2=1397535&view=diff
==============================================================================
---
openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/RegisterOSGIServicesExtension.java
(original)
+++
openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/RegisterOSGIServicesExtension.java
Fri Oct 12 12:12:49 2012
@@ -41,15 +41,20 @@ import java.util.Set;
public class RegisterOSGIServicesExtension implements Extension {
private static final Logger LOGGER =
LoggerFactory.getLogger(RegisterOSGIServicesExtension.class);
+ protected static Bundle current = null;
+
public void afterBeanDiscovery(@Observes final AfterBeanDiscovery abd) {
- final Bundle[] bundles = OpenEJBBundleContextHolder.get().getBundles();
- for (Bundle bundle : bundles) {
- final ServiceReference[] services = bundle.getRegisteredServices();
+ if (current != null) {
+ final ServiceReference[] services =
current.getRegisteredServices();
if (services != null) {
for (ServiceReference service : services) {
- final Class<?> clazz = serviceClass(service);
- abd.addBean(new OSGiServiceBean<Object>(service));
- LOGGER.debug("added service {} as a CDI Application scoped
bean", clazz.getName());
+ try {
+ final Class<?> clazz = serviceClass(service);
+ abd.addBean(new OSGiServiceBean<Object>(service));
+ LOGGER.debug("added service {} as a CDI Application
scoped bean", clazz.getName());
+ } catch (NoClassDefFoundError ignored) {
+ // no-op
+ }
}
}
}