You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by fm...@apache.org on 2010/08/06 09:08:07 UTC
svn commit: r982892 - in
/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl: Activator.java
config/ConfigurationComponentRegistry.java config/ScrConfiguration.java
manager/ComponentContextImpl.java
Author: fmeschbe
Date: Fri Aug 6 07:08:07 2010
New Revision: 982892
URL: http://svn.apache.org/viewvc?rev=982892&view=rev
Log:
FELIX-2526 Implement workaround for CT bugs and add framework property to enable the workarounds
Modified:
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurationComponentRegistry.java
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfiguration.java
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/Activator.java?rev=982892&r1=982891&r2=982892&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/Activator.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/Activator.java Fri Aug 6 07:08:07 2010
@@ -73,6 +73,10 @@ public class Activator implements Bundle
// thread acting upon configurations
private ComponentActorThread m_componentActor;
+ // whether to support two workarounds to run the OSGi R 4.2 CT
+ // See hasCtWorkaround()
+ private static boolean m_ctWorkaround;
+
/**
* Registers this instance as a (synchronous) bundle listener and loads the
* components of already registered bundles.
@@ -100,6 +104,9 @@ public class Activator implements Bundle
log( LogService.LOG_INFO, context.getBundle(), " Version = "
+ context.getBundle().getHeaders().get( Constants.BUNDLE_VERSION ), null );
+ // check whether we workaround OSGi CT issues
+ m_ctWorkaround = ScrConfiguration.hasCtWorkaround( context );
+
// create and start the component actor
m_componentActor = new ComponentActorThread();
Thread t = new Thread(m_componentActor, "SCR Component Actor");
@@ -474,4 +481,33 @@ public class Activator implements Bundle
return m_packageAdmin.getService();
}
+
+
+ /**
+ * Returns <code>true</code> if the <code>ds.ctworkaround</code> framework
+ * property has been set to <code>true</code>. Otherwise <code>false</code>
+ * is returned.
+ * <p>
+ * If this method returns <code>true</code>, two workarounds for the OSGi
+ * Compendium R 4.2 CT for Declarative Services are active:
+ * <ul>
+ * <li>The <code>ComponentContext.getProperties()</code> implementation
+ * always returns the same writeable <code>Dictionary</code> instead of
+ * a read-only dictionary</li>
+ * <li>Location binding of <code>Configuration</code> objects supplied to
+ * components is ignored.</li>
+ * </ul>
+ * <p>
+ * Setting the <code>ds.ctworkaround</code> framework property is required
+ * to pass the CT but setting the property in a productive environment
+ * is strongly discouraged.
+ *
+ * @return <code>true</code> if the <code>ds.ctworkaround</code> framework
+ * property is set to <code>true</code>.
+ * @see <a href="https://issues.apache.org/jira/browse/FELIX-2526">FELIX-2526</a>
+ */
+ public static boolean hasCtWorkaround()
+ {
+ return m_ctWorkaround;
+ }
}
\ No newline at end of file
Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurationComponentRegistry.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurationComponentRegistry.java?rev=982892&r1=982891&r2=982892&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurationComponentRegistry.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurationComponentRegistry.java Fri Aug 6 07:08:07 2010
@@ -235,6 +235,10 @@ public class ConfigurationComponentRegis
cm = getComponentHolder( factoryPid );
}
+ Activator.log( LogService.LOG_DEBUG, null, "configurationEvent: Handling "
+ + ( ( event.getType() == ConfigurationEvent.CM_DELETED ) ? "DELETE" : "UPDATE" ) + " of Configuration PID="
+ + pid, null );
+
if ( cm != null && !cm.getComponentMetadata().isConfigurationIgnored() )
{
switch ( event.getType() )
@@ -299,7 +303,7 @@ public class ConfigurationComponentRegis
try
{
final Configuration cfg = ca.getConfiguration( pid );
- if ( bundleLocation.equals( cfg.getBundleLocation() ) )
+ if ( Activator.hasCtWorkaround() || bundleLocation.equals( cfg.getBundleLocation() ) )
{
return cfg.getProperties();
}
Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfiguration.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfiguration.java?rev=982892&r1=982891&r2=982892&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfiguration.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfiguration.java Fri Aug 6 07:08:07 2010
@@ -22,6 +22,7 @@ package org.apache.felix.scr.impl.config
import java.util.Dictionary;
import java.util.Hashtable;
+import org.apache.felix.scr.impl.Activator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.service.cm.ConfigurationException;
@@ -46,6 +47,9 @@ public class ScrConfiguration
static final String PROP_LOGLEVEL = "ds.loglevel";
+ // framework property to enable the CT workarounds (see FELIX-2526)
+ private static final String PROP_CT_WORKAROUND = "ds.ctworkaround";
+
private static final String LOG_LEVEL_DEBUG = "debug";
private static final String LOG_LEVEL_INFO = "info";
@@ -64,6 +68,8 @@ public class ScrConfiguration
private boolean factoryEnabled;
+ private boolean ctWorkaround;
+
static final String PID = "org.apache.felix.scr.ScrService";
public ScrConfiguration( BundleContext bundleContext )
@@ -109,7 +115,6 @@ public class ScrConfiguration
{
if ( config == null )
{
-
logLevel = getDefaultLogLevel();
factoryEnabled = getDefaultFactoryEnabled();
}
@@ -132,7 +137,30 @@ public class ScrConfiguration
}
- private boolean getDefaultFactoryEnabled() {
+ public static boolean hasCtWorkaround( final BundleContext bundleContext )
+ {
+ boolean ctWorkaround = VALUE_TRUE.equals( bundleContext.getProperty( PROP_CT_WORKAROUND ) );
+ if ( ctWorkaround )
+ {
+ Activator
+ .log(
+ LogService.LOG_WARNING,
+ bundleContext.getBundle(),
+ "OSGi CT Workaround enabled. This Declarative Services instance is not operating specification compliant:",
+ null );
+ Activator.log( LogService.LOG_WARNING, bundleContext.getBundle(),
+ " - Dictionary returned from ComponentContext.getProperties() is writeable", null );
+ Activator.log( LogService.LOG_WARNING, bundleContext.getBundle(),
+ " - Location Binding of Configuration is ignored", null );
+ Activator.log( LogService.LOG_WARNING, bundleContext.getBundle(), "Remove " + PROP_CT_WORKAROUND
+ + " framework property to operate specification compliant", null );
+ }
+ return ctWorkaround;
+ }
+
+
+ private boolean getDefaultFactoryEnabled()
+ {
return VALUE_TRUE.equals( bundleContext.getProperty( PROP_FACTORY_ENABLED ) );
}
@@ -203,7 +231,8 @@ public class ScrConfiguration
{
return new MetaTypeProviderImpl( getDefaultLogLevel(), getDefaultFactoryEnabled(),
( ManagedService ) managedService );
- } catch (Throwable t)
+ }
+ catch ( Throwable t )
{
// we simply ignore this
}
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=982892&r1=982891&r2=982892&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 Fri Aug 6 07:08:07 2010
@@ -21,6 +21,7 @@ package org.apache.felix.scr.impl.manage
import java.util.Dictionary;
+import org.apache.felix.scr.impl.Activator;
import org.apache.felix.scr.impl.helper.ReadOnlyDictionary;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -52,8 +53,13 @@ public class ComponentContextImpl implem
public final Dictionary getProperties()
{
- // 112.11.3.5 The Dictionary is read-only and cannot be modified
- return new ReadOnlyDictionary( m_componentManager.getProperties() );
+ // 112.12.3.5 The Dictionary is read-only and cannot be modified
+ Dictionary ctxProperties = m_componentManager.getProperties();
+ if ( !Activator.hasCtWorkaround() )
+ {
+ ctxProperties = new ReadOnlyDictionary( ctxProperties );
+ }
+ return ctxProperties;
}