You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sa...@apache.org on 2008/07/13 15:27:09 UTC

svn commit: r676321 - in /webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi: deployment/AbstractRegistry.java deployment/ModuleRegistry.java deployment/Registry.java deployment/ServiceRegistry.java internal/Activator.java

Author: saminda
Date: Sun Jul 13 06:27:08 2008
New Revision: 676321

URL: http://svn.apache.org/viewvc?rev=676321&view=rev
Log:
Improved service & module depdendency properly 

Modified:
    webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/AbstractRegistry.java
    webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/ModuleRegistry.java
    webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/Registry.java
    webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/ServiceRegistry.java
    webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/internal/Activator.java

Modified: webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/AbstractRegistry.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/AbstractRegistry.java?rev=676321&r1=676320&r2=676321&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/AbstractRegistry.java (original)
+++ webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/AbstractRegistry.java Sun Jul 13 06:27:08 2008
@@ -20,6 +20,8 @@
 import org.osgi.framework.BundleEvent;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.context.ConfigurationContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import java.util.Map;
 import java.util.List;
@@ -33,6 +35,8 @@
  */
 public abstract class AbstractRegistry<V> implements Registry {
 
+    private Log log = LogFactory.getLog(AbstractRegistry.class);
+
     protected Map<Bundle, List<V>> resolvedBundles = new ConcurrentHashMap<Bundle, List<V>>();
 
     protected List<Bundle> unreslovedBundles = new ArrayList<Bundle>();
@@ -60,15 +64,18 @@
 
                 case BundleEvent.STOPPED:
                     if (context.getBundle() != bundle) {
-                        unRegister(event.getBundle());
+                        unRegister(event.getBundle(), false);
+                    }
+                    break;
+                case BundleEvent.UNINSTALLED:
+                    if (context.getBundle() != bundle) {
+                        remove(bundle);
                     }
                     break;
             }
         } catch (AxisFault e) {
-            //TODO: TDB use, log service error instead
-            e.printStackTrace();
             String msg = "Error while registering the bundle in AxisConfiguration";
-            throw new RuntimeException(msg, e);
+            log.error(msg, e);
         }
     }
 

Modified: webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/ModuleRegistry.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/ModuleRegistry.java?rev=676321&r1=676320&r2=676321&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/ModuleRegistry.java (original)
+++ webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/ModuleRegistry.java Sun Jul 13 06:27:08 2008
@@ -16,27 +16,25 @@
 package org.apache.axis2.osgi.deployment;
 
 import org.apache.axis2.AxisFault;
-import org.apache.axis2.engine.AxisConfiguration;
-import org.apache.axis2.modules.Module;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.deployment.DeploymentEngine;
 import org.apache.axis2.deployment.ModuleBuilder;
 import org.apache.axis2.description.AxisModule;
-import org.apache.axis2.description.AxisServiceGroup;
-import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.AxisServiceGroup;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.modules.Module;
+import static org.apache.axis2.osgi.deployment.OSGiAxis2Constants.OSGi_BUNDLE_ID;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
 
 import java.io.IOException;
 import java.net.URL;
 import java.util.*;
 
-import static org.apache.axis2.osgi.deployment.OSGiAxis2Constants.*;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
 /**
  * @see org.osgi.framework.BundleListener
  */
@@ -63,64 +61,75 @@
 
     }
 
