Author: ffang
Date: Sun Feb  8 13:13:36 2009
New Revision: 742088

URL: http://svn.apache.org/viewvc?rev=742088&view=rev
Log:
[SMX4NMR-17]totally implement DeploymentServiceMBean

Modified:
    
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminCommandsService.java
    
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminService.java
    
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DeploymentService.java

Modified: 
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminCommandsService.java
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminCommandsService.java?rev=742088&r1=742087&r2=742088&view=diff
==============================================================================
--- 
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminCommandsService.java
 (original)
+++ 
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminCommandsService.java
 Sun Feb  8 13:13:36 2009
@@ -40,8 +40,6 @@
 import org.osgi.framework.ServiceReference;
 import org.springframework.osgi.context.BundleContextAware;
 
-import com.sun.org.apache.bcel.internal.generic.GETSTATIC;
-
 public class AdminCommandsService implements AdminCommandsServiceMBean, 
BundleContextAware {
 
        
@@ -442,7 +440,7 @@
         if (null != serviceAssemblyName && serviceAssemblyName.length() > 0) {
             result = new String[] {serviceAssemblyName };
         } else if (null != componentName && componentName.length() > 0) {
-            result = getDeployedServiceAssembliesForComponent(componentName);
+            result = 
getAdminService().getDeployedServiceAssembliesForComponent(componentName);
         } else {
                ServiceReference[] serviceRefs = 
getAdminService().getSAServiceReferences(null);
                result = new String[serviceRefs.length];
@@ -524,30 +522,5 @@
                return adminService;
        }
        
-       /**
-     * Returns a list of Service Assemblies that contain SUs for the given 
component.
-     * 
-     * @param componentName name of the component.
-     * @return list of Service Assembly names.
-     */
-    public String[] getDeployedServiceAssembliesForComponent(String 
componentName) {
-        String[] result = null;
-        // iterate through the service assembiliessalc
-        Set<String> tmpList = new HashSet<String>();
-        ServiceReference[] serviceRefs = 
getAdminService().getSAServiceReferences(null);
-        for (ServiceReference ref : serviceRefs) {
-               ServiceAssembly sa = (ServiceAssembly) 
getBundleContext().getService(ref);
-            ServiceUnit[] sus = sa.getServiceUnits();
-            if (sus != null) {
-                for (int i = 0; i < sus.length; i++) {
-                    if (sus[i].getComponent().getName().equals(componentName)) 
{
-                        tmpList.add(sa.getName());
-                    }
-                }
-            }
-        }
-        result = new String[tmpList.size()];
-        tmpList.toArray(result);
-        return result;
-    }
+       
 }

Modified: 
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminService.java
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminService.java?rev=742088&r1=742087&r2=742088&view=diff
==============================================================================
--- 
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminService.java
 (original)
+++ 
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminService.java
 Sun Feb  8 13:13:36 2009
@@ -16,9 +16,14 @@
  */
 package org.apache.servicemix.jbi.management;
 
+import java.util.HashSet;
+import java.util.Set;
+
 import javax.jbi.management.AdminServiceMBean;
 import javax.management.ObjectName;
 
+import org.apache.servicemix.jbi.deployer.ServiceAssembly;
+import org.apache.servicemix.jbi.deployer.ServiceUnit;
 import org.apache.servicemix.jbi.deployer.handler.JBIDeploymentListener;
 import org.apache.servicemix.jbi.deployer.impl.Deployer;
 import org.osgi.framework.BundleContext;
@@ -148,4 +153,100 @@
                 null);
        return (Deployer) 
((JBIDeploymentListener)getBundleContext().getService(ref)).getDeployer();
        }
