incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lin...@apache.org
Subject svn commit: r932216 - in /incubator/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal: Activator.java FileUtils.java SubsystemAdminImpl.java
Date Fri, 09 Apr 2010 02:24:33 GMT
Author: linsun
Date: Fri Apr  9 02:24:33 2010
New Revision: 932216

URL: http://svn.apache.org/viewvc?rev=932216&view=rev
Log:
add logging, update install logic a bit based on the javadoc

Modified:
    incubator/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java
    incubator/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/FileUtils.java
    incubator/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemAdminImpl.java

Modified: incubator/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java?rev=932216&r1=932215&r2=932216&view=diff
==============================================================================
--- incubator/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java
(original)
+++ incubator/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java
Fri Apr  9 02:24:33 2010
@@ -29,6 +29,8 @@ import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceFactory;
 import org.osgi.framework.ServiceRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * The bundle activator for the this bundle.
@@ -36,12 +38,16 @@ import org.osgi.framework.ServiceRegistr
  * and register the SubsystemAdmin service.
  */
 public class Activator implements BundleActivator {
-
+    private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);
+    
     private BundleContext context;
     private List<ServiceRegistration> registrations = new ArrayList<ServiceRegistration>();
     private static SubsystemEventDispatcher eventDispatcher;
 
     public void start(BundleContext context) throws Exception {
+        if (LOGGER.isDebugEnabled()) {
+            LOGGER.debug("subsystem activator starting");
+        }
         this.context = context;
         eventDispatcher = new SubsystemEventDispatcher(context);
         
@@ -66,13 +72,17 @@ public class Activator implements Bundle
     }
 
     public void stop(BundleContext context) throws Exception {
+        if (LOGGER.isDebugEnabled()) {
+            LOGGER.debug("subsystem activator stopping");
+        }
         for (ServiceRegistration r : registrations) {
             try {
                 r.unregister();
             } catch (Exception e) {
-                // Ignore
+                LOGGER.warn("Subsystem Activator shut down", e);
             }
         }
+        eventDispatcher.destroy();
     }
 
 
@@ -82,6 +92,9 @@ public class Activator implements Bundle
         private final Map<SubsystemAdminImpl, Long> references = new HashMap<SubsystemAdminImpl,