-    public void unRegister(Bundle bundle) {
+    public void unRegister(Bundle bundle, boolean uninstall) {
         lock.lock();
         try {
-            List<Long> stopBundleList = new ArrayList<Long>();
+
             List<AxisModule> moduleList = resolvedBundles.get(bundle);
-            for (AxisModule module : moduleList) {
-                AxisConfiguration axisConfig = configCtx.getAxisConfiguration();
-                for (Iterator iterator = axisConfig.getServiceGroups(); iterator.hasNext();) {
-                    AxisServiceGroup axisServiceGroup = (AxisServiceGroup) iterator.next();
-                    if (axisServiceGroup.isEngaged(module)) {
-                        Long value = (Long) axisServiceGroup.getParameterValue(OSGi_BUNDLE_ID);
-                        if (value != null) {
-                            stopBundleList.add(value);
-                        }
-                    }
-                }
-                //
-                HashMap serviceMap = axisConfig.getServices();
-                Collection values = serviceMap.values();
-                for (Object value1 : values) {
-                    AxisService axisService = (AxisService) value1;
-                    if (axisService.isEngaged(module)) {
-                        Long value = (Long) axisService.getParameterValue(OSGi_BUNDLE_ID);
-                        if (value != null && !stopBundleList.contains(value)) {
-                            stopBundleList.add(value);
+            if (moduleList != null) {
+                List<Long> stopBundleList = new ArrayList<Long>();
+                for (AxisModule module : moduleList) {
+                    AxisConfiguration axisConfig = configCtx.getAxisConfiguration();
+                    for (Iterator iterator = axisConfig.getServiceGroups(); iterator.hasNext();) {
+                        AxisServiceGroup axisServiceGroup = (AxisServiceGroup) iterator.next();
+                        if (axisServiceGroup.isEngaged(module)) {
+                            Long value = (Long) axisServiceGroup.getParameterValue(OSGi_BUNDLE_ID);
+                            if (value != null) {
+                                stopBundleList.add(value);
+                            }
                         }
                     }
-                    for (Iterator iterator1 = axisService.getOperations(); iterator1.hasNext();) {
-                        AxisOperation axisOperation = (AxisOperation) iterator1.next();
-                        if (axisOperation.isEngaged(module)) {
-                            Long value = (Long) axisOperation.getParameterValue(OSGi_BUNDLE_ID);
+                    //
+                    HashMap serviceMap = axisConfig.getServices();
+                    Collection values = serviceMap.values();
+                    for (Object value1 : values) {
+                        AxisService axisService = (AxisService) value1;
+                        if (axisService.isEngaged(module)) {
+                            Long value = (Long) axisService.getParameterValue(OSGi_BUNDLE_ID);
                             if (value != null && !stopBundleList.contains(value)) {
                                 stopBundleList.add(value);
                             }
                         }
+                        for (Iterator iterator1 = axisService.getOperations(); iterator1.hasNext();)
+                        {
+                            AxisOperation axisOperation = (AxisOperation) iterator1.next();
+                            if (axisOperation.isEngaged(module)) {
+                                Long value = (Long) axisOperation.getParameterValue(OSGi_BUNDLE_ID);
+                                if (value != null && !stopBundleList.contains(value)) {
+                                    stopBundleList.add(value);
+                                }
+                            }
+                        }
                     }
+                    Module moduleInterface = module.getModule();
+                    if (moduleInterface != null) {
+                        try {
+                            moduleInterface.shutdown(configCtx);
+                        } catch (AxisFault e) {
+                            String msg = "Error while shutting down the module : " +
+                                         module.getName() + " : " +
+                                         module.getVersion() + " moduel in Bundle - " +
+                                         bundle.getSymbolicName();
+                            log.error(msg, e);
+                        }
+                    }
+                    axisConfig.removeModule(module.getName(), module.getVersion());
+                    if (resolvedBundles.containsKey(bundle)) {
+                        resolvedBundles.remove(bundle);
+                    }
+                    log.info("[Axis2/OSGi] Stopping :" + module.getName() + " : " +
+                             module.getVersion() + " moduel in Bundle - " +
+                             bundle.getSymbolicName());
                 }
-                axisConfig.removeModule(module.getName(), module.getVersion());
-                if (resolvedBundles.containsKey(bundle)) {
-                    resolvedBundles.remove(bundle);
-                }
-                log.info("[Axis2/OSGi] Stopping :" + module.getName() + " : " +
-                         module.getVersion() + " moduel in Bundle - " +
-                         bundle.getSymbolicName());
-            }
-            for (Long bundleId : stopBundleList) {
-                Bundle stopBundle = context.getBundle(bundleId);
-                if (stopBundle != null) {
-                    try {
-                        serviceRegistry.unRegister(stopBundle);
-                        stopBundle.stop();
-                    } catch (BundleException e) {
-                        String msg = "Error while stopping the bundle";
-                        log.error(msg, e);
-                    } catch (AxisFault e) {
-                        String msg = "Erro while stopping the bundle";
-                        log.error(msg, e);
-
+                for (Long bundleId : stopBundleList) {
+                    Bundle unRegBundle = context.getBundle(bundleId);
+                    if (unRegBundle != null) {
+                        try {
+                            serviceRegistry.unRegister(unRegBundle, false);
+                        }  catch (AxisFault e) {
+                            String msg = "Erro while stopping the bundle";
+                            log.error(msg, e);
+                        }
                     }
                 }
             }
@@ -195,4 +204,8 @@
         }
 
     }
+
+    public void remove(Bundle bundle) throws AxisFault {
+        unRegister(bundle, true);
+    }
 }

Modified: webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/Registry.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/Registry.java?rev=676321&r1=676320&r2=676321&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/Registry.java (original)
+++ webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/Registry.java Sun Jul 13 06:27:08 2008
@@ -27,7 +27,9 @@
 
     void register(Bundle bundle) throws AxisFault;
 
-    void unRegister(Bundle bundle) throws AxisFault;
+    void unRegister(Bundle bundle, boolean uninstall) throws AxisFault;
 
     void resolve() throws AxisFault;
+
+    void remove(Bundle bundle) throws AxisFault;
 }

Modified: webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/ServiceRegistry.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/ServiceRegistry.java?rev=676321&r1=676320&r2=676321&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/ServiceRegistry.java (original)
+++ webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/ServiceRegistry.java Sun Jul 13 06:27:08 2008
@@ -158,38 +158,54 @@
 
     }
 
-    public void unRegister(Bundle bundle) throws AxisFault {
+    public void unRegister(Bundle bundle, boolean uninstall) throws AxisFault {
         lock.lock();
         try {
             List<AxisServiceGroup> axisServiceGroupList = resolvedBundles.get(bundle);
-            for (AxisServiceGroup axisServiceGroup : axisServiceGroupList) {
-                if (resolvedBundles.containsKey(bundle)) {
-                    resolvedBundles.remove(bundle);
-                }
-                if (unreslovedBundles.contains(bundle)) {
-                    unreslovedBundles.remove(bundle);
-                }
-                try {
-                    for (Iterator iterator = axisServiceGroup.getServices(); iterator.hasNext();) {
-                        AxisService service = (AxisService) iterator.next();
-                        System.out.println("[Axis2/OSGi] Service - " + service.getName());
+            if (axisServiceGroupList != null) {
+                for (AxisServiceGroup axisServiceGroup : axisServiceGroupList) {
+                    if (resolvedBundles.containsKey(bundle)) {
+                        resolvedBundles.remove(bundle);
+                    }
+                    if (!unreslovedBundles.contains(bundle) && !uninstall) {
+                        unreslovedBundles.add(bundle);
+                    }
+                    try {
+                        for (Iterator iterator = axisServiceGroup.getServices();
+                             iterator.hasNext();) {
+                            AxisService service = (AxisService) iterator.next();
+                            System.out.println("[Axis2/OSGi] Service - " + service.getName());
+                        }
+                        configCtx.getAxisConfiguration()
+                                .removeServiceGroup(axisServiceGroup.getServiceGroupName());
+                        System.out.println("[Axis2/OSGi] Stopping " +
+                                           axisServiceGroup.getServiceGroupName() +
+                                           " service group in Bundle - " +
+                                           bundle.getSymbolicName());
+                    } catch (AxisFault e) {
+                        String msg = "Error while removing the service group";
+                        log.error(msg, e);
                     }
-                    configCtx.getAxisConfiguration()
-                            .removeServiceGroup(axisServiceGroup.getServiceGroupName());
-                    System.out.println("[Axis2/OSGi] Stopping " +
-                                       axisServiceGroup.getServiceGroupName() +
-                                       " service group in Bundle - " +
-                                       bundle.getSymbolicName());
-                } catch (AxisFault e) {
-                    String msg = "Error while removing the service group";
-                    log.error(msg, e);
-                }
 
+                }
             }
         } finally {
             lock.unlock();
         }
     }
 
-
+    public void remove(Bundle bundle) throws AxisFault {
+        unRegister(bundle, true);
+        lock.lock();
+        try {
+            if (resolvedBundles.containsKey(bundle)) {
+                resolvedBundles.remove(bundle);
+            }
+            if (unreslovedBundles.contains(bundle)) {
+                unreslovedBundles.remove(bundle);
+            }
+        } finally {
+            lock.unlock();
+        }
+    }
 }

Modified: webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/internal/Activator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/internal/Activator.java?rev=676321&r1=676320&r2=676321&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/internal/Activator.java (original)
+++ webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/internal/Activator.java Sun Jul 13 06:27:08 2008
@@ -31,7 +31,7 @@
 /**
  * Activator will set the necessary parameters that initiate Axis2 OSGi integration
  */
-public class Activator implements BundleActivator, FrameworkListener {
+public class Activator implements BundleActivator{
 
     private static Log log = LogFactory.getLog(Activator.class);
 
@@ -39,17 +39,11 @@
 
     private final OSGiConfigurationContextFactory managedService;
 
-    private BundleContext context;
-
-
     public Activator() {
         managedService = new OSGiConfigurationContextFactory();
     }
 
-
     public void start(BundleContext context) throws Exception {
-        context.addFrameworkListener(this);
-        this.context = context;
         managedService.init(context);
         managedService.updated(null);
         tracker = new HttpServiceTracker(context);
@@ -67,30 +61,6 @@
         }
     }
 
-    public void frameworkEvent(FrameworkEvent event) {
-        if (event.getType() == FrameworkEvent.PACKAGES_REFRESHED) {
-            try {
-                Runnable thread = new Runnable() {
-                    public void run() {
-                        Bundle thisBundle = context.getBundle();
-                        try {
-                            thisBundle.stop();
-                            thisBundle.start();
-                        } catch (BundleException e) {
-                            String msg = "Error while refreshing the bundle";
-                            log.error(msg, e);
-                        }
-                    }
-                };
-                new Thread(thread).start();
-            } catch (Exception e) {
-                String msg = "Error while FrameworkEvent.PACKAGES_REFRESHED";
-                log.error(msg, e);
-            }
-        }
-
-    }
-
     //HttpServiceTracker
 
     class HttpServiceTracker extends ServiceTracker {