felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r409159 - in /incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework: Felix.java PackageAdminImpl.java
Date Wed, 24 May 2006 13:46:07 GMT
Author: rickhall
Date: Wed May 24 06:46:06 2006
New Revision: 409159

URL: http://svn.apache.org/viewvc?rev=409159&view=rev
Log:
Implemented the new PackageAdmin.resolveBundles() method (FELIX-35).

Modified:
    incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
    incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/PackageAdminImpl.java

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java?rev=409159&r1=409158&r2=409159&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
(original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
Wed May 24 06:46:06 2006
@@ -2737,10 +2737,55 @@
         return null;
     }
 
+    protected boolean resolveBundles(Bundle[] targets)
+    {
+        if (System.getSecurityManager() != null)
+        {
+// TODO: FW SECURITY - Perform proper security check.
+            AccessController.checkPermission(m_adminPerm);
+        }
+
+        // Acquire locks for all bundles to be resolved.
+        BundleImpl[] bundles = acquireBundleResolveLocks(targets);
+
+        try
+        {
+            boolean result = true;
+
+            // If there are targets, then resolve each one.
+            if (bundles != null)
+            {
+                for (int i = 0; i < bundles.length; i++)
+                {
+                    try
+                    {
+                        _resolveBundle(bundles[i]);
+                    }
+                    catch (BundleException ex)
+                    {
+                        result = false;
+                        m_logger.log(
+                            Logger.LOG_WARNING,
+                            "Unable to resolve bundle " + bundles[i].getBundleId(),
+                            ex);
+                    }
+                }
+            }
+
+            return result;
+        }
+        finally
+        {
+            // Always release all bundle locks.
+            releaseBundleLocks(bundles);
+        }
+    }
+
     protected void refreshPackages(Bundle[] targets)
     {
         if (System.getSecurityManager() != null)
         {
+// TODO: FW SECURITY - Perform proper security check.
             AccessController.checkPermission(m_adminPerm);
         }
 
@@ -3830,6 +3875,94 @@
         }
     }
 
+    protected BundleImpl[] acquireBundleResolveLocks(Bundle[] targets)
+    {
+        // Hold bundles to be locked.
+        BundleImpl[] bundles = null;
+        // Convert existing target bundle array to bundle impl array.
+        if (targets != null)
+        {
+            bundles = new BundleImpl[targets.length];
+            for (int i = 0; i < targets.length; i++)
+            {
+                bundles[i] = (BundleImpl) targets[i];
+            }
+        }
+
+        synchronized (m_bundleLock)
+        {
+            boolean success = false;
+            while (!success)
+            {
+                // If targets is null, then resolve all unresolved bundles.
+                if (targets == null)
+                {
+                    List list = new ArrayList();
+
+                    // Add all unresolved bundles to the list.
+                    synchronized (m_installedBundleLock_Priority2)
+                    {
+                        Iterator iter = m_installedBundleMap.values().iterator();
+                        while (iter.hasNext())
+                        {
+                            BundleImpl bundle = (BundleImpl) iter.next();
+                            if (bundle.getInfo().getState() == Bundle.INSTALLED)
+                            {
+                                list.add(bundle);
+                            }
+                        }
+                    }
+
+                    // Create an array.
+                    if (list.size() > 0)
+                    {
+                        bundles = (BundleImpl[]) list.toArray(new BundleImpl[list.size()]);
+                    }
+                }
+                
+                // Check if all unresolved bundles can be locked.
+                boolean lockable = true;
+                if (bundles != null)
+                {
+                    for (int i = 0; lockable && (i < bundles.length); i++)
+                    {
+                        lockable = bundles[i].getInfo().isLockable();
+                    }
+        
+                    // If we can lock all bundles, then lock them.
+                    if (lockable)
+                    {
+                        for (int i = 0; i < bundles.length; i++)
+                        {
+                            bundles[i].getInfo().lock();
+                        }
+                        success = true;
+                    }
+                    // Otherwise, wait and try again.
+                    else
+                    {
+                        try
+                        {
+                            m_bundleLock.wait();
+                        }
+                        catch (InterruptedException ex)
+                        {
+                            // Ignore and just keep waiting.
+                        }
+                    }
+                }
+                else
+                {
+                    // If there were no bundles to lock, then we can just
+                    // exit the lock loop.
+                    success = true;
+                }
+            }
+        }
+
+        return bundles;
+    }
+
     protected BundleImpl[] acquireBundleRefreshLocks(Bundle[] targets)
     {
         // Hold bundles to be locked.
@@ -3898,7 +4031,7 @@
                     bundles = (BundleImpl[]) map.values().toArray(new BundleImpl[map.size()]);
                 }
                 
-                // Check if all corresponding bundles can be locked
+                // Check if all corresponding bundles can be locked.
                 boolean lockable = true;
                 if (bundles != null)
                 {

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/PackageAdminImpl.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/PackageAdminImpl.java?rev=409159&r1=409158&r2=409159&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/PackageAdminImpl.java
(original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/PackageAdminImpl.java
Wed May 24 06:46:06 2006
@@ -1,5 +1,5 @@
 /*
- *   Copyright 2005 The Apache Software Foundation
+ *   Copyright 2006 The Apache Software Foundation
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
  *   you may not use this file except in compliance with the License.
@@ -146,8 +146,7 @@
 
     public boolean resolveBundles(Bundle[] bundles)
     {
-        // TODO: Implement PackageAdmin.resolveBundles()
-        return false;
+        return m_felix.resolveBundles(bundles);
     }
 
     public RequiredBundle[] getRequiredBundles(String symbolicName)



Mime
View raw message