incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lin...@apache.org
Subject svn commit: r1040622 - in /incubator/aries/trunk/subsystem/subsystem-core: ./ src/main/java/org/apache/aries/subsystem/core/internal/
Date Tue, 30 Nov 2010 16:34:11 GMT
Author: linsun
Date: Tue Nov 30 16:34:11 2010
New Revision: 1040622

URL: http://svn.apache.org/viewvc?rev=1040622&view=rev
Log:
revert r1021324 in subsystem-core project since Graham told me he doesn't need the Future
stuff anyway

Removed:
    incubator/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ImmediateFuture.java
    incubator/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemFutureTask.java
Modified:
    incubator/aries/trunk/subsystem/subsystem-core/   (props changed)
    incubator/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemAdminImpl.java
    incubator/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceProcessor.java

Propchange: incubator/aries/trunk/subsystem/subsystem-core/
            ('svn:ignore' removed)

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=1040622&r1=1040621&r2=1040622&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
Tue Nov 30 16:34:11 2010
@@ -21,15 +21,15 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.concurrent.Executor;
-import java.util.concurrent.Future;
 
 import org.apache.aries.subsystem.Subsystem;
 import org.apache.aries.subsystem.SubsystemAdmin;
 import org.apache.aries.subsystem.SubsystemConstants;
 import org.apache.aries.subsystem.SubsystemEvent;
 import org.apache.aries.subsystem.SubsystemException;
+import org.apache.aries.subsystem.SubsystemListener;
 import org.apache.aries.subsystem.spi.Resource;
+import org.apache.aries.subsystem.spi.ResourceResolver;
 import org.apache.felix.utils.manifest.Clause;
 import org.apache.felix.utils.manifest.Parser;
 import org.osgi.framework.Bundle;
@@ -38,6 +38,7 @@ import org.osgi.framework.BundleEvent;
 import org.osgi.framework.Constants;
 import org.osgi.framework.SynchronousBundleListener;
 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;
@@ -49,16 +50,20 @@ public class SubsystemAdminImpl implemen
 
     final BundleContext context;
     final Map<Long, Subsystem> subsystems = new HashMap<Long, Subsystem>();
+    final ServiceTracker compositeAdminTracker;
+    final ServiceTracker resourceResolverTracker;
     final SubsystemEventDispatcher eventDispatcher;