+    
+    /**
+     * Returns a list of Service Assemblies that contain SUs for the given 
component.
+     * 
+     * @param componentName name of the component.
+     * @return list of Service Assembly names.
+     */
+    public String[] getDeployedServiceAssembliesForComponent(String 
componentName) {
+        String[] result = null;
+        // iterate through the service assembiliessalc
+        Set<String> tmpList = new HashSet<String>();
+        ServiceReference[] serviceRefs = getSAServiceReferences(null);
+        for (ServiceReference ref : serviceRefs) {
+               ServiceAssembly sa = (ServiceAssembly) 
getBundleContext().getService(ref);
+            ServiceUnit[] sus = sa.getServiceUnits();
+            if (sus != null) {
+                for (int i = 0; i < sus.length; i++) {
+                    if (sus[i].getComponent().getName().equals(componentName)) 
{
+                        tmpList.add(sa.getName());
+                    }
+                }
+            }
+        }
+        result = new String[tmpList.size()];
+        tmpList.toArray(result);
+        return result;
+    }
+    
+    public String[] getDeployedServiceUnitsForComponent(String componentName) {
+        String[] result = null;
+        // iterate through the service assembiliessalc
+        Set<String> tmpList = new HashSet<String>();
+        ServiceReference[] serviceRefs = getSAServiceReferences(null);
+        for (ServiceReference ref : serviceRefs) {
+               ServiceAssembly sa = (ServiceAssembly) 
getBundleContext().getService(ref);
+            ServiceUnit[] sus = sa.getServiceUnits();
+            if (sus != null) {
+                for (int i = 0; i < sus.length; i++) {
+                    if (sus[i].getComponent().getName().equals(componentName)) 
{
+                        tmpList.add(sus[i].getName());
+                    }
+                }
+            }
+        }
+        result = new String[tmpList.size()];
+        tmpList.toArray(result);
+        return result;
+    }
+    
+    public String[] getComponentsForDeployedServiceAssembly(String saName) {
+        String[] result = null;
+        // iterate through the service assembiliessalc
+        Set<String> tmpList = new HashSet<String>();
+        ServiceReference ref = getSAServiceReference("(" + Deployer.NAME + "=" 
+ saName + ")");
+        if (ref != null) {
+               ServiceAssembly sa = (ServiceAssembly) 
getBundleContext().getService(ref);
+            ServiceUnit[] sus = sa.getServiceUnits();
+            if (sus != null) {
+                for (int i = 0; i < sus.length; i++) {
+                    if (sus[i].getComponent().getName().equals(saName)) {
+                        tmpList.add(sus[i].getComponent().getName());
+                    }
+                }
+            }
+        }
+        result = new String[tmpList.size()];
+        tmpList.toArray(result);
+        return result;
+    }
+    
+    /**
+     * Returns a boolean value indicating whether the SU is currently deployed.
+     * 
+     * @param componentName - name of component.
+     * @param suName - name of the Service Unit.
+     * @return boolean value indicating whether the SU is currently deployed.
+     */
+    public boolean isDeployedServiceUnit(String componentName, String suName) {
+        boolean result = false;
+        ServiceReference[] serviceRefs = getSAServiceReferences(null);
+        for (ServiceReference ref : serviceRefs) {
+               ServiceAssembly sa = (ServiceAssembly) 
getBundleContext().getService(ref);
+            ServiceUnit[] sus = sa.getServiceUnits();
+            if (sus != null) {
+                for (int i = 0; i < sus.length; i++) {
+                    if (sus[i].getComponent().getName().equals(componentName)
+                                    && sus[i].getName().equals(suName)) {
+                        result = true;
+                        break;
+                    }
+                }
+            }
+        }
+        return result;
+    }
+
 }

Modified: 
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DeploymentService.java
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DeploymentService.java?rev=742088&r1=742087&r2=742088&view=diff
==============================================================================
--- 
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DeploymentService.java
 (original)
+++ 
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DeploymentService.java
 Sun Feb  8 13:13:36 2009
@@ -18,6 +18,7 @@
 
 import java.io.File;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
 import javax.jbi.JBIException;
@@ -27,6 +28,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.servicemix.jbi.deployer.Component;
+import org.apache.servicemix.jbi.deployer.ServiceAssembly;
 import org.apache.servicemix.jbi.deployer.descriptor.Descriptor;
 import org.apache.servicemix.jbi.deployer.descriptor.ServiceAssemblyDesc;
 import org.apache.servicemix.jbi.deployer.descriptor.ServiceUnitDesc;
@@ -160,31 +162,47 @@
     }
 
     public String[] getDeployedServiceUnitList(String componentName) throws 
Exception {
-        return new String[0]; 
+        return 
getAdminService().getDeployedServiceUnitsForComponent(componentName);
     }
 
     public String[] getDeployedServiceAssemblies() throws Exception {
-        return new String[0];
+       String[] ret = null;
+       Set<String> sas = 
getAdminService().getDeployer().getDeployServiceAssemblies();
+       ret = new String[sas.size()];
+       sas.toArray(ret);
+       return ret;
     }
 
     public String getServiceAssemblyDescriptor(String saName) throws Exception 
{
-        return null;
+        ServiceReference ref = getAdminService().getSAServiceReference("(" + 
Deployer.NAME + "=" + saName + ")");
+        if (ref == null) {
+            throw new JBIException("ServiceAssembly '" + saName + "' not 
found");
+        }
+        ServiceAssembly sa = (ServiceAssembly) 
getAdminService().getBundleContext().getService(ref);
+        return sa.getDescription();
     }
 
     public String[] getDeployedServiceAssembliesForComponent(String 
componentName) throws Exception {
-        return new String[0];
+       return 
getAdminService().getDeployedServiceAssembliesForComponent(componentName);
     }
 
     public String[] getComponentsForDeployedServiceAssembly(String saName) 
throws Exception {
-        return new String[0];
+        return 
getAdminService().getComponentsForDeployedServiceAssembly(saName);
     }
 
     public boolean isDeployedServiceUnit(String componentName, String suName) 
throws Exception {
-        return false;
+        return getAdminService().isDeployedServiceUnit(componentName, suName);
     }
 
     public boolean canDeployToComponent(String componentName) {
-        return false;
+        ServiceReference ref = 
getAdminService().getComponentServiceReference("(" + Deployer.NAME + "=" + 
componentName + ")");
+        if (ref == null) {
+               return false;
+        }
+        ComponentImpl componentImpl = (ComponentImpl) 
getAdminService().getBundleContext().getService(ref);
+        return componentImpl != null 
+               && componentImpl.getCurrentState() == LifeCycleMBean.STARTED 
+                       && componentImpl.getComponent().getServiceUnitManager() 
!= null;
     }
 
     public String start(String serviceAssemblyName) throws Exception {


Reply via email to