Long>();
 
         public synchronized Object getService(Bundle bundle, ServiceRegistration registration)
{
+            if (LOGGER.isDebugEnabled()) {
+                LOGGER.debug("Get SubsystemAdmin service from bundle symbolic name {} version
{}", bundle.getSymbolicName(), bundle.getVersion());
+            }
             BundleContext systemBundleContext = bundle.getBundleContext().getBundle(0).getBundleContext();
             SubsystemAdminImpl admin = admins.get(systemBundleContext);
             long ref = 0;
@@ -96,6 +109,9 @@ public class Activator implements Bundle
         }
 
         public synchronized void ungetService(Bundle bundle, ServiceRegistration registration,
Object service) {
+            if (LOGGER.isDebugEnabled()) {
+                LOGGER.debug("Unget SubsystemAdmin service {} from bundle symbolic name {}
version {}", new Object[] {service, bundle.getSymbolicName(), bundle.getVersion()});
+            }
             SubsystemAdminImpl admin = (SubsystemAdminImpl) service;
             long ref = references.get(admin) - 1;
             if (ref == 0) {

Modified: incubator/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/FileUtils.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/FileUtils.java?rev=932216&r1=932215&r2=932216&view=diff
==============================================================================
--- incubator/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/FileUtils.java
(original)
+++ incubator/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/FileUtils.java
Fri Apr  9 02:24:33 2010
@@ -68,11 +68,10 @@ public class FileUtils {
                         closeQuietly(fos);
                     }
                     zis.closeEntry();
-                    entry = zis.getNextEntry();
                 } else {
                     mkdirs(file);
-                    entry = zis.getNextEntry();
                 }
+                entry = zis.getNextEntry();
             }//while
         } finally {
             closeQuietly(zis, is);

Modified: incubator/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemAdminImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemAdminImpl.java?rev=932216&r1=932215&r2=932216&view=diff
==============================================================================
--- incubator/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemAdminImpl.java
(original)
+++ incubator/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemAdminImpl.java
Fri Apr  9 02:24:33 2010
@@ -38,9 +38,11 @@ import org.osgi.framework.Version;
 import org.osgi.service.composite.CompositeAdmin;
 import org.osgi.service.composite.CompositeBundle;
 import org.osgi.util.tracker.ServiceTracker;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class SubsystemAdminImpl implements SubsystemAdmin {
-
+    private static final Logger LOGGER = LoggerFactory.getLogger(SubsystemAdminImpl.class);
     private static final Version SUBSYSTEM_MANIFEST_VERSION = new Version("1.0");
 
     final Semaphore lock = new Semaphore(1);
@@ -75,12 +77,19 @@ public class SubsystemAdminImpl implemen
 
     public void bundleChanged(BundleEvent event) {
         synchronized (subsystems) {
+            Bundle bundle = event.getBundle();
             if (event.getType() == BundleEvent.UPDATED || event.getType() == BundleEvent.UNINSTALLED)
{
-                subsystems.remove(event.getBundle().getBundleId());
+                if (LOGGER.isDebugEnabled()) {
+                    LOGGER.debug("Removing bundle symbolic name {} version {} from subsystems
map being tracked", bundle.getSymbolicName(), bundle.getVersion());
+                }
+                subsystems.remove(bundle.getBundleId());
             }
             if (event.getType() == BundleEvent.INSTALLED || event.getType() == BundleEvent.UPDATED)
{
-                Subsystem s = isSubsystem(event.getBundle());
+                Subsystem s = isSubsystem(bundle);
                 if (s != null) {
+                    if (LOGGER.isDebugEnabled()) {
+                        LOGGER.debug("Adding bundle symbolic name {} version {} to subsystems
map being tracked", bundle.getSymbolicName(), bundle.getVersion());
+                    }
                     subsystems.put(s.getSubsystemId(), s);
                 }
             }
@@ -93,6 +102,9 @@ public class SubsystemAdminImpl implemen
             for (Bundle bundle : context.getBundles()) {
                 Subsystem s = isSubsystem(bundle);
                 if (s != null) {
+                    if (LOGGER.isDebugEnabled()) {
+                        LOGGER.debug("Adding bundle symbolic name {} version {} to subsystems
map being tracked", bundle.getSymbolicName(), bundle.getVersion());
+                    }
                     subsystems.put(s.getSubsystemId(), s);
                 }
             }
@@ -101,6 +113,7 @@ public class SubsystemAdminImpl implemen
 
     protected Subsystem isSubsystem(Bundle bundle) {
         if (bundle instanceof CompositeBundle) {
+            // it is important not to use bundle.getSymbolicName() here as that would not
contain the directives we need.
             String bsn = (String) bundle.getHeaders().get(Constants.BUNDLE_SYMBOLICNAME);
             Clause[] bsnClauses = Parser.parseHeader(bsn);
             if ("true".equals(bsnClauses[0].getDirective(SubsystemConstants.SUBSYSTEM_DIRECTIVE)))
{
@@ -132,6 +145,18 @@ public class SubsystemAdminImpl implemen
     }
 
     public synchronized Subsystem install(String url, final InputStream is) throws SubsystemException
{
+        if (LOGGER.isDebugEnabled()) {
+            LOGGER.debug("Installing subsystem url {}", url);
+        }
+        // let's check if the subsystem has been installed or not first before proceed installation
+        Subsystem toReturn = getInstalledSubsytem(url);      
+        if (toReturn != null) {
+            if (LOGGER.isDebugEnabled()) {
+                LOGGER.debug("A subsystem containing the same location identifier {} is already
installed", url);
+            }
+            return toReturn;
+        }
+        
         Resource subsystemResource = new ResourceImpl(null, null, SubsystemConstants.RESOURCE_TYPE_SUBSYSTEM,
url) {
             @Override
             public InputStream open() throws IOException {
@@ -151,14 +176,22 @@ public class SubsystemAdminImpl implemen
             success = true;
         } finally {
             if (!success) {
+                if (LOGGER.isDebugEnabled()) {
+                    LOGGER.debug("Installing subsystem url {} is not successful, rollback
now", url);
+                }
                 session.rollback();
             }
         }
-        for (Subsystem ss : getSubsystems().values()) {
-            if (url.equals(ss.getLocation())) {
-                return ss;
+
+        // let's get the one we just installed
+        toReturn = getInstalledSubsytem(url);       
+        if (toReturn != null) {
+            if (LOGGER.isDebugEnabled()) {
+                LOGGER.debug("Installing subsystem url {} is successful", url);
             }
+            return toReturn;
         }
+        
         throw new IllegalStateException();
     }
 
@@ -174,10 +207,12 @@ public class SubsystemAdminImpl implemen
         if (!(ss instanceof SubsystemImpl)) {
             throw new IllegalArgumentException("The given subsystem is not managed by the
SubsystemAdmin instance");
         }
+        if (ss.getState().equals(Subsystem.State.UNINSTALLED)) {
+            return;
+        }
         SubsystemImpl subsystem = (SubsystemImpl) ss;
         try {
             subsystem.composite.uninstall();
-            this.subsystems.remove(subsystem.id);
         } catch (BundleException e) {
             // TODO: Rollback
             throw new SubsystemException("Error while uninstalling the subsystem", e);
@@ -188,11 +223,16 @@ public class SubsystemAdminImpl implemen
         if (!(ss instanceof SubsystemImpl)) {
             throw new IllegalArgumentException("The given subsystem is not managed by the
SubsystemAdmin instance");
         }
+        if (ss.getState().equals(Subsystem.State.UNINSTALLED)) {
+            return;
+        }
         SubsystemImpl subsystem = (SubsystemImpl) ss;
         try {
             subsystem.composite.uninstall();
         } catch (BundleException e) {
-            // Ignore
+            if (LOGGER.isDebugEnabled()) {
+                LOGGER.debug("Uninstalling subsystem scope {} is not successful.  Removing
the subsystem from  subsystems map being tracked", ss.getScope());
+            }
         } finally {
             this.subsystems.remove(subsystem.id);
         }
@@ -203,4 +243,12 @@ public class SubsystemAdminImpl implemen
         return false;
     }
 
+    private Subsystem getInstalledSubsytem(String url) {
+        for (Subsystem ss : getSubsystems().values()) {
+            if (url.equals(ss.getLocation())) {
+                return ss;
+            }
+        }
+        return null;
+    }
 }



Mime
View raw message