axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sami...@apache.org
Subject svn commit: r675229 - in /webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment: AbstractRegistry.java ModuleRegistry.java ServiceRegistry.java
Date Wed, 09 Jul 2008 15:31:58 GMT
Author: saminda
Date: Wed Jul  9 08:31:57 2008
New Revision: 675229

URL: http://svn.apache.org/viewvc?rev=675229&view=rev
Log:
1. Added logs and removed souts
2. Added services and modules to have *modules.xml and *services.xml. 
3. Improved the deployment logic a lot 

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/ServiceRegistry.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=675229&r1=675228&r2=675229&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
Wed Jul  9 08:31:57 2008
@@ -33,7 +33,7 @@
  */
 public abstract class AbstractRegistry<V> implements Registry {
 
-    protected Map<Bundle, V> resolvedBundles = new ConcurrentHashMap<Bundle, V>();
+    protected Map<Bundle, List<V>> resolvedBundles = new ConcurrentHashMap<Bundle,
List<V>>();
 
     protected List<Bundle> unreslovedBundles = new ArrayList<Bundle>();
 

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=675229&r1=675228&r2=675229&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
Wed Jul  9 08:31:57 2008
@@ -34,16 +34,20 @@
 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
- * TODO: TBD removed sout
  */
 public class ModuleRegistry extends AbstractRegistry<AxisModule> {
 
+    private static Log log = LogFactory.getLog(ModuleRegistry.class);
+
     private Registry serviceRegistry;
 
-    public ModuleRegistry(BundleContext context, ConfigurationContext configCtx, Registry
serviceRegistry) {
+    public ModuleRegistry(BundleContext context, ConfigurationContext configCtx,
+                          Registry serviceRegistry) {
         super(context, configCtx);
         this.serviceRegistry = serviceRegistry;
     }
@@ -59,58 +63,64 @@
 
     }
 
-    public void unRegister(Bundle bundle) throws AxisFault {
+    public void unRegister(Bundle bundle) {
         lock.lock();
         try {
             List<Long> stopBundleList = new ArrayList<Long>();
-            AxisModule module = resolvedBundles.get(bundle);
-            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);
+            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);
+                        }
                     }
                 }
-                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);
+                            }
+                        }
+                    }
                 }
-            }
-            if (module != null) {
-                resolvedBundles.remove(bundle);
-                axisConfig
-                        .removeModule(module.getName(), module.getVersion());
-                System.out.println("[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(bundle);
+                        serviceRegistry.unRegister(stopBundle);
                         stopBundle.stop();
                     } catch (BundleException e) {
-                        String msg = "Error while stoping the bundle";
-                        //TODO; TBD; error msg.
+                        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);
+
                     }
                 }
             }
@@ -119,11 +129,27 @@
         }
     }
 
