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/10/12 18:25:18 UTC

svn commit: r1397632 - in /openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl: Deployer.java RegisterOSGIServicesExtension.java

Author: rmannibucau
Date: Fri Oct 12 16:25:18 2012
New Revision: 1397632

URL: http://svn.apache.org/viewvc?rev=1397632&view=rev
Log:
registring accessible osgi service

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=1397632&r1=1397631&r2=1397632&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 16:25:18 2012
@@ -24,20 +24,14 @@ import org.apache.openejb.UndeployExcept
 import org.apache.openejb.assembler.classic.AppInfo;
 import org.apache.openejb.assembler.classic.Assembler;
 import org.apache.openejb.config.AppModule;
-import org.apache.openejb.config.ConfigurableClasspathArchive;
 import org.apache.openejb.config.ConfigurationFactory;
 import org.apache.openejb.config.DeploymentLoader;
-import org.apache.openejb.config.EjbModule;
-import org.apache.openejb.config.FinderFactory;
-import org.apache.openejb.config.NewLoaderLogic;
 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.apache.xbean.finder.AnnotationFinder;
 import org.apache.xbean.finder.filter.Filter;
-import org.apache.xbean.osgi.bundle.util.BundleUtils;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleEvent;
@@ -48,7 +42,6 @@ import org.slf4j.LoggerFactory;
 
 import java.io.File;
 import java.io.IOException;
-import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -70,7 +63,6 @@ public class Deployer implements BundleL
 
     private final Map<Bundle, List<ServiceRegistration>> registrations = new ConcurrentHashMap<Bundle, List<ServiceRegistration>>();
     private final Map<Bundle, String> paths = new ConcurrentHashMap<Bundle, String>();
-    private final Map<Bundle, Set<URL>> libByBundle = new ConcurrentHashMap<Bundle, Set<URL>>();
 
     private final Activator openejbActivator;
 
@@ -120,6 +112,7 @@ public class Deployer implements BundleL
 
         Thread.currentThread().setContextClassLoader(osgiCl);
 
+        /*
         final Set<Bundle> wiredBundles = BundleUtils.getWiredBundles(bundle);
         final Set<URL> libs = new HashSet<URL>();
         final Filter filter = new OSGiPrefixFilter(NewLoaderLogic.getExclusions());
@@ -140,17 +133,18 @@ public class Deployer implements BundleL
                 // no-op
             }
 
-            final Set<URL> others = libByBundle.get(b);
-            if (others != null) {
-                libs.addAll(others);
-            }
+            // final Set<URL> others = libByBundle.get(b);
+            // if (others != null) {
+            //    libs.addAll(others);
+            //}
         }
+        */
 
         try {
             try {
                 try {
                     File bundleDump = findBundleFile(bundle);
-                    libs.remove(bundleDump.toURI().toURL()); // remove this bundle from libs
+                    // libs.remove(bundleDump.toURI().toURL()); // remove this bundle from libs
 
                     if (bundleDump == null || !bundleDump.exists()) {
                         LOGGER.warn("can't find bundle {}", bundle.getBundleId());
@@ -159,6 +153,7 @@ public class Deployer implements BundleL
 
                     LOGGER.info("looking bundle {} in {}", bundle.getBundleId(), bundleDump);
                     final AppModule appModule = new OSGiDeploymentLoader(bundle).load(bundleDump);
+                    /*
                     if (libs.size() > 0) {
                         for (EjbModule ejbModule : appModule.getEjbModules()) {
                             if (ejbModule.getJarLocation() != null) {
@@ -170,8 +165,9 @@ public class Deployer implements BundleL
                                 ejbModule.setFinder(annotationFinder.link());
                             }
                         }
-                        libByBundle.put(bundle, libs);
+                        // libByBundle.put(bundle, libs);
                     }
+                    */
                     LOGGER.info("deploying bundle #" + bundle.getBundleId() + " as an EJBModule");
 
                     final ConfigurationFactory configurationFactory = new ConfigurationFactory();
@@ -272,7 +268,8 @@ public class Deployer implements BundleL
     }
 
     private void undeploy(final Bundle bundle) {
-        libByBundle.remove(bundle);
+        // libByBundle.remove(bundle);
+
         if (registrations.containsKey(bundle)) {
             for (final ServiceRegistration registration : registrations.get(bundle)) {
                 try {

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=1397632&r1=1397631&r2=1397632&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 16:25:18 2012
@@ -45,15 +45,20 @@ public class RegisterOSGIServicesExtensi
 
     public void afterBeanDiscovery(@Observes final AfterBeanDiscovery abd) {
         if (current != null) {
-            final ServiceReference[] services = current.getRegisteredServices();
-            if (services != null) {
-                for (ServiceReference service  : services) {
-                    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
+            for (Bundle b : current.getBundleContext().getBundles()) {
+                final ServiceReference[] services = b.getRegisteredServices();
+                if (services != null) {
+                    for (ServiceReference service  : services) {
+                        try {
+                            final Class<?> clazz = serviceClass(service);
+                            current.loadClass(clazz.getName());
+                            abd.addBean(new OSGiServiceBean<Object>(service));
+                            LOGGER.debug("added service {} as a CDI Application scoped bean", clazz.getName());
+                        } catch (NoClassDefFoundError ignored) {
+                            // no-op
+                        } catch (ClassNotFoundException e) {
+                            // can't load the class so no need to register the service
+                        }
                     }
                 }
             }