felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1737170 - in /felix/trunk/scr/src: main/java/org/apache/felix/scr/impl/manager/ test/java/org/apache/felix/scr/impl/helper/ test/java/org/apache/felix/scr/impl/manager/ test/java/org/apache/felix/scr/integration/ test/java/org/apache/felix...
Date Thu, 31 Mar 2016 00:19:31 GMT
Author: djencks
Date: Thu Mar 31 00:19:31 2016
New Revision: 1737170

URL: http://svn.apache.org/viewvc?rev=1737170&view=rev
Log:
FELIX-5213, make ServiceReference accessible always during activation

Modified:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceFactoryComponentManager.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleComponentManager.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/helper/BindMethodTest.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/manager/SingleComponentManagerTest.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/MutablePropertiesTest.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/MutatingServiceImpl.java

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java?rev=1737170&r1=1737169&r2=1737170&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
Thu Mar 31 00:19:31 2016
@@ -721,7 +721,7 @@ public abstract class AbstractComponentM
 
             if ( ( isImmediate() || getComponentMetadata().isFactory() ) )
             {
-                getServiceInternal();
+                getServiceInternal(registrationManager.getServiceRegistration());
             }
         }
         finally
@@ -808,21 +808,11 @@ public abstract class AbstractComponentM
         unregisterComponentId();
     }
 
-    final ServiceReference<S> getServiceReference()
-    {
-        ServiceRegistration<S> reg = getServiceRegistration();
-        if (reg != null)
-        {
-            return reg.getReference();
-        }
-        return null;
-    }
-
     //---------- Component handling methods ----------------------------------
 
     protected abstract void deleteComponent( int reason );
 
-    boolean getServiceInternal()
+    boolean getServiceInternal(ServiceRegistration<S> serviceRegistration)
     {
         return false;
     }
@@ -1023,12 +1013,6 @@ public abstract class AbstractComponentM
     }
 
 