-    private void addModules(Bundle bundle) throws AxisFault {
+    /**
+     * When the bundle is activated, this method will look for xml files that ends with "module.xml".
+     * Thus, a given bundle can have n number of Axis2 modules with differen names suffixed
with module.xml.
+     * Ex: rampart_module.xml; rahas_module.xml addressingmodule.xml
+     * <p/>
+     * <p/>
+     * If there are n number of *module.xml and out of which failed modules will be ignored
and and all the
+     * successful *module.xml files will use to crate the proper AxisModule. It is utmost
important that
+     * that if n number of *module.xml files are present, module should be give a proper
name.
+     *
+     * @param bundle started bundle
+     */
+    private void addModules(Bundle bundle) {
         if (!resolvedBundles.containsKey(bundle)) {
-            try {
-                Enumeration enumeration = bundle.findEntries("META-INF", "module.xml", false);
-                while (enumeration != null && enumeration.hasMoreElements()) {
+            Enumeration enumeration = bundle.findEntries("META-INF", "*module.xml", false);
+            List<AxisModule> moduleList = null;
+            if (enumeration != null) {
+                moduleList = new ArrayList<AxisModule>();
+            }
+            while (enumeration != null && enumeration.hasMoreElements()) {
+                try {
                     URL url = (URL) enumeration.nextElement();
                     AxisModule axismodule = new AxisModule();
                     ClassLoader loader =
@@ -133,7 +159,7 @@
                             new ModuleBuilder(url.openStream(), axismodule,
                                               configCtx.getAxisConfiguration());
                     Dictionary headers = bundle.getHeaders();
-                    String bundleSymbolicName = (String)headers.get("Bundle-SymbolicName");
+                    String bundleSymbolicName = (String) headers.get("Bundle-SymbolicName");
                     if (bundleSymbolicName != null && bundleSymbolicName.length()
!= 0) {
                         axismodule.setName(bundleSymbolicName);
                     }
@@ -141,7 +167,6 @@
                     builder.populateModule();
                     axismodule.setParent(configCtx.getAxisConfiguration());
                     //                axismodule.setFileName(new URL(bundle.getLocation()));
-                    //TODO this logic needed to be revised. remove sout
                     AxisModule module =
                             configCtx.getAxisConfiguration().getModule(axismodule.getName());
                     if (module == null) {
@@ -151,18 +176,22 @@
                         if (moduleObj != null) {
                             moduleObj.init(configCtx, axismodule);
                         }
-                        resolvedBundles.put(bundle, axismodule);
-                        System.out.println("[Axis2/OSGi] Starting any modules in Bundle -
" +
-                                           bundle.getSymbolicName());
+                        moduleList.add(axismodule);
+                        log.info("[Axis2/OSGi] Starting any modules in Bundle - " +
+                                 bundle.getSymbolicName());
                     } else {
-                        System.out.println("[ModuleRegistry] Module : " + axismodule.getName()
+
-                                           " is already available.");
+                        log.info("[ModuleRegistry] Module : " + axismodule.getName() +
+                                 " is already available.");
                     }
+                } catch (IOException e) {
+                    String msg = "Error while reading module.xml";
+                    log.error(msg, e);
                 }
-            } catch (IOException e) {
-                String msg = "Error while reading module.xml";
-                throw new AxisFault(msg, e);
             }
+            if (moduleList != null && moduleList.size() > 0) {
+                resolvedBundles.put(bundle, moduleList);
+            }
+
         }
 
     }

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=675229&r1=675228&r2=675229&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
Wed Jul  9 08:31:57 2008
@@ -22,6 +22,8 @@
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.AxisServiceGroup;
 import static org.apache.axis2.osgi.deployment.OSGiAxis2Constants.*;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 
@@ -34,6 +36,8 @@
  */
 public class ServiceRegistry extends AbstractRegistry<AxisServiceGroup> {
 
+    private static Log log = LogFactory.getLog(ServiceRegistry.class);
+
     public ServiceRegistry(BundleContext context, ConfigurationContext configCtx) {
         super(context, configCtx);
     }
@@ -47,93 +51,124 @@
         }
     }
 
-    private void addServices(Bundle bundle) throws AxisFault {
-        try {
+    /**
+     * When a bundle is started this method will look for xml files that suffix with "services.xml".
+     * Thus, a given bundle can have n number of *services.xml.
+     * Ex: my1services.xml and my2_services.xml.
+     * <p/>
+     * Due to security consideration, if one *services.xml fail, all the services will treated
as fail.
+     *
+     * @param bundle registered bundle
+     */
+    private void addServices(Bundle bundle) {
+        if (!resolvedBundles.containsKey(bundle)) {
             Enumeration enumeration = bundle.findEntries("META-INF", "services.xml", false);
-            while (enumeration != null && enumeration.hasMoreElements()) {
-                URL url = (URL) enumeration.nextElement();
-                AxisServiceGroup serviceGroup =
-                        new AxisServiceGroup(configCtx.getAxisConfiguration());
-                serviceGroup.addParameter("last.updated", bundle.getLastModified());
-                ClassLoader loader =
-                        new BundleClassLoader(bundle, Registry.class.getClassLoader());
-                serviceGroup.setServiceGroupClassLoader(loader);
-                InputStream inputStream = url.openStream();
-                DescriptionBuilder builder = new DescriptionBuilder(inputStream, configCtx);
-                OMElement rootElement = builder.buildOM();
-                String elementName = rootElement.getLocalName();
-                Dictionary headers = bundle.getHeaders();
-                String bundleSymbolicName = (String) headers.get("Bundle-SymbolicName");
-                serviceGroup.setServiceGroupName(bundleSymbolicName);
-                HashMap wsdlServicesMap = new HashMap();
-                if (DeploymentConstants.TAG_SERVICE.equals(elementName)) {
-                    AxisService axisService = new AxisService(bundleSymbolicName);
-                    axisService.setParent(serviceGroup);
-                    axisService.setClassLoader(loader);
-                    ServiceBuilder serviceBuilder = new OSGiServiceBuilder(configCtx, axisService);
-                    serviceBuilder.setWsdlServiceMap(wsdlServicesMap);
-                    AxisService service = serviceBuilder.populateService(rootElement);
-                    ArrayList serviceList = new ArrayList();
-                    serviceList.add(service);
-                    DeploymentEngine.addServiceGroup(serviceGroup,
-                                                     serviceList,
-                                                     null,
-                                                     null,
-                                                     configCtx.getAxisConfiguration());
-                    //TODO: use OSGi log service from compendum.
-                    System.out.println("[Axis2/OSGi] Deployed axis2 service:" + service.getName()
+
-                                       " in Bundle: " +
-                                       bundle.getSymbolicName());
-                } else if (DeploymentConstants.TAG_SERVICE_GROUP.equals(elementName)) {
-                    ServiceGroupBuilder groupBuilder =
-                            new OSGiServiceGroupBuilder(rootElement, wsdlServicesMap,
-                                                        configCtx);
-                    ArrayList serviceList = groupBuilder.populateServiceGroup(serviceGroup);
-                    DeploymentEngine.addServiceGroup(serviceGroup,
-                                                     serviceList,
-                                                     null,
-                                                     null,
-                                                     configCtx.getAxisConfiguration());
-                    System.out.println("[Axis2/OSGi] Deployed axis2 service group:" +
-                                       serviceGroup.getServiceGroupName() + " in Bundle:
" +
-                                       bundle.getSymbolicName());
-                }
-                //bundle Id keeps the association between bundle and axisService group for
later use
-                serviceGroup.addParameter(OSGi_BUNDLE_ID, bundle.getBundleId());
-                resolvedBundles.put(bundle, serviceGroup);
-                //marked as resolved.
-                if (unreslovedBundles.contains(bundle)) {
-                    unreslovedBundles.remove(bundle);
-                }
+            int i = 0;
+            List<AxisServiceGroup> axisServiceGroupList = null;
+            if (enumeration != null) {
+                axisServiceGroupList = new ArrayList<AxisServiceGroup>();
             }
-        } catch (Throwable e) {
-            //TODO: TBD log
-            String msg = "Error while reading from the bundle";
-            if (e instanceof DeploymentException) {
-                String message = e.getMessage();
-                if (message != null && message.length() != 0) {
-                    if (message.indexOf(MODULE_NOT_FOUND_ERROR) > -1) {
-                        if (!unreslovedBundles.contains(bundle)) {
-                            unreslovedBundles.add(bundle);
+            while (enumeration != null && enumeration.hasMoreElements()) {
+                try {
+                    URL url = (URL) enumeration.nextElement();
+                    AxisServiceGroup serviceGroup =
+                            new AxisServiceGroup(configCtx.getAxisConfiguration());
+                    serviceGroup.addParameter("last.updated", bundle.getLastModified());
+                    ClassLoader loader =
+                            new BundleClassLoader(bundle, Registry.class.getClassLoader());
+                    serviceGroup.setServiceGroupClassLoader(loader);
+                    InputStream inputStream = url.openStream();
+                    DescriptionBuilder builder = new DescriptionBuilder(inputStream, configCtx);
+                    OMElement rootElement = builder.buildOM();
+                    String elementName = rootElement.getLocalName();
+                    Dictionary headers = bundle.getHeaders();
+                    String bundleSymbolicName = (String) headers.get("Bundle-SymbolicName");
+                    bundleSymbolicName = bundleSymbolicName + "_" + i;
+                    serviceGroup.setServiceGroupName(bundleSymbolicName);
+                    HashMap wsdlServicesMap = new HashMap();
+                    if (DeploymentConstants.TAG_SERVICE.equals(elementName)) {
+                        AxisService axisService = new AxisService(bundleSymbolicName);
+                        axisService.setParent(serviceGroup);
+                        axisService.setClassLoader(loader);
+                        ServiceBuilder serviceBuilder =
+                                new OSGiServiceBuilder(configCtx, axisService);
+                        serviceBuilder.setWsdlServiceMap(wsdlServicesMap);
+                        AxisService service = serviceBuilder.populateService(rootElement);
+                        ArrayList serviceList = new ArrayList();
+                        serviceList.add(service);
+                        DeploymentEngine.addServiceGroup(serviceGroup,
+                                                         serviceList,
+                                                         null,
+                                                         null,
+                                                         configCtx.getAxisConfiguration());
+                        log.info("[Axis2/OSGi] Deployed axis2 service:" + service.getName()
+
+                                 " in Bundle: " +
+                                 bundle.getSymbolicName());
+                    } else if (DeploymentConstants.TAG_SERVICE_GROUP.equals(elementName))
{
+                        ServiceGroupBuilder groupBuilder =
+                                new OSGiServiceGroupBuilder(rootElement, wsdlServicesMap,
+                                                            configCtx);
+                        ArrayList serviceList = groupBuilder.populateServiceGroup(serviceGroup);
+                        DeploymentEngine.addServiceGroup(serviceGroup,
+                                                         serviceList,
+                                                         null,
+                                                         null,
+                                                         configCtx.getAxisConfiguration());
+                        log.info("[Axis2/OSGi] Deployed axis2 service group:" +
+                                 serviceGroup.getServiceGroupName() + " in Bundle: " +
+                                 bundle.getSymbolicName());
+                    }
+                    //bundle Id keeps the association between bundle and axisService group
for later use
+                    serviceGroup.addParameter(OSGi_BUNDLE_ID, bundle.getBundleId());
+                    axisServiceGroupList.add(serviceGroup);
+                    //marked as resolved.
+                    if (unreslovedBundles.contains(bundle)) {
+                        unreslovedBundles.remove(bundle);
+                    }
+                    i++;
+                } catch (Throwable e) {
+                    String msg = "Error while reading from the bundle";
+                    if (e instanceof DeploymentException) {
+                        String message = e.getMessage();
+                        if (message != null && message.length() != 0) {
+                            if (message.indexOf(MODULE_NOT_FOUND_ERROR) > -1) {
+                                if (!unreslovedBundles.contains(bundle)) {
+                                    log.info("A service being found with unmeant module "
+
+                                             "dependency. Hence, moved it to UNRESOLVED state.");
+                                    unreslovedBundles.add(bundle);
+                                }
+                            } else {
+                                log.error(msg, e);
+                                break;
+                            }
+                        } else {
+                            log.error(msg, e);
+                            break;
                         }
                     } else {
-                        throw new AxisFault(msg, e);
+                        log.error(msg, e);
+                        break;
                     }
-                } else {
-                    throw new AxisFault(msg, e);
                 }
-            } else {
-                throw new AxisFault(msg, e);
+            }
+            if (axisServiceGroupList != null && axisServiceGroupList.size() >
0) {
+                resolvedBundles.put(bundle, axisServiceGroupList);
             }
         }
+
     }
 
     public void unRegister(Bundle bundle) throws AxisFault {
         lock.lock();
         try {
-            AxisServiceGroup axisServiceGroup = resolvedBundles.get(bundle);
-            if (axisServiceGroup != null) {
-                resolvedBundles.remove(bundle);
+            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();
@@ -147,11 +182,9 @@
                                        bundle.getSymbolicName());
                 } catch (AxisFault e) {
                     String msg = "Error while removing the service group";
-                    throw new AxisFault(msg, e);
+                    log.error(msg, e);
                 }
-            }
-            if (unreslovedBundles.contains(bundle)) {
-                unreslovedBundles.remove(bundle);
+
             }
         } finally {
             lock.unlock();



Mime
View raw message