-    final ServiceTracker executorTracker;
-    final HashMap<String, SubsystemFutureTask> installInProgress = new HashMap<String,
SubsystemFutureTask>();
-    final HashMap<String, SubsystemFutureTask> updateInProgress = new HashMap<String,
SubsystemFutureTask>();
+    final ServiceTracker listenersTracker;
     
     public SubsystemAdminImpl(BundleContext context, SubsystemEventDispatcher eventDispatcher)
{
         this.context = context;
         this.eventDispatcher = eventDispatcher;
-        this.executorTracker = new ServiceTracker(context, Executor.class.getName(), null);
-        this.executorTracker.open();
+        this.compositeAdminTracker = new ServiceTracker(context, CompositeAdmin.class.getName(),
null);
+        this.compositeAdminTracker.open();
+        this.resourceResolverTracker = new ServiceTracker(context, ResourceResolver.class.getName(),
null);
+        this.resourceResolverTracker.open();
+        this.listenersTracker = new ServiceTracker(context, SubsystemListener.class.getName(),
null);
+        this.listenersTracker.open();
         // Track subsystems
         synchronized (subsystems) {
             this.context.addBundleListener(new SynchronousBundleListener() {
@@ -71,62 +76,27 @@ public class SubsystemAdminImpl implemen
     }
 
     public void dispose() {
-        executorTracker.close();
+        compositeAdminTracker.close();
+        resourceResolverTracker.close();
+        listenersTracker.close();
     }
 
     public void bundleChanged(BundleEvent event) {
         synchronized (subsystems) {
             Bundle bundle = event.getBundle();
-            if (event.getType() == BundleEvent.UNINSTALLED) {
+            if (event.getType() == BundleEvent.UPDATED || event.getType() == BundleEvent.UNINSTALLED)
{
                 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.UPDATED) {
-                Subsystem s = isSubsystem(bundle);
-
-                // If this is a subsystem we have in progress, then set the result on the
SubsystemFutureTask
-                if (updateInProgress.containsKey(s.getLocation())) {
-                    SubsystemFutureTask task = updateInProgress.remove(s.getLocation());
-                    task.set(s);
-                    if (LOGGER.isDebugEnabled()) {
-                        LOGGER.debug(
-                                "Update of subsystem url {} is successful",
-                                s.getLocation());
-                    }
-
-                    // emit the subsystem event
-                    eventDispatcher.subsystemEvent(new SubsystemEvent(
-                            SubsystemEvent.Type.UPDATED, System.currentTimeMillis(), s));
-
-                }
-
-            }
-            if (event.getType() == BundleEvent.INSTALLED) {
+            if (event.getType() == BundleEvent.INSTALLED || event.getType() == BundleEvent.UPDATED)
{
                 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);
-                    
-                    // If this is a subsystem we have in progress, then set the result on
the SubsystemFutureTask
-                    if (installInProgress.containsKey(s.getLocation())) {
-                        SubsystemFutureTask task = installInProgress.remove(s
-                                .getLocation());
-                        task.set(s);
-                        if (LOGGER.isDebugEnabled()) {
-                            LOGGER.debug(
-                                    "Install of subsystem url {} is successful",
-                                    s.getLocation());
-                        }
-
-                        // emit the subsystem event
-                        eventDispatcher.subsystemEvent(new SubsystemEvent(
-                                SubsystemEvent.Type.INSTALLED, System.currentTimeMillis(),
s));
-
-                    }
                 }
             }
             if (event.getType() == BundleEvent.RESOLVED) {
@@ -194,182 +164,117 @@ public class SubsystemAdminImpl implemen
         }
     }
 
-    public Future<Subsystem> install(String url) {
+    public Subsystem install(String url) {
         return install(url, null);
     }
 
-    public synchronized Future<Subsystem> install(final String url, final InputStream
is) {
+    public synchronized Subsystem install(String url, final InputStream is) throws SubsystemException
{
         if (LOGGER.isDebugEnabled()) {
             LOGGER.debug("Installing subsystem url {}", url);
         }
-        
-        // check if the subsystem install is already in progress
-        Future<Subsystem> futureToReturn = installInProgress.get(url);
-        if (futureToReturn != null) {
-            if (LOGGER.isDebugEnabled()) {
-                LOGGER.debug("A Future<Subsystem> containing the same location identifier
{} is already in installing.", url);
-            }       
-            return futureToReturn;
-        }
-
-        // check if the subsystem has already been installed before proceeding with the installation
+        // 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 new ImmediateFuture<Subsystem>(toReturn);
+            return toReturn;
         }
         
-        // Create a new Future to handle the installation of the Subsystem
-        SubsystemFutureTask installTask = new SubsystemFutureTask(new Runnable() {
-            public void run() {
-                Resource subsystemResource = new ResourceImpl(null, null,
-                        SubsystemConstants.RESOURCE_TYPE_SUBSYSTEM, url,
-                        Collections.<String, String> emptyMap()) {
-                    @Override
-                    public InputStream open() throws IOException {
-                        if (is != null) {
-                            return is;
-                        }
-                        return super.open();
-                    }
-                };
-                SubsystemResourceProcessor processor = new SubsystemResourceProcessor();
-                SubsystemResourceProcessor.SubsystemSession session = processor
-                        .createSession(context);
-                boolean success = false;
-                try {
-                    session.process(subsystemResource);
-                    session.prepare();
-                    session.commit();
-                    success = true;
-                    
-                } finally {
-                    if (!success) {
-                        if (LOGGER.isDebugEnabled()) {
-                            LOGGER.debug(
-                                    "Installing subsystem url {} is not successful, rollback
now",
-                                    url);
-                        }
-                        session.rollback();
-                    }
-                }                
+        Resource subsystemResource = new ResourceImpl(null, null, SubsystemConstants.RESOURCE_TYPE_SUBSYSTEM,
url, Collections.<String, String>emptyMap()) {
+            @Override
+            public InputStream open() throws IOException {
+                if (is != null) {
+                    return is;
+                }
+                return super.open();
             }
-        }, context, url, is);
-        
-        // Kick off the future and return it
-        installInProgress.put(url, installTask);
-
-        execute(installTask);
+        };
+        SubsystemResourceProcessor processor = new SubsystemResourceProcessor();
+        SubsystemResourceProcessor.SubsystemSession session = processor.createSession(context);
+        boolean success = false;
+        try {
+            session.process(subsystemResource);
+            session.prepare();
+            session.commit();
+            success = true;
+        } finally {
+            if (!success) {
+                if (LOGGER.isDebugEnabled()) {
+                    LOGGER.debug("Installing subsystem url {} is not successful, rollback
now", url);
+                }
+                session.rollback();
+            }
+        }
 
-        return installTask;
-    }
+        // let's get the one we just installed
+        if (success) {
+            toReturn = getInstalledSubsytem(url);       
+            if (toReturn != null) {
+                if (LOGGER.isDebugEnabled()) {
+                    LOGGER.debug("Installing subsystem url {} is successful", url);
+                }
+                
+                // emit the subsystem event
+                eventDispatcher.subsystemEvent(new SubsystemEvent(SubsystemEvent.Type.INSTALLED,
System.currentTimeMillis(), toReturn));
 
-    /**
-     * Execute the Future either using an Executor from the service registry or
-     * a new Thread.
-     * 
-     * @param installTask
-     */
-    private void execute(SubsystemFutureTask installTask) {
-        Executor ex = (Executor) executorTracker.getService();
-        if (ex != null) {
-            if (LOGGER.isDebugEnabled()) {
-                LOGGER.debug("Using Executor to execute Subsystem Install");
+                return toReturn;
             }
-            ex.execute(installTask);
-        } else {
-            // Create own thread if no executor is available
-            Thread thread = new Thread(installTask);
-            thread.start();
         }
+        
+        throw new IllegalStateException();
     }
 
-    public Future<Subsystem> update(Subsystem subsystem) throws SubsystemException
{
-        return update(subsystem, null);
+    public void update(Subsystem subsystem) throws SubsystemException {
+        update(subsystem, null);
     }
 
-    public Future<Subsystem> update(final Subsystem subsystem, final InputStream is)
throws SubsystemException {
+    public void update(final Subsystem subsystem, final InputStream is) throws SubsystemException
{
         if (subsystem.getState().equals(Subsystem.State.UNINSTALLED)) {
             throw new IllegalStateException("Unable to update subsystem as subsystem is already
uninstalled");
         }
         
-        // check if the subsystem install is already in progress
-        Future<Subsystem> futureToReturn = updateInProgress.get(subsystem.getLocation());
-        if (futureToReturn != null) {
-            if (LOGGER.isDebugEnabled()) {
-                LOGGER.debug("A Future<Subsystem> containing the same location identifier
{} is already updating.", subsystem.getLocation());
-            }       
-            return futureToReturn;
-        }        
-
-        // Create a new Future to handle the update of the Subsystem
-        SubsystemFutureTask updateTask = new SubsystemFutureTask(
-                new Runnable() {
-                    public void run() {
-                        if (subsystem.getState().equals(Subsystem.State.ACTIVE)
-                                || subsystem.getState().equals(
-                                        Subsystem.State.STARTING)
-                                || subsystem.getState().equals(
-                                        Subsystem.State.STOPPING)) {
-                            subsystem.stop();
-                        }
-                        Resource subsystemResource = new ResourceImpl(
-                                subsystem.getSymbolicName(),
-                                subsystem.getVersion(),
-                                SubsystemConstants.RESOURCE_TYPE_SUBSYSTEM,
-                                subsystem.getLocation(),
-                                Collections.<String, String> emptyMap()) {
-                            @Override
-                            public InputStream open() throws IOException {
-                                if (is != null) {
-                                    return is;
-                                }
-                                // subsystem-updatelocation specified the
-                                // manifest has higher priority than subsystem
-                                // original location
-                                String subsystemLoc = subsystem
-                                        .getHeaders()
-                                        .get(SubsystemConstants.SUBSYSTEM_UPDATELOCATION);
-                                if (subsystemLoc != null
-                                        && subsystemLoc.length() > 0) {
-                                    // we have a subsystem location lets us use it
-                                    return new URL(subsystemLoc).openStream();
-                                }
-                                return super.open();
-                            }
-                        };
-                        SubsystemResourceProcessor processor = new SubsystemResourceProcessor();
-                        SubsystemResourceProcessor.SubsystemSession session = processor
-                                .createSession(context);
-                        boolean success = false;
-                        try {
-                            session.process(subsystemResource);
-                            session.prepare();
-                            session.commit();
-                            success = true;
-                            if (LOGGER.isDebugEnabled()) {
-                                LOGGER.debug(
-                                        "Updating subsystem {} is successful",
-                                        subsystem.getSymbolicName());
-                            }
-
-                        } finally {
-                            if (!success) {
-                                session.rollback();
-                            }
-                        }
-                    }
-                }, context, subsystem.getLocation(), is);
-
-        // Kick off the future and return it
-        updateInProgress.put(subsystem.getLocation(), updateTask);
-
-        execute(updateTask);
-
-        return updateTask;
+        if (subsystem.getState().equals(Subsystem.State.ACTIVE) 
+                || subsystem.getState().equals(Subsystem.State.STARTING) 
+                || subsystem.getState().equals(Subsystem.State.STOPPING)) {
+            subsystem.stop();
+        }
         
+        Resource subsystemResource = new ResourceImpl(subsystem.getSymbolicName(), subsystem.getVersion(),
SubsystemConstants.RESOURCE_TYPE_SUBSYSTEM, subsystem.getLocation(), Collections.<String,
String>emptyMap()) {
+            @Override
+            public InputStream open() throws IOException {
+                if (is != null) {
+                    return is;
+                }
+                // subsystem-updatelocation specified the manifest has higher priority than
subsystem original location
+                String subsystemLoc = subsystem.getHeaders().get(SubsystemConstants.SUBSYSTEM_UPDATELOCATION);
+                if (subsystemLoc != null && subsystemLoc.length() > 0) {
+                    // we have a subsystem location let us use it
+                    return new URL(subsystemLoc).openStream();
+                }
+                return super.open();
+            }
+        };
+        SubsystemResourceProcessor processor = new SubsystemResourceProcessor();
+        SubsystemResourceProcessor.SubsystemSession session = processor.createSession(context);
+        boolean success = false;
+        try {
+            session.process(subsystemResource);
+            session.prepare();
+            session.commit();
+            success = true;
+            if (LOGGER.isDebugEnabled()) {
+                LOGGER.debug("Updating subsystem {} is successful", subsystem.getSymbolicName());
+            }
+ 
+            // emit the subsystem event
+            eventDispatcher.subsystemEvent(new SubsystemEvent(SubsystemEvent.Type.UPDATED,
System.currentTimeMillis(), subsystem));
+ 
+        } finally {
+            if (!success) {
+                session.rollback();
+            }
+        }
     }
 
     public void uninstall(Subsystem subsystem) {
@@ -400,6 +305,11 @@ public class SubsystemAdminImpl implemen
         }
     }
 
+    public boolean cancel() {
+        // TODO
+        return false;
+    }
+
     private Subsystem getInstalledSubsytem(String url) {
         for (Subsystem ss : getSubsystems()) {
             if (url.equals(ss.getLocation())) {
@@ -408,5 +318,4 @@ public class SubsystemAdminImpl implemen
         }
         return null;
     }
-        
 }

Modified: incubator/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceProcessor.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceProcessor.java?rev=1040622&r1=1040621&r2=1040622&view=diff
==============================================================================
--- incubator/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceProcessor.java
(original)
+++ incubator/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceProcessor.java
Tue Nov 30 16:34:11 2010
@@ -50,8 +50,6 @@ import org.osgi.service.composite.Compos
 import org.osgi.service.composite.CompositeBundle;
 import org.osgi.service.composite.CompositeConstants;
 import org.osgi.util.tracker.ServiceTracker;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import static org.apache.aries.subsystem.core.internal.FileUtils.closeQuietly;
 
@@ -61,9 +59,6 @@ import static org.apache.aries.subsystem
 
 public class SubsystemResourceProcessor implements ResourceProcessor {
 
-    private static final Logger LOGGER = LoggerFactory
-    .getLogger(SubsystemResourceProcessor.class);
-
     private static final Version SUBSYSTEM_MANIFEST_VERSION = new Version("1.0");
 
     public SubsystemSession createSession(BundleContext context) {
@@ -99,12 +94,6 @@ public class SubsystemResourceProcessor 
          */
         private void process(Resource res, Manifest manifest) {
 
-            if (LOGGER.isDebugEnabled()) {
-                LOGGER.debug(
-                        "Installing subsystem resource {}",
-                        res.getLocation());
-            }            
-            
             try {
 
                 CompositeAdmin admin = getService(CompositeAdmin.class);
@@ -141,13 +130,6 @@ public class SubsystemResourceProcessor 
                 List<Resource> content = new ArrayList<Resource>();
                 String contentHeader = manifest.getMainAttributes().getValue(
                         SUBSYSTEM_CONTENT);
-                
-                if (LOGGER.isDebugEnabled()) {
-                    LOGGER.debug(
-                            "Installing subsystem content {}",
-                            contentHeader);
-                }                         
-                
                 Clause[] contentClauses = Parser.parseHeader(contentHeader);
                 for (Clause c : contentClauses) {
                     Resource r = resolver.find(c.toString());



Mime
View raw message