-    final ServiceRegistration<S> getServiceRegistration()
-    {
-        return registrationManager.getServiceRegistration();
-    }
-
-
     synchronized void clear()
     {
         // for some testing, the activator may be null

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java?rev=1737170&r1=1737169&r2=1737170&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
Thu Mar 31 00:19:31 2016
@@ -30,6 +30,7 @@ import org.apache.felix.scr.impl.helper.
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.component.ComponentInstance;
 import org.osgi.service.log.LogService;
 
@@ -47,6 +48,8 @@ public class ComponentContextImpl<S> imp
     private final ComponentInstance m_componentInstance = new ComponentInstanceImpl<S>(this);
 
     private final Bundle m_usingBundle;
+    
+    private final ServiceRegistration<S> m_serviceRegistration;
 
     private volatile S m_implementationObject;
 
@@ -56,10 +59,11 @@ public class ComponentContextImpl<S> imp
 
     private final ComponentServiceObjectsHelper serviceObjectsHelper;
 
-    public ComponentContextImpl( final SingleComponentManager<S> componentManager,
final Bundle usingBundle )
+    public ComponentContextImpl( final SingleComponentManager<S> componentManager,
final Bundle usingBundle, ServiceRegistration<S> serviceRegistration )
     {
         m_componentManager = componentManager;
         m_usingBundle = usingBundle;
+        m_serviceRegistration = serviceRegistration;
         edgeInfos = new EdgeInfo[componentManager.getComponentMetadata().getDependencies().size()];
         for (int i = 0; i< edgeInfos.length; i++)
         {
@@ -99,6 +103,11 @@ public class ComponentContextImpl<S> imp
         return edgeInfos[index];
     }
 
+    ServiceRegistration<S> getServiceRegistration()
+    {
+        return m_serviceRegistration;
+    }
+
    protected SingleComponentManager<S> getComponentManager()
     {
         return m_componentManager;
@@ -196,7 +205,7 @@ public class ComponentContextImpl<S> imp
 
     public ServiceReference<S> getServiceReference()
     {
-        return m_componentManager.getServiceReference();
+        return m_serviceRegistration == null? null: m_serviceRegistration.getReference();
     }
 
 
@@ -263,4 +272,5 @@ public class ComponentContextImpl<S> imp
         }
 
     }
+
 }

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceFactoryComponentManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceFactoryComponentManager.java?rev=1737170&r1=1737169&r2=1737170&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceFactoryComponentManager.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceFactoryComponentManager.java
Thu Mar 31 00:19:31 2016
@@ -46,7 +46,7 @@ public class ServiceFactoryComponentMana
     @Override
     public void setServiceProperties(Dictionary<String, ?> serviceProperties)
     {
-        throw new IllegalStateException( "Bundle scoped service properties are immutable"
);
+        throw new IllegalStateException( "Bundle or instance scoped service properties are
immutable" );
     }
 
 
@@ -92,13 +92,13 @@ public class ServiceFactoryComponentMana
     /* (non-Javadoc)
      * @see org.osgi.framework.ServiceFactory#getService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration)
      */
-    public S getService( Bundle bundle, ServiceRegistration<S> registration )
+    public S getService( Bundle bundle, ServiceRegistration<S> serviceRegistration
)
     {
         log( LogService.LOG_DEBUG, "ServiceFactory.getService()", null );
 
         // When the getServiceMethod is called, the implementation object must be created
 
-        ComponentContextImpl<S> componentContext = new ComponentContextImpl<S>(this,
bundle);
+        ComponentContextImpl<S> componentContext = new ComponentContextImpl<S>(this,
bundle, serviceRegistration);
         if (collectDependencies(componentContext) )
         {
             log( LogService.LOG_DEBUG,

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleComponentManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleComponentManager.java?rev=1737170&r1=1737169&r2=1737170&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleComponentManager.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleComponentManager.java
Thu Mar 31 00:19:31 2016
@@ -37,6 +37,7 @@ import org.apache.felix.scr.impl.helper.
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.component.ComponentConstants;
 import org.osgi.service.component.ComponentInstance;
@@ -517,6 +518,22 @@ public class SingleComponentManager<S> e
         return super.getServiceProperties();
     }
 
+    final ServiceRegistration<S> getServiceRegistration()
+    {
+        return m_componentContext == null? null: m_componentContext.getServiceRegistration();
+    }
+
+
+    final ServiceReference<S> getServiceReference()
+    {
+        ServiceRegistration<S> reg = getServiceRegistration();
+        if (reg != null)
+        {
+            return reg.getReference();
+        }
+        return null;
+    }
+
     private void updateServiceRegistration()
     {
         ServiceRegistration<S> sr = getServiceRegistration();
@@ -788,7 +805,7 @@ public class SingleComponentManager<S> e
         }
         boolean decrement = true;
         try {
-            boolean success = getServiceInternal();
+            boolean success = getServiceInternal(serviceRegistration);
             ComponentContextImpl<S> componentContext = m_componentContext;
             if ( success && componentContext != null)
             {
@@ -811,7 +828,7 @@ public class SingleComponentManager<S> e
 
 
     @Override
-    boolean getServiceInternal()
+    boolean getServiceInternal(ServiceRegistration<S> serviceRegistration)
     {
         if (m_circularReferences.get() != null)
         {
@@ -825,7 +842,7 @@ public class SingleComponentManager<S> e
             boolean success = true;
             if ( m_componentContext == null )
             {
-                ComponentContextImpl<S> componentContext = new ComponentContextImpl<S>(this,
this.getBundle());
+                ComponentContextImpl<S> componentContext = new ComponentContextImpl<S>(this,
this.getBundle(), serviceRegistration);
                 if ( collectDependencies(componentContext))
                 {
                         log(

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/helper/BindMethodTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/helper/BindMethodTest.java?rev=1737170&r1=1737169&r2=1737170&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/helper/BindMethodTest.java (original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/helper/BindMethodTest.java Thu
Mar 31 00:19:31 2016
@@ -452,7 +452,7 @@ public class BindMethodTest extends Test
         BindMethod bm = new BindMethod( methodName, component.getClass(),
                 FakeService.class.getName(), dsVersion, false );
         RefPair refPair = new SingleRefPair( m_serviceReference );
-        ComponentContextImpl<T1> cc = new ComponentContextImpl(icm, new MockBundle());
+        ComponentContextImpl<T1> cc = new ComponentContextImpl(icm, new MockBundle(),
null);
         assertTrue( bm.getServiceObject( cc, refPair, m_context, icm ) );
         BindParameters bp = new BindParameters(cc, refPair);
         bm.invoke( component, bp, null, icm );

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/manager/SingleComponentManagerTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/manager/SingleComponentManagerTest.java?rev=1737170&r1=1737169&r2=1737170&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/manager/SingleComponentManagerTest.java
(original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/manager/SingleComponentManagerTest.java
Thu Mar 31 00:19:31 2016
@@ -33,6 +33,7 @@ import org.junit.Test;
 import org.mockito.Mockito;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
 
 public class SingleComponentManagerTest
 {
@@ -48,7 +49,7 @@ public class SingleComponentManagerTest
 
         SingleComponentManager<Object> scm = new SingleComponentManager<Object>(cc,
new ComponentMethods()) {
             @Override
-            boolean getServiceInternal()
+            boolean getServiceInternal(ServiceRegistration<Object> serviceRegistration)
             {
                 return true;
             }
@@ -58,7 +59,7 @@ public class SingleComponentManagerTest
         Bundle b = Mockito.mock(Bundle.class);
         Mockito.when(b.getBundleContext()).thenReturn(bc);
 
-        ComponentContextImpl<Object> cci = new ComponentContextImpl<Object>(scm,
b);
+        ComponentContextImpl<Object> cci = new ComponentContextImpl<Object>(scm,
b, null);
         Object implObj = new Object();
         cci.setImplementationObject(implObj);
         cci.setImplementationAccessible(true);
@@ -89,7 +90,7 @@ public class SingleComponentManagerTest
 
         SingleComponentManager<?> scm = new SingleComponentManager<Object>(cc,
new ComponentMethods()) {
             @Override
-            boolean getServiceInternal()
+            boolean getServiceInternal(ServiceRegistration<Object> serviceRegistration)
             {
                 return true;
             }

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/MutablePropertiesTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/MutablePropertiesTest.java?rev=1737170&r1=1737169&r2=1737170&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/MutablePropertiesTest.java
(original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/MutablePropertiesTest.java
Thu Mar 31 00:19:31 2016
@@ -223,7 +223,7 @@ public class MutablePropertiesTest exten
 
         enableAndCheck(cd);
 
-        assertMsc(msc, false, true, null);
+        assertMsc(msc, true, true, null);
     }
 
     private void assertMsc(MutatingServiceConsumer msc, Boolean set, Boolean updated, Boolean
unset)

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/MutatingServiceImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/MutatingServiceImpl.java?rev=1737170&r1=1737169&r2=1737170&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/MutatingServiceImpl.java
(original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/MutatingServiceImpl.java
Thu Mar 31 00:19:31 2016
@@ -46,7 +46,10 @@ public class MutatingServiceImpl impleme
     {
         this.activateContext = activateContext;
         Map result = new Hashtable( (Map )activateContext.getProperties() );
-        result.put( "theValue", "anotherValue1" );
+        if (activateContext.getServiceReference() != null) 
+        {
+            result.put( "theValue", "anotherValue1" );
+        }
         if (result.containsKey( ".p2" ))
         {
             result.put( ".theValue", "privateValue" );



Mime
View raw message