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 2012/10/18 08:49:39 UTC
svn commit: r1399530 - in
/felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl:
ConfigurationManager.java helper/BaseTracker.java
helper/ConfigurationMap.java helper/ManagedServiceFactoryTracker.java
helper/ManagedServiceTracker.java
Author: fmeschbe
Date: Thu Oct 18 06:49:39 2012
New Revision: 1399530
URL: http://svn.apache.org/viewvc?rev=1399530&view=rev
Log:
FELIX-3721 Make sure ManagedService[Factory] services are always called back on initial service registration
Modified:
felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/helper/BaseTracker.java
felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/helper/ConfigurationMap.java
felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/helper/ManagedServiceFactoryTracker.java
felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/helper/ManagedServiceTracker.java
Modified: felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java?rev=1399530&r1=1399529&r2=1399530&view=diff
==============================================================================
--- felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java (original)
+++ felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java Thu Oct 18 06:49:39 2012
@@ -36,6 +36,7 @@ import java.util.Random;
import org.apache.felix.cm.PersistenceManager;
import org.apache.felix.cm.file.FilePersistenceManager;
import org.apache.felix.cm.impl.helper.BaseTracker;
+import org.apache.felix.cm.impl.helper.ConfigurationMap;
import org.apache.felix.cm.impl.helper.ManagedServiceFactoryTracker;
import org.apache.felix.cm.impl.helper.ManagedServiceTracker;
import org.apache.felix.cm.impl.helper.TargetedPID;
@@ -903,7 +904,7 @@ public class ConfigurationManager implem
* be a <code>ManagedServiceFactory</code>. Otherwise the service
* is considered to be a <code>ManagedService</code>.
*/
- public void configure( String[] pid, ServiceReference sr, final boolean factory )
+ public void configure( String[] pid, ServiceReference sr, final boolean factory, final ConfigurationMap<?> configs )
{
if ( this.isLogEnabled( LogService.LOG_DEBUG ) )
{
@@ -914,11 +915,11 @@ public class ConfigurationManager implem
Runnable r;
if ( factory )
{
- r = new ManagedServiceFactoryUpdate( pid, sr );
+ r = new ManagedServiceFactoryUpdate( pid, sr, configs );
}
else
{
- r = new ManagedServiceUpdate( pid, sr );
+ r = new ManagedServiceUpdate( pid, sr, configs );
}
updateThread.schedule( r );
log( LogService.LOG_DEBUG, "[{0}] scheduled", new Object[]
@@ -1370,10 +1371,14 @@ public class ConfigurationManager implem
private final ServiceReference sr;
- ManagedServiceUpdate( String[] pids, ServiceReference sr )
+ private final ConfigurationMap<?> configs;
+
+
+ ManagedServiceUpdate( String[] pids, ServiceReference sr, ConfigurationMap<?> configs )
{
this.pids = pids;
this.sr = sr;
+ this.configs = configs;
}
@@ -1428,7 +1433,7 @@ public class ConfigurationManager implem
log( LogService.LOG_DEBUG, "Updating service {0} with configuration {1}@{2}", new Object[]
{ servicePid, configPid, new Long( revision ) } );
- managedServiceTracker.provideConfiguration( sr, configPid, null, properties, revision);
+ managedServiceTracker.provideConfiguration( sr, configPid, null, properties, revision, this.configs );
}
public String toString()
@@ -1450,11 +1455,14 @@ public class ConfigurationManager implem
private final ServiceReference sr;
+ private final ConfigurationMap<?> configs;
+
- ManagedServiceFactoryUpdate( String[] factoryPids, ServiceReference sr )
+ ManagedServiceFactoryUpdate( String[] factoryPids, ServiceReference sr, final ConfigurationMap<?> configs )
{
this.factoryPids = factoryPids;
this.sr = sr;
+ this.configs = configs;
}
@@ -1583,7 +1591,7 @@ public class ConfigurationManager implem
log( LogService.LOG_DEBUG, "{0}: Updating configuration pid={1}", new Object[]
{ ConfigurationManager.toString( sr ), config.getPid() } );
managedServiceFactoryTracker.provideConfiguration( sr, config.getPid(), config.getFactoryPid(),
- rawProperties, revision );
+ rawProperties, revision, this.configs );
}
}
@@ -1647,7 +1655,7 @@ public class ConfigurationManager implem
revision = rc.getRevision();
}
- helper.provideConfiguration( sr, configPid, null, properties, -revision );
+ helper.provideConfiguration( sr, configPid, null, properties, -revision, null );
return true;
}
@@ -1713,7 +1721,7 @@ public class ConfigurationManager implem
else if ( canReceive( refBundle, configBundleLocation ) )
{
helper.provideConfiguration( ref, this.config.getPid(), this.config.getFactoryPid(),
- this.properties, this.revision );
+ this.properties, this.revision, null );
}
else
{
@@ -1879,7 +1887,7 @@ public class ConfigurationManager implem
{
// call updated method
helper.provideConfiguration( sr, this.config.getPid(), this.config.getFactoryPid(),
- this.properties, this.revision );
+ this.properties, this.revision, null );
log( LogService.LOG_DEBUG, "Configuration {0} provided to {1} (new visibility)", new Object[]
{ config.getPid(), ConfigurationManager.toString( sr ) } );
}
Modified: felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/helper/BaseTracker.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/helper/BaseTracker.java?rev=1399530&r1=1399529&r2=1399530&view=diff
==============================================================================
--- felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/helper/BaseTracker.java (original)
+++ felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/helper/BaseTracker.java Thu Oct 18 06:49:39 2012
@@ -67,8 +67,9 @@ public abstract class BaseTracker<S> ext
{ ConfigurationManager.toString( reference ) } );
final String[] pids = getServicePid( reference );
- configure( reference, pids );
- return createConfigurationMap( pids );
+ final ConfigurationMap<?> configurations = createConfigurationMap( pids );
+ configure( reference, pids, configurations );
+ return configurations;
}
@@ -81,7 +82,7 @@ public abstract class BaseTracker<S> ext
String[] pids = getServicePid( reference );
if ( service.isDifferentPids( pids ) )
{
- configure( reference, pids );
+ configure( reference, pids, service );
service.setConfiguredPids( pids );
}
}
@@ -96,11 +97,11 @@ public abstract class BaseTracker<S> ext
}
- private void configure( ServiceReference<S> reference, String[] pids )
+ private void configure( ServiceReference<S> reference, String[] pids, ConfigurationMap<?> configurations )
{
if ( pids != null )
{
- this.cm.configure( pids, reference, managedServiceFactory );
+ this.cm.configure( pids, reference, managedServiceFactory, configurations );
}
}
@@ -165,17 +166,33 @@ public abstract class BaseTracker<S> ext
* @param factoryPid The targeted factory PID or <code>null</code> for
* a non-factory configuration
* @param properties The configuration properties, which may be
- * <code>null</code> for a non-factory configuration
- * @param revision The configuration revision
+ * <code>null</code> if this is the provisioning call upon
+ * service registration of a ManagedService
+ * @param revision The configuration revision or -1 if there is no
+ * configuration actually to provide.
+ * @param configurationMap The PID to configuration map for PIDs
+ * used by the service to update
*
* @see {@link ManagedServiceTracker#provideConfiguration(ServiceReference, TargetedPID, TargetedPID, Dictionary, long)}
* @see {@link ManagedServiceFactoryTracker#provideConfiguration(ServiceReference, TargetedPID, TargetedPID, Dictionary, long)}
*/
public abstract void provideConfiguration( ServiceReference<S> service, TargetedPID configPid,
- TargetedPID factoryPid, Dictionary<String, ?> properties, long revision );
+ TargetedPID factoryPid, Dictionary<String, ?> properties, long revision,
+ ConfigurationMap<?> configurationMap);
- public abstract void removeConfiguration( ServiceReference<S> service, TargetedPID configPid, TargetedPID factoryPid );
+ /**
+ * Remove the configuration indicated by the {@code configPid} from
+ * the service.
+ *
+ * @param service The reference to the service from which the
+ * configuration is to be removed.
+ * @param configPid The {@link TargetedPID} of the configuration
+ * @param factoryPid The {@link TargetedPID factory PID} of the
+ * configuration. This may be {@code null} for a non-factory
+ * configuration.
+ */
+ public abstract void removeConfiguration( ServiceReference<S> service, TargetedPID configPid, TargetedPID factoryPid);
protected final S getRealService( ServiceReference<S> reference )
Modified: felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/helper/ConfigurationMap.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/helper/ConfigurationMap.java?rev=1399530&r1=1399529&r2=1399530&view=diff
==============================================================================
--- felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/helper/ConfigurationMap.java (original)
+++ felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/helper/ConfigurationMap.java Thu Oct 18 06:49:39 2012
@@ -26,7 +26,7 @@ import java.util.Map;
import java.util.Set;
-abstract class ConfigurationMap<T>
+public abstract class ConfigurationMap<T>
{
private Map<String, T> configurations;
Modified: felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/helper/ManagedServiceFactoryTracker.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/helper/ManagedServiceFactoryTracker.java?rev=1399530&r1=1399529&r2=1399530&view=diff
==============================================================================
--- felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/helper/ManagedServiceFactoryTracker.java (original)
+++ felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/helper/ManagedServiceFactoryTracker.java Thu Oct 18 06:49:39 2012
@@ -54,29 +54,47 @@ public class ManagedServiceFactoryTracke
@Override
public void provideConfiguration( ServiceReference<ManagedServiceFactory> reference, TargetedPID configPid,
- TargetedPID factoryPid, Dictionary<String, ?> properties, long revision )
+ TargetedPID factoryPid, Dictionary<String, ?> properties, long revision, ConfigurationMap<?> configs )
{
+ // Get the ManagedServiceFactory and terminate here if already
+ // unregistered from the framework concurrently
ManagedServiceFactory service = getRealService( reference );
- final ConfigurationMap configs = this.getService( reference );
- if ( service != null && configs != null )
+ if (service == null) {
+ return;
+ }
+
+ // Get the Configuration-to-PID map from the parameter or from
+ // the service tracker. If not available, the service tracker
+ // already unregistered this service concurrently
+ if ( configs == null )
{
- if ( configs.shallTake( configPid, factoryPid, revision ) )
+ configs = this.getService( reference );
+ if ( configs == null )
{
- try
- {
- Dictionary props = getProperties( properties, reference, configPid.toString(),
- factoryPid.toString() );
- service.updated( configPid.toString(), props );
- configs.record( configPid, factoryPid, revision );
- }
- catch ( Throwable t )
- {
- this.handleCallBackError( t, reference, configPid );
- }
- finally
- {
- this.ungetRealService( reference );
- }
+ return;
+ }
+ }
+
+ // Both the ManagedService to update and the Configuration-to-PID
+ // are available, so the service can be updated with the
+ // configuration (which may be null)
+
+ if ( configs.shallTake( configPid, factoryPid, revision ) )
+ {
+ try
+ {
+ Dictionary props = getProperties( properties, reference, configPid.toString(),
+ factoryPid.toString() );
+ service.updated( configPid.toString(), props );
+ configs.record( configPid, factoryPid, revision );
+ }
+ catch ( Throwable t )
+ {
+ this.handleCallBackError( t, reference, configPid );
+ }
+ finally
+ {
+ this.ungetRealService( reference );
}
}
}
Modified: felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/helper/ManagedServiceTracker.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/helper/ManagedServiceTracker.java?rev=1399530&r1=1399529&r2=1399530&view=diff
==============================================================================
--- felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/helper/ManagedServiceTracker.java (original)
+++ felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/helper/ManagedServiceTracker.java Thu Oct 18 06:49:39 2012
@@ -75,10 +75,10 @@ public class ManagedServiceTracker exten
*/
@Override
public void provideConfiguration( ServiceReference<ManagedService> service, TargetedPID configPid,
- TargetedPID factoryPid, Dictionary<String, ?> properties, long revision )
+ TargetedPID factoryPid, Dictionary<String, ?> properties, long revision, ConfigurationMap<?> configs )
{
Dictionary<String, ?> supplied = ( properties == null ) ? INITIAL_MARKER : properties;
- updateService( service, configPid, supplied, revision );
+ updateService( service, configPid, supplied, revision, configs );
}
@@ -86,57 +86,75 @@ public class ManagedServiceTracker exten
public void removeConfiguration( ServiceReference<ManagedService> service, TargetedPID configPid,
TargetedPID factoryPid )
{
- updateService( service, configPid, null, -1 );
+ updateService( service, configPid, null, -1, null );
}
private void updateService( ServiceReference<ManagedService> service, final TargetedPID configPid,
- Dictionary<String, ?> properties, long revision )
+ Dictionary<String, ?> properties, long revision, ConfigurationMap<?> configs)
{
+ // Get the ManagedService and terminate here if already
+ // unregistered from the framework concurrently
final ManagedService srv = this.getRealService( service );
- final ConfigurationMap configs = this.getService( service );
- if ( srv != null && configs != null )
+ if (srv == null) {
+ return;
+ }
+
+ // Get the Configuration-to-PID map from the parameter or from
+ // the service tracker. If not available, the service tracker
+ // already unregistered this service concurrently
+ if ( configs == null )
{
- boolean doUpdate = false;
- if ( properties == null )
+ configs = this.getService( service );
+ if ( configs == null )
{
- doUpdate = configs.removeConfiguration( configPid, null );
+ return;
}
- else if ( properties == INITIAL_MARKER )
- {
- // initial call to ManagedService may supply null properties
- properties = null;
- revision = -1;
- doUpdate = true;
- }
- else if ( revision < 0 || configs.shallTake( configPid, null, revision ) )
+ }
+
+ // Both the ManagedService to update and the Configuration-to-PID
+ // are available, so the service can be updated with the
+ // configuration (which may be null)
+
+ boolean doUpdate = false;
+ if ( properties == null )
+ {
+ doUpdate = configs.removeConfiguration( configPid, null );
+ }
+ else if ( properties == INITIAL_MARKER )
+ {
+ // initial call to ManagedService may supply null properties
+ properties = null;
+ revision = -1;
+ doUpdate = true;
+ }
+ else if ( revision < 0 || configs.shallTake( configPid, null, revision ) )
+ {
+ // run the plugins and cause the update
+ properties = getProperties( properties, service, configPid.toString(), null );
+ doUpdate = true;
+ revision = Math.abs( revision );
+ }
+ else
+ {
+ // new configuration is not a better match, don't update
+ doUpdate = false;
+ }
+
+ if ( doUpdate )
+ {
+ try
{
- // run the plugins and cause the update
- properties = getProperties( properties, service, configPid.toString(), null );
- doUpdate = true;
- revision = Math.abs( revision );
+ srv.updated( properties );
+ configs.record( configPid, null, revision );
}
- else
+ catch ( Throwable t )
{
- // new configuration is not a better match, don't update
- doUpdate = false;
+ this.handleCallBackError( t, service, configPid );
}
-
- if ( doUpdate )
+ finally
{
- try
- {
- srv.updated( properties );
- configs.record( configPid, null, revision );
- }
- catch ( Throwable t )
- {
- this.handleCallBackError( t, service, configPid );
- }
- finally
- {
- this.ungetRealService( service );
- }
+ this.ungetRealService( service );
}
}
}