You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by pa...@apache.org on 2020/10/22 22:43:07 UTC

[felix-dev] branch connect updated: Cache the current revision

This is an automated email from the ASF dual-hosted git repository.

pauls pushed a commit to branch connect
in repository https://gitbox.apache.org/repos/asf/felix-dev.git


The following commit(s) were added to refs/heads/connect by this push:
     new a5c4619  Cache the current revision
a5c4619 is described below

commit a5c4619a333f914991fe94536f3102cab1df1992
Author: Karl Pauls <ka...@gmail.com>
AuthorDate: Fri Oct 23 00:42:55 2020 +0200

    Cache the current revision
---
 .../java/org/apache/felix/framework/BundleImpl.java   | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/framework/src/main/java/org/apache/felix/framework/BundleImpl.java b/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
index f8f0591..a0d180e 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
@@ -68,6 +68,7 @@ class BundleImpl implements Bundle, BundleRevisions
 
     private final BundleArchive m_archive;
     private final List<BundleRevisionImpl> m_revisions = new ArrayList<BundleRevisionImpl>(0);
+    private volatile BundleRevisionImpl m_currentRevision = null;
     private volatile int m_state;
     private boolean m_useDeclaredActivationPolicy;
     private BundleActivator m_activator = null;
@@ -205,6 +206,7 @@ class BundleImpl implements Bundle, BundleRevisions
             }
 
             m_revisions.clear();
+            m_currentRevision = null;
 
             // Re-add the revision to the bundle.
             addRevision(current);
@@ -1099,7 +1101,7 @@ class BundleImpl implements Bundle, BundleRevisions
     }
 
     @Override
-    public synchronized <A> A adapt(Class<A> type)
+    public <A> A adapt(Class<A> type)
     {
         checkAdapt(type);
         if (type == BundleContext.class)
@@ -1117,14 +1119,14 @@ class BundleImpl implements Bundle, BundleRevisions
             {
                 return null;
             }
-            return (A) m_revisions.get(0);
+            return (A) m_currentRevision;
         }
         // We need some way to get the current revision even if
         // the associated bundle is uninstalled, so we use the
         // impl revision class for this purpose.
         else if (type == BundleRevisionImpl.class)
         {
-            return (A) m_revisions.get(0);
+            return (A) m_currentRevision;
         }
         else if (type == BundleRevisions.class)
         {
@@ -1136,7 +1138,9 @@ class BundleImpl implements Bundle, BundleRevisions
             {
                 return null;
             }
-            return (A) m_revisions.get(0).getWiring();
+            BundleRevisionImpl revision = m_currentRevision;
+
+            return (A) (revision != null ? revision.getWiring() : null);
         }
         else if ( type == AccessControlContext.class)
         {
@@ -1237,6 +1241,8 @@ class BundleImpl implements Bundle, BundleRevisions
     synchronized boolean rollbackRevise() throws Exception
     {
         BundleRevision br = m_revisions.remove(0);
+        m_currentRevision = !m_revisions.isEmpty() ? m_revisions.get(0) : null;
+
         // Since revising a bundle adds a revision to the global
         // state, we must remove it from the global state on rollback.
         getFramework().getResolver().removeRevision(br);
@@ -1250,7 +1256,9 @@ class BundleImpl implements Bundle, BundleRevisions
     // which is the normal case.
     synchronized void addRevision(BundleRevisionImpl revision) throws Exception
     {
+        BundleRevisionImpl previous = m_currentRevision;
         m_revisions.add(0, revision);
+        m_currentRevision = revision;
 
         try
         {
@@ -1259,6 +1267,7 @@ class BundleImpl implements Bundle, BundleRevisions
         catch (Exception ex)
         {
             m_revisions.remove(0);
+            m_currentRevision = previous;
             throw ex;
         }
 
@@ -1355,7 +1364,7 @@ class BundleImpl implements Bundle, BundleRevisions
     {
         ProtectionDomain pd = null;
 
-        for (int i = m_revisions.size() - 1; (i >= 0) && (pd == null); i--)
+        for (int i = 0; (i < m_revisions.size()) && (pd == null); i++)
         {
             pd = m_revisions.get(i).getProtectionDomain();
         }