Felix Meschberger | 2fd5b58 | 2007-12-10 10:32:29 +0000 | [diff] [blame] | 1 | /* |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.apache.felix.cm.impl; |
| 20 | |
| 21 | |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 22 | import java.io.IOException; |
| 23 | import java.security.SecureRandom; |
Carsten Ziegeler | 4168398 | 2007-12-27 08:35:27 +0000 | [diff] [blame] | 24 | import java.util.*; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 25 | |
| 26 | import org.apache.felix.cm.PersistenceManager; |
| 27 | import org.apache.felix.cm.file.FilePersistenceManager; |
Carsten Ziegeler | 4168398 | 2007-12-27 08:35:27 +0000 | [diff] [blame] | 28 | import org.osgi.framework.*; |
| 29 | import org.osgi.service.cm.*; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 30 | import org.osgi.service.log.LogService; |
| 31 | import org.osgi.util.tracker.ServiceTracker; |
| 32 | |
| 33 | |
| 34 | /** |
| 35 | * The <code>ConfigurationManager</code> is the central class in this |
| 36 | * implementation of the Configuration Admin Service Specification. As such it |
| 37 | * has the following tasks: |
| 38 | * <ul> |
| 39 | * <li>It is a <code>BundleActivator</code> which is called when the bundle |
| 40 | * is started and stopped. |
| 41 | * <li>It is a <code>BundleListener</code> which gets informed when the |
| 42 | * states of bundles change. Mostly this is needed to unbind any bound |
| 43 | * configuration in case a bundle is uninstalled. |
| 44 | * <li>It is a <code>ServiceListener</code> which gets informed when |
| 45 | * <code>ManagedService</code> and <code>ManagedServiceFactory</code> |
| 46 | * services are registered and unregistered. This is used to provide |
| 47 | * configuration to these services. As a service listener it also listens for |
| 48 | * {@link PersistenceManager} instances being registered to support different |
| 49 | * configuration persistence layers. |
| 50 | * <li>A {@link ConfigurationAdminFactory} instance is registered as the |
| 51 | * <code>ConfigurationAdmin</code> service. |
| 52 | * <li>A {@link FilePersistenceManager} instance is registered as a default |
| 53 | * {@link PersistenceManager}. |
| 54 | * <li>Last but not least this instance manages all tasks laid out in the |
| 55 | * specification such as maintaining configuration, taking care of configuration |
| 56 | * events, etc. |
| 57 | * </ul> |
| 58 | * <p> |
| 59 | * The default {@link FilePersistenceManager} is configured with a configuration |
| 60 | * location taken from the <code>felix.cm.dir</code> framework property. If |
| 61 | * this property is not set the <code>config</code> directory in the current |
| 62 | * working directory as specified in the <code>user.dir</code> system property |
| 63 | * is used. |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 64 | */ |
| 65 | public class ConfigurationManager implements BundleActivator, BundleListener |
| 66 | { |
| 67 | |
| 68 | /** |
| 69 | * The name of the bundle context property defining the location for the |
| 70 | * configuration files (value is "felix.cm.dir"). |
Felix Meschberger | 2fd5b58 | 2007-12-10 10:32:29 +0000 | [diff] [blame] | 71 | * |
Carsten Ziegeler | 7853b9a | 2008-01-11 16:30:24 +0000 | [diff] [blame] | 72 | * @see #start(BundleContext) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 73 | */ |
| 74 | public static final String CM_CONFIG_DIR = "felix.cm.dir"; |
| 75 | |
Felix Meschberger | 08282c3 | 2009-01-28 07:01:55 +0000 | [diff] [blame] | 76 | /** |
| 77 | * The name of the bundle context property defining the maximum log level |
| 78 | * (value is "felix.cm.loglevel"). The log level setting is only used if |
| 79 | * there is no OSGi LogService available. Otherwise this setting is ignored. |
| 80 | * <p> |
| 81 | * This value of this property is expected to be an integer number |
| 82 | * corresponding to the log level values of the OSGi LogService. That is 1 |
| 83 | * for errors, 2 for warnings, 3 for informational messages and 4 for debug |
| 84 | * messages. The default value is 2, such that only warnings and errors are |
| 85 | * logged in the absence of a LogService. |
| 86 | */ |
| 87 | public static final String CM_LOG_LEVEL = "felix.cm.loglevel"; |
| 88 | |
Felix Meschberger | 85b355d | 2007-08-31 07:17:38 +0000 | [diff] [blame] | 89 | // The name of the LogService (not using the class, which might be missing) |
| 90 | private static final String LOG_SERVICE_NAME = "org.osgi.service.log.LogService"; |
Felix Meschberger | 2fd5b58 | 2007-12-10 10:32:29 +0000 | [diff] [blame] | 91 | |
Felix Meschberger | 08282c3 | 2009-01-28 07:01:55 +0000 | [diff] [blame] | 92 | private static final int CM_LOG_LEVEL_DEFAULT = 2; |
Felix Meschberger | 5dfaa96 | 2009-08-14 19:26:01 +0000 | [diff] [blame] | 93 | |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 94 | // random number generator to create configuration PIDs for factory |
| 95 | // configurations |
| 96 | private static SecureRandom numberGenerator; |
| 97 | |
| 98 | // comparator used to keep the ordered persistence manager map |
| 99 | private static final Comparator cmRankComp = new RankingComparator( true, ConfigurationPlugin.CM_RANKING ); |
| 100 | |
| 101 | // the BundleContext of the Configuration Admin Service bundle |
| 102 | private BundleContext bundleContext; |
| 103 | |
Felix Meschberger | db90b1b | 2007-09-06 08:18:10 +0000 | [diff] [blame] | 104 | // the service registration of the configuration admin |
| 105 | private ServiceRegistration configurationAdminRegistration; |
Felix Meschberger | 2fd5b58 | 2007-12-10 10:32:29 +0000 | [diff] [blame] | 106 | |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 107 | // the ServiceTracker to emit log services (see log(int, String, Throwable)) |
| 108 | private ServiceTracker logTracker; |
| 109 | |
| 110 | // the ConfigurationEvent listeners |
| 111 | private ServiceTracker configurationListenerTracker; |
| 112 | |
| 113 | // service tracker for managed services |
| 114 | private ServiceTracker managedServiceTracker; |
| 115 | |
| 116 | // service tracker for managed service factories |
| 117 | private ServiceTracker managedServiceFactoryTracker; |
| 118 | |
| 119 | // PersistenceManager services |
| 120 | private ServiceTracker persistenceManagerTracker; |
| 121 | |
| 122 | // the thread used to schedule tasks required to run asynchronously |
| 123 | private UpdateThread updateThread; |
| 124 | |
| 125 | /** |
| 126 | * The actual list of {@link PersistenceManager persistence managers} to use |
| 127 | * when looking for configuration data. This list is built from the |
| 128 | * {@link #persistenceManagerMap}, which is ordered according to the |
| 129 | * {@link RankingComparator}. |
| 130 | */ |
| 131 | private PersistenceManager[] persistenceManagers; |
| 132 | |
| 133 | // the persistenceManagerTracker.getTrackingCount when the |
| 134 | // persistenceManagers were last got |
| 135 | private int pmtCount; |
| 136 | |
| 137 | // the cache of Factory instances mapped by their factory PID |
Felix Meschberger | 6a698df | 2009-08-16 18:38:46 +0000 | [diff] [blame] | 138 | private final Map factories = new HashMap(); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 139 | |
| 140 | // the cache of Configuration instances mapped by their PID |
Felix Meschberger | 5d3e7ac | 2009-08-14 21:45:10 +0000 | [diff] [blame] | 141 | // have this always set to prevent NPE on bundle shutdown |
| 142 | private final Map configurations = new HashMap(); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 143 | |
Felix Meschberger | 3f9e4da | 2009-08-17 07:52:39 +0000 | [diff] [blame] | 144 | /** |
| 145 | * The map of dynamic configuration bindings. This maps the |
| 146 | * PID of the dynamically bound configuration or factory to its bundle |
| 147 | * location. |
| 148 | * <p> |
| 149 | * On bundle startup this map is loaded from persistence and validated |
| 150 | * against the locations of installed bundles: Entries pointing to bundle |
| 151 | * locations not currently installed are removed. |
| 152 | * <p> |
| 153 | * The map is written to persistence on each change. |
| 154 | */ |
| 155 | private DynamicBindings dynamicBindings; |
| 156 | |
Felix Meschberger | 08282c3 | 2009-01-28 07:01:55 +0000 | [diff] [blame] | 157 | // the maximum log level when no LogService is available |
| 158 | private int logLevel = CM_LOG_LEVEL_DEFAULT; |
Felix Meschberger | 5dfaa96 | 2009-08-14 19:26:01 +0000 | [diff] [blame] | 159 | |
Felix Meschberger | 2c2a5be | 2009-03-26 16:47:01 +0000 | [diff] [blame] | 160 | // flag indicating whether BundleChange events should be consumed (FELIX-979) |
| 161 | private volatile boolean handleBundleEvents; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 162 | |
| 163 | public void start( BundleContext bundleContext ) |
| 164 | { |
| 165 | // track the log service using a ServiceTracker |
Felix Meschberger | 85b355d | 2007-08-31 07:17:38 +0000 | [diff] [blame] | 166 | logTracker = new ServiceTracker( bundleContext, LOG_SERVICE_NAME , null ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 167 | logTracker.open(); |
Felix Meschberger | 5dfaa96 | 2009-08-14 19:26:01 +0000 | [diff] [blame] | 168 | |
Felix Meschberger | 08282c3 | 2009-01-28 07:01:55 +0000 | [diff] [blame] | 169 | // assign the log level |
| 170 | String logLevelProp = bundleContext.getProperty( CM_LOG_LEVEL ); |
| 171 | if ( logLevelProp == null ) |
| 172 | { |
| 173 | logLevel = CM_LOG_LEVEL_DEFAULT; |
| 174 | } |
| 175 | else |
| 176 | { |
| 177 | try |
| 178 | { |
| 179 | logLevel = Integer.parseInt( logLevelProp ); |
| 180 | } |
| 181 | catch ( NumberFormatException nfe ) |
| 182 | { |
| 183 | logLevel = CM_LOG_LEVEL_DEFAULT; |
| 184 | } |
| 185 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 186 | |
| 187 | // set up some fields |
| 188 | this.bundleContext = bundleContext; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 189 | |
| 190 | // configurationlistener support |
| 191 | configurationListenerTracker = new ServiceTracker( bundleContext, ConfigurationListener.class.getName(), null ); |
| 192 | configurationListenerTracker.open(); |
| 193 | |
| 194 | // initialize the asynchonous updater thread |
| 195 | this.updateThread = new UpdateThread( this ); |
| 196 | this.updateThread.start(); |
| 197 | |
| 198 | // set up the location (might throw IllegalArgumentException) |
| 199 | try |
| 200 | { |
Felix Meschberger | 86a0d17 | 2007-07-04 07:15:01 +0000 | [diff] [blame] | 201 | FilePersistenceManager fpm = new FilePersistenceManager( bundleContext, bundleContext |
| 202 | .getProperty( CM_CONFIG_DIR ) ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 203 | Hashtable props = new Hashtable(); |
| 204 | props.put( Constants.SERVICE_PID, fpm.getClass().getName() ); |
| 205 | props.put( Constants.SERVICE_DESCRIPTION, "Platform Filesystem Persistence Manager" ); |
| 206 | props.put( Constants.SERVICE_VENDOR, "Apache Software Foundation" ); |
| 207 | props.put( Constants.SERVICE_RANKING, new Integer( Integer.MIN_VALUE ) ); |
| 208 | bundleContext.registerService( PersistenceManager.class.getName(), fpm, props ); |
Felix Meschberger | 3f9e4da | 2009-08-17 07:52:39 +0000 | [diff] [blame] | 209 | |
| 210 | // setup dynamic configuration bindings |
| 211 | dynamicBindings = new DynamicBindings( bundleContext, fpm ); |
| 212 | } |
| 213 | catch ( IOException ioe ) |
| 214 | { |
| 215 | log( LogService.LOG_ERROR, "Failure setting up dynamic configuration bindings", ioe ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 216 | } |
| 217 | catch ( IllegalArgumentException iae ) |
| 218 | { |
| 219 | log( LogService.LOG_ERROR, "Cannot create the FilePersistenceManager", iae ); |
| 220 | } |
| 221 | |
| 222 | // register as bundle and service listener |
Felix Meschberger | 2c2a5be | 2009-03-26 16:47:01 +0000 | [diff] [blame] | 223 | handleBundleEvents = true; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 224 | bundleContext.addBundleListener( this ); |
| 225 | |
| 226 | // get all persistence managers to begin with |
Felix Meschberger | 5d3e7ac | 2009-08-14 21:45:10 +0000 | [diff] [blame] | 227 | pmtCount = 1; // make sure to get the persistence managers at least once |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 228 | persistenceManagerTracker = new ServiceTracker( bundleContext, PersistenceManager.class.getName(), null ); |
| 229 | persistenceManagerTracker.open(); |
| 230 | |
| 231 | // create and register configuration admin - start after PM tracker ... |
| 232 | ConfigurationAdminFactory caf = new ConfigurationAdminFactory( this ); |
| 233 | Hashtable props = new Hashtable(); |
| 234 | props.put( Constants.SERVICE_PID, "org.apache.felix.cm.ConfigurationAdmin" ); |
| 235 | props.put( Constants.SERVICE_DESCRIPTION, "Configuration Admin Service Specification 1.2 Implementation" ); |
| 236 | props.put( Constants.SERVICE_VENDOR, "Apache Software Foundation" ); |
Felix Meschberger | db90b1b | 2007-09-06 08:18:10 +0000 | [diff] [blame] | 237 | configurationAdminRegistration = bundleContext.registerService( ConfigurationAdmin.class.getName(), caf, props ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 238 | |
| 239 | // start handling ManagedService[Factory] services |
Carsten Ziegeler | 4168398 | 2007-12-27 08:35:27 +0000 | [diff] [blame] | 240 | managedServiceTracker = new ManagedServiceTracker(this); |
| 241 | managedServiceFactoryTracker = new ManagedServiceFactoryTracker(this); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | |
| 245 | public void stop( BundleContext bundleContext ) |
| 246 | { |
Felix Meschberger | db90b1b | 2007-09-06 08:18:10 +0000 | [diff] [blame] | 247 | |
Felix Meschberger | 5d3e7ac | 2009-08-14 21:45:10 +0000 | [diff] [blame] | 248 | // stop handling bundle events immediately |
| 249 | handleBundleEvents = false; |
| 250 | |
Felix Meschberger | db90b1b | 2007-09-06 08:18:10 +0000 | [diff] [blame] | 251 | // immediately unregister the Configuration Admin before cleaning up |
Felix Meschberger | 1056835 | 2009-01-15 08:57:11 +0000 | [diff] [blame] | 252 | // clearing the field before actually unregistering the service |
| 253 | // prevents IllegalStateException in getServiceReference() if |
| 254 | // the field is not null but the service already unregistered |
| 255 | if (configurationAdminRegistration != null) { |
| 256 | ServiceRegistration reg = configurationAdminRegistration; |
| 257 | configurationAdminRegistration = null; |
| 258 | reg.unregister(); |
| 259 | } |
Felix Meschberger | 2fd5b58 | 2007-12-10 10:32:29 +0000 | [diff] [blame] | 260 | |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 261 | // stop handling ManagedService[Factory] services |
| 262 | managedServiceFactoryTracker.close(); |
| 263 | managedServiceTracker.close(); |
| 264 | |
| 265 | // don't care for PersistenceManagers any more |
| 266 | persistenceManagerTracker.close(); |
| 267 | |
| 268 | // stop listening for events |
| 269 | bundleContext.removeBundleListener( this ); |
| 270 | |
| 271 | if ( configurationListenerTracker != null ) |
| 272 | { |
| 273 | configurationListenerTracker.close(); |
| 274 | } |
| 275 | |
| 276 | if ( updateThread != null ) |
| 277 | { |
| 278 | // terminate asynchrounous updates |
| 279 | updateThread.terminate(); |
| 280 | |
| 281 | // wait for all updates to terminate |
| 282 | try |
| 283 | { |
| 284 | updateThread.join(); |
| 285 | } |
| 286 | catch ( InterruptedException ie ) |
| 287 | { |
| 288 | // don't really care |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | if ( logTracker != null ) |
| 293 | { |
| 294 | logTracker.close(); |
| 295 | } |
| 296 | |
Felix Meschberger | 6a698df | 2009-08-16 18:38:46 +0000 | [diff] [blame] | 297 | // just ensure the configuration cache is empty |
Felix Meschberger | 5d3e7ac | 2009-08-14 21:45:10 +0000 | [diff] [blame] | 298 | synchronized ( configurations ) |
| 299 | { |
| 300 | configurations.clear(); |
| 301 | } |
| 302 | |
Felix Meschberger | 6a698df | 2009-08-16 18:38:46 +0000 | [diff] [blame] | 303 | // just ensure the factory cache is empty |
| 304 | synchronized ( factories ) |
| 305 | { |
| 306 | factories.clear(); |
| 307 | } |
| 308 | |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 309 | this.bundleContext = null; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | |
| 313 | // ---------- Configuration caching support -------------------------------- |
| 314 | |
| 315 | ConfigurationImpl getCachedConfiguration( String pid ) |
| 316 | { |
| 317 | synchronized ( configurations ) |
| 318 | { |
| 319 | return ( ConfigurationImpl ) configurations.get( pid ); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | |
Felix Meschberger | 6a698df | 2009-08-16 18:38:46 +0000 | [diff] [blame] | 324 | ConfigurationImpl[] getCachedConfigurations() |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 325 | { |
| 326 | synchronized ( configurations ) |
| 327 | { |
Felix Meschberger | 6a698df | 2009-08-16 18:38:46 +0000 | [diff] [blame] | 328 | return ( ConfigurationImpl[] ) configurations.values().toArray( |
| 329 | new ConfigurationImpl[configurations.size()] ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 330 | } |
| 331 | } |
| 332 | |
| 333 | |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 334 | ConfigurationImpl cacheConfiguration( ConfigurationImpl configuration ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 335 | { |
| 336 | synchronized ( configurations ) |
| 337 | { |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 338 | Object existing = configurations.get( configuration.getPid() ); |
| 339 | if ( existing != null ) |
| 340 | { |
| 341 | return ( ConfigurationImpl ) existing; |
| 342 | } |
| 343 | |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 344 | configurations.put( configuration.getPid(), configuration ); |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 345 | return configuration; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | |
| 349 | |
| 350 | void removeConfiguration( ConfigurationImpl configuration ) |
| 351 | { |
| 352 | synchronized ( configurations ) |
| 353 | { |
| 354 | configurations.remove( configuration.getPid() ); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | |
Felix Meschberger | 6a698df | 2009-08-16 18:38:46 +0000 | [diff] [blame] | 359 | Factory getCachedFactory( String factoryPid ) |
| 360 | { |
| 361 | synchronized ( factories ) |
| 362 | { |
| 363 | return ( Factory ) factories.get( factoryPid ); |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | |
| 368 | Factory[] getCachedFactories() |
| 369 | { |
| 370 | synchronized ( factories ) |
| 371 | { |
| 372 | return ( Factory[] ) factories.values().toArray( new Factory[factories.size()] ); |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | |
| 377 | void cacheFactory( Factory factory ) |
| 378 | { |
| 379 | synchronized ( factories ) |
| 380 | { |
| 381 | factories.put( factory.getFactoryPid(), factory ); |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | |
Felix Meschberger | 3f9e4da | 2009-08-17 07:52:39 +0000 | [diff] [blame] | 386 | // ---------- ConfigurationAdminImpl support |
Felix Meschberger | 6a698df | 2009-08-16 18:38:46 +0000 | [diff] [blame] | 387 | |
Felix Meschberger | 3f9e4da | 2009-08-17 07:52:39 +0000 | [diff] [blame] | 388 | void setDynamicBundleLocation( final String pid, final String location ) |
| 389 | { |
| 390 | if ( dynamicBindings != null ) |
| 391 | { |
| 392 | try |
| 393 | { |
| 394 | dynamicBindings.putLocation( pid, location ); |
| 395 | } |
| 396 | catch ( IOException ioe ) |
| 397 | { |
| 398 | log( LogService.LOG_ERROR, "Failed storing dynamic configuration binding for " + pid + " to " |
| 399 | + location, ioe ); |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | |
| 405 | String getDynamicBundleLocation( final String pid ) |
| 406 | { |
| 407 | if ( dynamicBindings != null ) |
| 408 | { |
| 409 | return dynamicBindings.getLocation( pid ); |
| 410 | } |
| 411 | |
| 412 | return null; |
| 413 | } |
| 414 | |
| 415 | |
| 416 | // ---------- ConfigurationAdminImpl support |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 417 | |
| 418 | /* |
| 419 | * (non-Javadoc) |
Felix Meschberger | 2fd5b58 | 2007-12-10 10:32:29 +0000 | [diff] [blame] | 420 | * |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 421 | * @see org.osgi.service.cm.ConfigurationAdmin#createFactoryConfiguration(java.lang.String) |
| 422 | */ |
| 423 | ConfigurationImpl createFactoryConfiguration( ConfigurationAdminImpl configurationAdmin, String factoryPid ) |
| 424 | throws IOException |
| 425 | { |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 426 | // check Persmission if factory is bound to another bundle |
Felix Meschberger | fbc7dc1 | 2008-08-06 08:25:58 +0000 | [diff] [blame] | 427 | Factory factory = getFactory( factoryPid ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 428 | if ( factory.getBundleLocation() != null |
| 429 | && !factory.getBundleLocation().equals( configurationAdmin.getBundle().getLocation() ) ) |
| 430 | { |
| 431 | configurationAdmin.checkPermission(); |
| 432 | } |
| 433 | |
| 434 | // create the configuration |
| 435 | String pid = createPid( factoryPid ); |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 436 | ConfigurationImpl config = createConfiguration( pid, factoryPid, configurationAdmin.getBundle().getLocation() ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 437 | |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 438 | return config; |
| 439 | } |
| 440 | |
| 441 | |
| 442 | /* |
| 443 | * (non-Javadoc) |
Felix Meschberger | 2fd5b58 | 2007-12-10 10:32:29 +0000 | [diff] [blame] | 444 | * |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 445 | * @see org.osgi.service.cm.ConfigurationAdmin#createFactoryConfiguration(java.lang.String, |
| 446 | * java.lang.String) |
| 447 | */ |
| 448 | ConfigurationImpl createFactoryConfiguration( String factoryPid, String location ) throws IOException |
| 449 | { |
| 450 | // create the configuration |
| 451 | String pid = createPid( factoryPid ); |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 452 | ConfigurationImpl config = createConfiguration( pid, factoryPid, location ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 453 | |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 454 | return config; |
| 455 | } |
| 456 | |
| 457 | |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 458 | ConfigurationImpl getExistingConfiguration( String pid ) throws IOException |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 459 | { |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 460 | ConfigurationImpl config = getCachedConfiguration( pid ); |
| 461 | if ( config != null ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 462 | { |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 463 | return config; |
| 464 | } |
Felix Meschberger | 2fd5b58 | 2007-12-10 10:32:29 +0000 | [diff] [blame] | 465 | |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 466 | PersistenceManager[] pmList = getPersistenceManagers(); |
| 467 | for ( int i = 0; i < pmList.length; i++ ) |
| 468 | { |
| 469 | if ( pmList[i].exists( pid ) ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 470 | { |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 471 | Dictionary props = pmList[i].load( pid ); |
| 472 | config = new ConfigurationImpl( this, pmList[i], props ); |
| 473 | return cacheConfiguration( config ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 474 | } |
| 475 | } |
Felix Meschberger | 2fd5b58 | 2007-12-10 10:32:29 +0000 | [diff] [blame] | 476 | |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 477 | // neither the cache nor any persistence manager has configuration |
| 478 | return null; |
| 479 | } |
Felix Meschberger | 2fd5b58 | 2007-12-10 10:32:29 +0000 | [diff] [blame] | 480 | |
| 481 | |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 482 | ConfigurationImpl getConfiguration( String pid, String bundleLocation ) throws IOException |
| 483 | { |
| 484 | // check for existing (cached or persistent) configuration |
| 485 | ConfigurationImpl config = getExistingConfiguration( pid ); |
| 486 | if ( config != null ) |
| 487 | { |
| 488 | return config; |
| 489 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 490 | |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 491 | // else create new configuration also setting the bundle location |
Felix Meschberger | fbc7dc1 | 2008-08-06 08:25:58 +0000 | [diff] [blame] | 492 | // and cache the new configuration |
| 493 | config = createConfiguration( pid, null, bundleLocation ); |
| 494 | return cacheConfiguration( config ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | |
| 498 | ConfigurationImpl[] listConfigurations( ConfigurationAdminImpl configurationAdmin, String filterString ) |
| 499 | throws IOException, InvalidSyntaxException |
| 500 | { |
| 501 | Filter filter = null; |
| 502 | if ( filterString != null ) |
| 503 | { |
| 504 | filter = bundleContext.createFilter( filterString ); |
| 505 | } |
| 506 | |
| 507 | boolean unprivileged = configurationAdmin != null && !configurationAdmin.hasPermission(); |
| 508 | String location = unprivileged ? configurationAdmin.getBundle().getLocation() : null; |
| 509 | |
| 510 | List configList = new ArrayList(); |
| 511 | |
| 512 | PersistenceManager[] pmList = getPersistenceManagers(); |
| 513 | for ( int i = 0; i < pmList.length; i++ ) |
| 514 | { |
| 515 | Enumeration configs = pmList[i].getDictionaries(); |
| 516 | while ( configs.hasMoreElements() ) |
| 517 | { |
| 518 | Dictionary config = ( Dictionary ) configs.nextElement(); |
| 519 | |
| 520 | // ignore non-Configuration dictionaries |
Felix Meschberger | 86a0d17 | 2007-07-04 07:15:01 +0000 | [diff] [blame] | 521 | String pid = ( String ) config.get( Constants.SERVICE_PID ); |
| 522 | if ( pid == null ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 523 | { |
| 524 | continue; |
| 525 | } |
| 526 | |
| 527 | // ignore this config if not privileged and not bound to bundle |
| 528 | if ( unprivileged ) |
| 529 | { |
| 530 | Object boundLocation = config.get( ConfigurationAdmin.SERVICE_BUNDLELOCATION ); |
| 531 | if ( !location.equals( boundLocation ) ) |
| 532 | { |
| 533 | continue; |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | // check filter |
| 538 | if ( filter == null || filter.match( config ) ) |
| 539 | { |
Felix Meschberger | 86a0d17 | 2007-07-04 07:15:01 +0000 | [diff] [blame] | 540 | // ensure the service.pid and returned a cached config if available |
| 541 | ConfigurationImpl cfg = getCachedConfiguration( pid ); |
| 542 | if ( cfg == null ) |
| 543 | { |
| 544 | cfg = new ConfigurationImpl( this, pmList[i], config ); |
| 545 | } |
| 546 | |
Felix Meschberger | 0c4e704 | 2008-08-06 07:41:48 +0000 | [diff] [blame] | 547 | // FELIX-611: Ignore configuration objects without props |
| 548 | if ( !cfg.isNew() ) |
| 549 | { |
| 550 | configList.add( cfg ); |
| 551 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 552 | } |
| 553 | } |
| 554 | } |
| 555 | |
Felix Meschberger | 8faceff | 2007-07-04 07:19:48 +0000 | [diff] [blame] | 556 | return ( ConfigurationImpl[] ) configList.toArray( new ConfigurationImpl[configList |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 557 | .size()] ); |
| 558 | } |
| 559 | |
| 560 | |
Felix Meschberger | cefe5eb | 2009-08-19 12:37:32 +0000 | [diff] [blame^] | 561 | void deleted( ConfigurationImpl config ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 562 | { |
| 563 | // remove the configuration from the cache |
| 564 | removeConfiguration( config ); |
Felix Meschberger | cefe5eb | 2009-08-19 12:37:32 +0000 | [diff] [blame^] | 565 | updateThread.schedule( new DeleteConfiguration( config, true ) ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | |
Felix Meschberger | cefe5eb | 2009-08-19 12:37:32 +0000 | [diff] [blame^] | 569 | void updated( ConfigurationImpl config ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 570 | { |
Felix Meschberger | cefe5eb | 2009-08-19 12:37:32 +0000 | [diff] [blame^] | 571 | updateThread.schedule( new UpdateConfiguration( config, true ) ); |
| 572 | } |
| 573 | |
| 574 | |
| 575 | void revokeConfiguration( ConfigurationImpl config ) |
| 576 | { |
| 577 | updateThread.schedule( new DeleteConfiguration( config, false ) ); |
| 578 | |
| 579 | // immediately unbind the configuration |
| 580 | config.setDynamicBundleLocation( null ); |
| 581 | config.setServiceReference( null ); |
| 582 | } |
| 583 | |
| 584 | |
| 585 | void reassignConfiguration( ConfigurationImpl config ) |
| 586 | { |
| 587 | updateThread.schedule( new UpdateConfiguration( config, false ) ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | |
Felix Meschberger | 6642333 | 2007-08-22 08:46:34 +0000 | [diff] [blame] | 591 | void fireConfigurationEvent( int type, String pid, String factoryPid ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 592 | { |
| 593 | |
Felix Meschberger | 6642333 | 2007-08-22 08:46:34 +0000 | [diff] [blame] | 594 | updateThread.schedule( new FireConfigurationEvent( type, pid, factoryPid) ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | |
| 598 | // ---------- BundleListener ----------------------------------------------- |
| 599 | |
| 600 | public void bundleChanged( BundleEvent event ) |
| 601 | { |
Felix Meschberger | 2c2a5be | 2009-03-26 16:47:01 +0000 | [diff] [blame] | 602 | if ( event.getType() == BundleEvent.UNINSTALLED && handleBundleEvents ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 603 | { |
Felix Meschberger | 6a698df | 2009-08-16 18:38:46 +0000 | [diff] [blame] | 604 | final String location = event.getBundle().getLocation(); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 605 | |
Felix Meschberger | 6a698df | 2009-08-16 18:38:46 +0000 | [diff] [blame] | 606 | // we only reset dynamic bindings, which are only present in |
| 607 | // cached configurations, hence only consider cached configs here |
| 608 | final ConfigurationImpl[] configs = getCachedConfigurations(); |
| 609 | for ( int i = 0; i < configs.length; i++ ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 610 | { |
Felix Meschberger | 6a698df | 2009-08-16 18:38:46 +0000 | [diff] [blame] | 611 | final ConfigurationImpl cfg = configs[i]; |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 612 | if ( location.equals( cfg.getDynamicBundleLocation() ) ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 613 | { |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 614 | cfg.setDynamicBundleLocation( null ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 615 | } |
| 616 | } |
Felix Meschberger | 6a698df | 2009-08-16 18:38:46 +0000 | [diff] [blame] | 617 | |
| 618 | // we only reset dynamic bindings, which are only present in |
| 619 | // cached factories, hence only consider cached factories here |
| 620 | final Factory[] factories = getCachedFactories(); |
| 621 | for ( int i = 0; i < factories.length; i++ ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 622 | { |
Felix Meschberger | 6a698df | 2009-08-16 18:38:46 +0000 | [diff] [blame] | 623 | final Factory factory = factories[i]; |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 624 | if ( location.equals( factory.getDynamicBundleLocation() ) ) |
Felix Meschberger | 6a698df | 2009-08-16 18:38:46 +0000 | [diff] [blame] | 625 | { |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 626 | factory.setDynamicBundleLocation( null ); |
Felix Meschberger | 6a698df | 2009-08-16 18:38:46 +0000 | [diff] [blame] | 627 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 628 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 629 | } |
| 630 | } |
| 631 | |
| 632 | |
| 633 | // ---------- internal ----------------------------------------------------- |
| 634 | |
| 635 | private PersistenceManager[] getPersistenceManagers() |
| 636 | { |
Felix Meschberger | d71f410 | 2007-07-06 15:34:32 +0000 | [diff] [blame] | 637 | int currentPmtCount = persistenceManagerTracker.getTrackingCount(); |
| 638 | if ( persistenceManagers == null || currentPmtCount > pmtCount ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 639 | { |
| 640 | |
Felix Meschberger | df26ae8 | 2009-08-14 19:50:43 +0000 | [diff] [blame] | 641 | List pmList = new ArrayList(); |
Felix Meschberger | d71f410 | 2007-07-06 15:34:32 +0000 | [diff] [blame] | 642 | PersistenceManager[] pm; |
| 643 | |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 644 | ServiceReference[] refs = persistenceManagerTracker.getServiceReferences(); |
| 645 | if ( refs == null || refs.length == 0 ) |
| 646 | { |
Felix Meschberger | d71f410 | 2007-07-06 15:34:32 +0000 | [diff] [blame] | 647 | pm = new PersistenceManager[0]; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 648 | } |
Felix Meschberger | d71f410 | 2007-07-06 15:34:32 +0000 | [diff] [blame] | 649 | else |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 650 | { |
Felix Meschberger | d71f410 | 2007-07-06 15:34:32 +0000 | [diff] [blame] | 651 | // sort the references according to the cmRanking property |
| 652 | SortedSet pms = new TreeSet( new RankingComparator( false ) ); |
| 653 | for ( int i = 0; i < refs.length; i++ ) |
| 654 | { |
| 655 | pms.add( refs[i] ); |
| 656 | } |
| 657 | |
| 658 | // create the service array from the sorted set of referenecs |
Felix Meschberger | d71f410 | 2007-07-06 15:34:32 +0000 | [diff] [blame] | 659 | int pmIndex = 0; |
Felix Meschberger | df26ae8 | 2009-08-14 19:50:43 +0000 | [diff] [blame] | 660 | for ( Iterator pi = pms.iterator(); pi.hasNext(); pmIndex++ ) |
Felix Meschberger | d71f410 | 2007-07-06 15:34:32 +0000 | [diff] [blame] | 661 | { |
| 662 | ServiceReference ref = ( ServiceReference ) pi.next(); |
Felix Meschberger | df26ae8 | 2009-08-14 19:50:43 +0000 | [diff] [blame] | 663 | Object service = persistenceManagerTracker.getService( ref ); |
| 664 | if ( service != null ) |
| 665 | { |
| 666 | pmList.add( service ); |
| 667 | } |
Felix Meschberger | d71f410 | 2007-07-06 15:34:32 +0000 | [diff] [blame] | 668 | } |
Felix Meschberger | df26ae8 | 2009-08-14 19:50:43 +0000 | [diff] [blame] | 669 | |
| 670 | pm = ( PersistenceManager[] ) pmList.toArray( new PersistenceManager[pmList.size()] ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 671 | } |
| 672 | |
Felix Meschberger | df26ae8 | 2009-08-14 19:50:43 +0000 | [diff] [blame] | 673 | pmtCount = pm.length; |
Felix Meschberger | d71f410 | 2007-07-06 15:34:32 +0000 | [diff] [blame] | 674 | persistenceManagers = pm; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | return persistenceManagers; |
| 678 | } |
| 679 | |
| 680 | |
Felix Meschberger | b4f83e4 | 2009-01-15 08:53:36 +0000 | [diff] [blame] | 681 | private ServiceReference getServiceReference() |
| 682 | { |
| 683 | ServiceRegistration reg = configurationAdminRegistration; |
| 684 | return ( reg != null ) ? reg.getReference() : null; |
| 685 | } |
| 686 | |
| 687 | |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 688 | private void configure( ServiceReference sr, ManagedService service ) |
| 689 | { |
Felix Meschberger | 851c641 | 2009-08-16 18:43:26 +0000 | [diff] [blame] | 690 | String[] pids = getServicePid( sr ); |
| 691 | if ( pids != null ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 692 | { |
Felix Meschberger | 851c641 | 2009-08-16 18:43:26 +0000 | [diff] [blame] | 693 | for ( int i = 0; i < pids.length; i++ ) |
| 694 | { |
| 695 | ManagedServiceUpdate update = new ManagedServiceUpdate( pids[i], sr, service ); |
Felix Meschberger | 6a698df | 2009-08-16 18:38:46 +0000 | [diff] [blame] | 696 | updateThread.schedule( update ); |
| 697 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 698 | } |
Felix Meschberger | 851c641 | 2009-08-16 18:43:26 +0000 | [diff] [blame] | 699 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 700 | |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 701 | |
| 702 | private void configure( ServiceReference sr, ManagedServiceFactory service ) |
| 703 | { |
Felix Meschberger | 851c641 | 2009-08-16 18:43:26 +0000 | [diff] [blame] | 704 | String[] pids = getServicePid( sr ); |
| 705 | if ( pids != null ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 706 | { |
Felix Meschberger | 851c641 | 2009-08-16 18:43:26 +0000 | [diff] [blame] | 707 | for ( int i = 0; i < pids.length; i++ ) |
| 708 | { |
| 709 | ManagedServiceFactoryUpdate update = new ManagedServiceFactoryUpdate( pids[i], sr, service ); |
Felix Meschberger | 6a698df | 2009-08-16 18:38:46 +0000 | [diff] [blame] | 710 | updateThread.schedule( update ); |
| 711 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 712 | } |
Felix Meschberger | 851c641 | 2009-08-16 18:43:26 +0000 | [diff] [blame] | 713 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 714 | |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 715 | |
Felix Meschberger | fbc7dc1 | 2008-08-06 08:25:58 +0000 | [diff] [blame] | 716 | /** |
| 717 | * Factory method to create a new configuration object. The configuration |
| 718 | * object returned is not stored in configuration cache and only persisted |
| 719 | * if the <code>factoryPid</code> parameter is <code>null</code>. |
Felix Meschberger | 5dfaa96 | 2009-08-14 19:26:01 +0000 | [diff] [blame] | 720 | * |
Felix Meschberger | fbc7dc1 | 2008-08-06 08:25:58 +0000 | [diff] [blame] | 721 | * @param pid |
| 722 | * The PID of the new configuration object. Must not be |
| 723 | * <code>null</code>. |
| 724 | * @param factoryPid |
| 725 | * The factory PID of the new configuration. Not |
Felix Meschberger | 6a698df | 2009-08-16 18:38:46 +0000 | [diff] [blame] | 726 | * <code>null</code> if the new configuration object belongs to a |
| 727 | * factory. The configuration object will not be persisted if |
Felix Meschberger | fbc7dc1 | 2008-08-06 08:25:58 +0000 | [diff] [blame] | 728 | * this parameter is not <code>null</code>. |
| 729 | * @param bundleLocation |
| 730 | * The bundle location of the bundle to which the configuration |
Felix Meschberger | 6a698df | 2009-08-16 18:38:46 +0000 | [diff] [blame] | 731 | * belongs or <code>null</code> if the configuration is not bound |
| 732 | * yet. |
Felix Meschberger | fbc7dc1 | 2008-08-06 08:25:58 +0000 | [diff] [blame] | 733 | * @return The new configuration object |
| 734 | * @throws IOException |
| 735 | * May be thrown if an error occurrs persisting the new |
| 736 | * configuration object. |
| 737 | */ |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 738 | ConfigurationImpl createConfiguration( String pid, String factoryPid, String bundleLocation ) throws IOException |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 739 | { |
Felix Meschberger | fbc7dc1 | 2008-08-06 08:25:58 +0000 | [diff] [blame] | 740 | return new ConfigurationImpl( this, getPersistenceManagers()[0], pid, factoryPid, bundleLocation ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | |
| 744 | Factory getFactory( String factoryPid ) throws IOException |
| 745 | { |
Felix Meschberger | f463132 | 2008-03-10 12:32:35 +0000 | [diff] [blame] | 746 | Factory factory = getCachedFactory( factoryPid ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 747 | if ( factory != null ) |
| 748 | { |
| 749 | return factory; |
| 750 | } |
| 751 | |
| 752 | PersistenceManager[] pmList = getPersistenceManagers(); |
| 753 | for ( int i = 0; i < pmList.length; i++ ) |
| 754 | { |
| 755 | if ( Factory.exists( pmList[i], factoryPid ) ) |
| 756 | { |
Felix Meschberger | 3f9e4da | 2009-08-17 07:52:39 +0000 | [diff] [blame] | 757 | factory = Factory.load( this, pmList[i], factoryPid ); |
Felix Meschberger | f463132 | 2008-03-10 12:32:35 +0000 | [diff] [blame] | 758 | cacheFactory( factory ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 759 | return factory; |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | // if getting here, there is no configuration yet, optionally create new |
| 764 | return createFactory( factoryPid ); |
| 765 | } |
| 766 | |
| 767 | |
| 768 | Factory createFactory( String factoryPid ) |
| 769 | { |
Felix Meschberger | 3f9e4da | 2009-08-17 07:52:39 +0000 | [diff] [blame] | 770 | Factory factory = new Factory( this, getPersistenceManagers()[0], factoryPid ); |
Felix Meschberger | f463132 | 2008-03-10 12:32:35 +0000 | [diff] [blame] | 771 | cacheFactory( factory ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 772 | return factory; |
| 773 | } |
| 774 | |
| 775 | |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 776 | /** |
| 777 | * Calls the registered configuration plugins on the given configuration |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 778 | * properties from the given configuration object unless the configuration |
| 779 | * has just been created and not been updated yet. |
Felix Meschberger | 2fd5b58 | 2007-12-10 10:32:29 +0000 | [diff] [blame] | 780 | * |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 781 | * @param props The configuraiton properties run through the registered |
| 782 | * ConfigurationPlugin services. This may be <code>null</code> |
| 783 | * in which case this method just immediately returns. |
Felix Meschberger | 5dfaa96 | 2009-08-14 19:26:01 +0000 | [diff] [blame] | 784 | * @param targetPid The identification of the configuration update used to |
| 785 | * select the plugins according to their cm.target service |
| 786 | * property |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 787 | * @param sr The service reference of the managed service (factory) which |
Felix Meschberger | 5dfaa96 | 2009-08-14 19:26:01 +0000 | [diff] [blame] | 788 | * is to be updated with configuration |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 789 | * @param cfg The configuration object whose properties have to be passed |
Felix Meschberger | 5dfaa96 | 2009-08-14 19:26:01 +0000 | [diff] [blame] | 790 | * through the plugins |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 791 | */ |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 792 | private void callPlugins( final Dictionary props, final String targetPid, final ServiceReference sr, |
| 793 | final ConfigurationImpl cfg ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 794 | { |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 795 | // guard against NPE for new configuration never updated |
| 796 | if (props == null) { |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 797 | return; |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 798 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 799 | |
| 800 | ServiceReference[] plugins = null; |
| 801 | try |
| 802 | { |
Felix Meschberger | 5dfaa96 | 2009-08-14 19:26:01 +0000 | [diff] [blame] | 803 | String filter = "(|(!(cm.target=*))(cm.target=" + targetPid + "))"; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 804 | plugins = bundleContext.getServiceReferences( ConfigurationPlugin.class.getName(), filter ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 805 | } |
| 806 | catch ( InvalidSyntaxException ise ) |
| 807 | { |
| 808 | // no filter, no exception ... |
| 809 | } |
| 810 | |
| 811 | // abort early if there are no plugins |
| 812 | if ( plugins == null || plugins.length == 0 ) |
| 813 | { |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 814 | return; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | // sort the plugins by their service.cmRanking |
| 818 | SortedSet pluginSet = new TreeSet( cmRankComp ); |
Carsten Ziegeler | 7853b9a | 2008-01-11 16:30:24 +0000 | [diff] [blame] | 819 | for ( int i = 0; i < plugins.length; i++ ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 820 | { |
| 821 | pluginSet.add( plugins[i] ); |
| 822 | } |
| 823 | |
| 824 | // call the plugins in order |
| 825 | for ( Iterator pi = pluginSet.iterator(); pi.hasNext(); ) |
| 826 | { |
| 827 | ServiceReference pluginRef = ( ServiceReference ) pi.next(); |
| 828 | ConfigurationPlugin plugin = ( ConfigurationPlugin ) bundleContext.getService( pluginRef ); |
| 829 | try |
| 830 | { |
| 831 | plugin.modifyConfiguration( sr, props ); |
| 832 | } |
| 833 | catch ( Throwable t ) |
| 834 | { |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 835 | log( LogService.LOG_ERROR, "Unexpected problem calling configuration plugin " + toString( pluginRef ), |
| 836 | t ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 837 | } |
| 838 | finally |
| 839 | { |
| 840 | // ensure ungetting the plugin |
| 841 | bundleContext.ungetService( pluginRef ); |
| 842 | } |
| 843 | cfg.setAutoProperties( props, false ); |
| 844 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | |
| 848 | /** |
| 849 | * Creates a PID for the given factoryPid |
Felix Meschberger | 2fd5b58 | 2007-12-10 10:32:29 +0000 | [diff] [blame] | 850 | * |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 851 | * @param factoryPid |
| 852 | * @return |
| 853 | */ |
| 854 | private static String createPid( String factoryPid ) |
| 855 | { |
| 856 | SecureRandom ng = numberGenerator; |
| 857 | if ( ng == null ) |
| 858 | { |
| 859 | numberGenerator = ng = new SecureRandom(); |
| 860 | } |
| 861 | |
| 862 | byte[] randomBytes = new byte[16]; |
| 863 | ng.nextBytes( randomBytes ); |
| 864 | randomBytes[6] &= 0x0f; /* clear version */ |
| 865 | randomBytes[6] |= 0x40; /* set to version 4 */ |
| 866 | randomBytes[8] &= 0x3f; /* clear variant */ |
| 867 | randomBytes[8] |= 0x80; /* set to IETF variant */ |
| 868 | |
| 869 | StringBuffer buf = new StringBuffer( factoryPid.length() + 1 + 36 ); |
| 870 | |
| 871 | // prefix the new pid with the factory pid |
| 872 | buf.append( factoryPid ).append( "." ); |
| 873 | |
| 874 | // serialize the UUID into the buffer |
| 875 | for ( int i = 0; i < randomBytes.length; i++ ) |
| 876 | { |
| 877 | |
| 878 | if ( i == 4 || i == 6 || i == 8 || i == 10 ) |
| 879 | { |
| 880 | buf.append( '-' ); |
| 881 | } |
| 882 | |
| 883 | int val = randomBytes[i] & 0xff; |
| 884 | buf.append( Integer.toHexString( val >> 4 ) ); |
| 885 | buf.append( Integer.toHexString( val & 0xf ) ); |
| 886 | } |
| 887 | |
| 888 | return buf.toString(); |
| 889 | } |
| 890 | |
| 891 | |
| 892 | void log( int level, String message, Throwable t ) |
| 893 | { |
Felix Meschberger | 08282c3 | 2009-01-28 07:01:55 +0000 | [diff] [blame] | 894 | // log using the LogService if available |
Felix Meschberger | 85b355d | 2007-08-31 07:17:38 +0000 | [diff] [blame] | 895 | Object log = logTracker.getService(); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 896 | if ( log != null ) |
| 897 | { |
Felix Meschberger | b4f83e4 | 2009-01-15 08:53:36 +0000 | [diff] [blame] | 898 | ( ( LogService ) log ).log( getServiceReference(), level, message, t ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 899 | return; |
| 900 | } |
| 901 | |
Felix Meschberger | 08282c3 | 2009-01-28 07:01:55 +0000 | [diff] [blame] | 902 | // Otherwise only log if more serious than the configured level |
| 903 | if ( level <= logLevel ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 904 | { |
Felix Meschberger | 08282c3 | 2009-01-28 07:01:55 +0000 | [diff] [blame] | 905 | String code; |
| 906 | switch ( level ) |
| 907 | { |
| 908 | case LogService.LOG_INFO: |
| 909 | code = "*INFO *"; |
| 910 | break; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 911 | |
Felix Meschberger | 08282c3 | 2009-01-28 07:01:55 +0000 | [diff] [blame] | 912 | case LogService.LOG_WARNING: |
| 913 | code = "*WARN *"; |
| 914 | break; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 915 | |
Felix Meschberger | 08282c3 | 2009-01-28 07:01:55 +0000 | [diff] [blame] | 916 | case LogService.LOG_ERROR: |
| 917 | code = "*ERROR*"; |
| 918 | break; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 919 | |
Felix Meschberger | 08282c3 | 2009-01-28 07:01:55 +0000 | [diff] [blame] | 920 | case LogService.LOG_DEBUG: |
| 921 | default: |
| 922 | code = "*DEBUG*"; |
| 923 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 924 | |
Felix Meschberger | 08282c3 | 2009-01-28 07:01:55 +0000 | [diff] [blame] | 925 | System.err.println( code + " " + message ); |
| 926 | if ( t != null ) |
| 927 | { |
| 928 | t.printStackTrace( System.err ); |
| 929 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 930 | } |
| 931 | } |
| 932 | |
Felix Meschberger | 851c641 | 2009-08-16 18:43:26 +0000 | [diff] [blame] | 933 | |
| 934 | /** |
| 935 | * Returns the <code>service.pid</code> property of the service reference as |
| 936 | * an array of strings or <code>null</code> if the service reference does |
| 937 | * not have a service PID property. |
| 938 | * <p> |
| 939 | * The service.pid property may be a single string, in which case a single |
| 940 | * element array is returned. If the property is an array of string, this |
| 941 | * array is returned. If the property is a collection it is assumed to be a |
| 942 | * collection of strings and the collection is converted to an array to be |
| 943 | * returned. Otherwise (also if the property is not set) <code>null</code> |
| 944 | * is returned. |
| 945 | * |
| 946 | * @throws NullPointerException |
| 947 | * if reference is <code>null</code> |
| 948 | * @throws ArrayStoreException |
| 949 | * if the service pid is a collection and not all elements are |
| 950 | * strings. |
| 951 | */ |
| 952 | static String[] getServicePid( ServiceReference reference ) |
| 953 | { |
| 954 | Object pidObj = reference.getProperty( Constants.SERVICE_PID ); |
| 955 | if ( pidObj instanceof String ) |
| 956 | { |
| 957 | return new String[] |
| 958 | { ( String ) pidObj }; |
| 959 | } |
| 960 | else if ( pidObj instanceof String[] ) |
| 961 | { |
| 962 | return ( String[] ) pidObj; |
| 963 | } |
| 964 | else if ( pidObj instanceof Collection ) |
| 965 | { |
| 966 | Collection pidCollection = ( Collection ) pidObj; |
| 967 | return ( String[] ) pidCollection.toArray( new String[pidCollection.size()] ); |
| 968 | } |
| 969 | |
| 970 | return null; |
| 971 | } |
| 972 | |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 973 | |
| 974 | static String toString( ServiceReference ref ) |
| 975 | { |
| 976 | String[] ocs = ( String[] ) ref.getProperty( "objectClass" ); |
| 977 | String oc = "["; |
| 978 | for ( int i = 0; i < ocs.length; i++ ) |
| 979 | { |
| 980 | oc += ocs[i]; |
| 981 | if ( i < ocs.length - 1 ) |
| 982 | oc += ", "; |
| 983 | } |
| 984 | |
| 985 | oc += ", id=" + ref.getProperty( Constants.SERVICE_ID ); |
| 986 | oc += ", bundle=" + ref.getBundle().getBundleId(); |
| 987 | oc += "]"; |
| 988 | return oc; |
| 989 | } |
| 990 | |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 991 | // ---------- inner classes ------------------------------------------------ |
| 992 | |
| 993 | private class ManagedServiceUpdate implements Runnable |
| 994 | { |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 995 | private final String pid; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 996 | |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 997 | private final ServiceReference sr; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 998 | |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 999 | private final ManagedService service; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1000 | |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1001 | private final ConfigurationImpl config; |
| 1002 | |
| 1003 | private final Dictionary rawProperties; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1004 | |
| 1005 | ManagedServiceUpdate( String pid, ServiceReference sr, ManagedService service ) |
| 1006 | { |
| 1007 | this.pid = pid; |
| 1008 | this.sr = sr; |
| 1009 | this.service = service; |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1010 | |
| 1011 | // get or load configuration for the pid |
| 1012 | ConfigurationImpl config = null; |
| 1013 | Dictionary rawProperties = null; |
| 1014 | try |
| 1015 | { |
| 1016 | config = getExistingConfiguration( pid ); |
| 1017 | if (config != null) { |
| 1018 | rawProperties = config.getProperties( true ); |
| 1019 | } |
| 1020 | } |
| 1021 | catch ( IOException ioe ) |
| 1022 | { |
| 1023 | log( LogService.LOG_ERROR, "Error loading configuration for " + pid, ioe ); |
| 1024 | } |
| 1025 | |
| 1026 | this.config = config; |
| 1027 | this.rawProperties = rawProperties; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | |
| 1031 | public void run() |
| 1032 | { |
Felix Meschberger | 56e2b7e | 2009-08-16 18:49:58 +0000 | [diff] [blame] | 1033 | // check configuration and call plugins if existing |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1034 | Dictionary properties = rawProperties; |
| 1035 | if ( config != null ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1036 | { |
Felix Meschberger | 4124319 | 2009-01-14 19:59:58 +0000 | [diff] [blame] | 1037 | Bundle serviceBundle = sr.getBundle(); |
| 1038 | if ( serviceBundle == null ) |
| 1039 | { |
| 1040 | log( LogService.LOG_INFO, "ServiceFactory for PID " + pid |
| 1041 | + " seems to already have been unregistered, not updating with configuration", null ); |
| 1042 | return; |
| 1043 | } |
| 1044 | |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 1045 | // 104.3 Ignore duplicate PIDs from other bundles and report |
| 1046 | // them to the log |
| 1047 | // 104.4.1 No update call back for PID already bound to another |
| 1048 | // bundle location |
| 1049 | // 104.4.1 assign configuration to bundle if unassigned |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1050 | if ( !config.tryBindLocation( serviceBundle.getLocation() ) ) |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 1051 | { |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1052 | log( LogService.LOG_ERROR, "Cannot use configuration " + pid + " for " |
| 1053 | + ConfigurationManager.toString( sr ) + ": Configuration bound to bundle " |
| 1054 | + config.getBundleLocation(), null ); |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 1055 | return; |
| 1056 | } |
| 1057 | |
| 1058 | // 104.3 Report an error in the log if more than one service |
Felix Meschberger | 5d3e7ac | 2009-08-14 21:45:10 +0000 | [diff] [blame] | 1059 | // with the same PID asks for the configuration |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1060 | if ( config.getServiceReference() == null ) |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 1061 | { |
| 1062 | // assign the configuration to the service |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1063 | config.setServiceReference( sr ); |
| 1064 | } |
| 1065 | else if ( !sr.equals( config.getServiceReference() ) ) |
| 1066 | { |
| 1067 | log( LogService.LOG_ERROR, "Configuration for " + pid + " has already been used for service " |
| 1068 | + ConfigurationManager.toString( config.getServiceReference() ) |
| 1069 | + " and will now also be given to " + ConfigurationManager.toString( sr ), null ); |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | // prepare the configuration for the service (call plugins) |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1073 | callPlugins( properties, pid, sr, config ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1074 | } |
| 1075 | else |
| 1076 | { |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 1077 | // 104.5.3 ManagedService.updated must be called with null |
| 1078 | // if no configuration is available |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1079 | properties = null; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1080 | } |
| 1081 | |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1082 | // update the service with the configuration |
| 1083 | try |
| 1084 | { |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1085 | service.updated( properties ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1086 | } |
| 1087 | catch ( ConfigurationException ce ) |
| 1088 | { |
| 1089 | if ( ce.getProperty() != null ) |
| 1090 | { |
| 1091 | log( LogService.LOG_ERROR, sr + ": Updating configuration property " + ce.getProperty() |
| 1092 | + " caused a problem: " + ce.getReason(), ce ); |
| 1093 | } |
| 1094 | else |
| 1095 | { |
| 1096 | log( LogService.LOG_ERROR, sr + ": Updating configuration caused a problem: " + ce.getReason(), ce ); |
| 1097 | |
| 1098 | } |
| 1099 | } |
| 1100 | catch ( Throwable t ) |
| 1101 | { |
| 1102 | log( LogService.LOG_ERROR, sr + ": Unexpected problem updating configuration", t ); |
| 1103 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1104 | } |
Felix Meschberger | 5dfaa96 | 2009-08-14 19:26:01 +0000 | [diff] [blame] | 1105 | |
Felix Meschberger | 432e387 | 2008-03-07 14:58:57 +0000 | [diff] [blame] | 1106 | public String toString() |
| 1107 | { |
| 1108 | return "ManagedService Update: pid=" + pid; |
| 1109 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | private class ManagedServiceFactoryUpdate implements Runnable |
| 1113 | { |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1114 | private final String factoryPid; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1115 | |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1116 | private final ServiceReference sr; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1117 | |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1118 | private final ManagedServiceFactory service; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1119 | |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1120 | private final Factory factory; |
| 1121 | |
| 1122 | private final Map configs; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1123 | |
| 1124 | ManagedServiceFactoryUpdate( String factoryPid, ServiceReference sr, ManagedServiceFactory service ) |
| 1125 | { |
| 1126 | this.factoryPid = factoryPid; |
| 1127 | this.sr = sr; |
| 1128 | this.service = service; |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1129 | |
| 1130 | Factory factory = null; |
| 1131 | Map configs = null; |
| 1132 | try |
| 1133 | { |
| 1134 | factory = getFactory( factoryPid ); |
| 1135 | if (factory != null) { |
| 1136 | configs = new HashMap(); |
| 1137 | for ( Iterator pi = factory.getPIDs().iterator(); pi.hasNext(); ) |
| 1138 | { |
| 1139 | final String pid = ( String ) pi.next(); |
| 1140 | ConfigurationImpl cfg; |
| 1141 | try |
| 1142 | { |
| 1143 | cfg = getExistingConfiguration( pid ); |
| 1144 | } |
| 1145 | catch ( IOException ioe ) |
| 1146 | { |
| 1147 | log( LogService.LOG_ERROR, "Error loading configuration for " + pid, ioe ); |
| 1148 | continue; |
| 1149 | } |
| 1150 | |
| 1151 | // sanity check on the configuration |
| 1152 | if ( cfg == null ) |
| 1153 | { |
| 1154 | log( LogService.LOG_ERROR, "Configuration " + pid + " referred to by factory " + factoryPid |
| 1155 | + " does not exist", null ); |
| 1156 | factory.removePID( pid ); |
| 1157 | factory.storeSilently(); |
| 1158 | continue; |
| 1159 | } |
| 1160 | else if ( cfg.isNew() ) |
| 1161 | { |
| 1162 | // Configuration has just been created but not yet updated |
| 1163 | // we currently just ignore it and have the update mechanism |
| 1164 | // provide the configuration to the ManagedServiceFactory |
| 1165 | // As of FELIX-612 (not storing new factory configurations) |
| 1166 | // this should not happen. We keep this for added stability |
| 1167 | // but raise the logging level to error. |
| 1168 | log( LogService.LOG_ERROR, "Ignoring new configuration pid=" + pid, null ); |
| 1169 | continue; |
| 1170 | } |
| 1171 | else if ( !factoryPid.equals( cfg.getFactoryPid() ) ) |
| 1172 | { |
| 1173 | log( LogService.LOG_ERROR, "Configuration " + pid + " referred to by factory " + factoryPid |
| 1174 | + " seems to belong to factory " + cfg.getFactoryPid(), null ); |
| 1175 | factory.removePID( pid ); |
| 1176 | factory.storeSilently(); |
| 1177 | continue; |
| 1178 | } |
| 1179 | |
| 1180 | // get the configuration properties for later |
| 1181 | configs.put(cfg, cfg.getProperties( true )); |
| 1182 | } |
| 1183 | } |
| 1184 | } |
| 1185 | catch ( IOException ioe ) |
| 1186 | { |
| 1187 | log( LogService.LOG_ERROR, "Cannot get factory mapping for factory PID " + factoryPid, ioe ); |
| 1188 | } |
| 1189 | |
| 1190 | this.factory = factory; |
| 1191 | this.configs = configs; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | |
| 1195 | public void run() |
| 1196 | { |
Felix Meschberger | 4124319 | 2009-01-14 19:59:58 +0000 | [diff] [blame] | 1197 | Bundle serviceBundle = sr.getBundle(); |
| 1198 | if ( serviceBundle == null ) |
| 1199 | { |
| 1200 | log( LogService.LOG_INFO, "ManagedServiceFactory for factory PID " + factoryPid |
| 1201 | + " seems to already have been unregistered, not updating with factory", null ); |
| 1202 | return; |
| 1203 | } |
| 1204 | |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1205 | final String serviceBundleLocation = serviceBundle.getLocation(); |
| 1206 | if ( !factory.tryBindLocation( serviceBundleLocation ) ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1207 | { |
| 1208 | // factory PID is bound to another bundle |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1209 | log( LogService.LOG_ERROR, "Cannot use factory configuration " + factoryPid + " for " |
| 1210 | + ConfigurationManager.toString( sr ) + ": Configuration bound to bundle " |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1211 | + factory.getBundleLocation(), null ); |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1212 | |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1213 | return; |
| 1214 | } |
| 1215 | |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1216 | for ( Iterator ci=configs.entrySet().iterator(); ci.hasNext(); ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1217 | { |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1218 | final Map.Entry entry = (Map.Entry) ci.next(); |
| 1219 | final ConfigurationImpl cfg = (ConfigurationImpl) entry.getKey(); |
| 1220 | final Dictionary properties = (Dictionary) entry.getValue(); |
Felix Meschberger | 5dfaa96 | 2009-08-14 19:26:01 +0000 | [diff] [blame] | 1221 | |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1222 | // check bundle location of configuration |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1223 | if ( !cfg.tryBindLocation( serviceBundleLocation ) ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1224 | { |
| 1225 | // configuration is bound to another bundle |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1226 | log( LogService.LOG_ERROR, "Cannot use configuration " + cfg.getPid() + " (factory " + factoryPid |
| 1227 | + ") for " + ConfigurationManager.toString( sr ) + ": Configuration bound to bundle " |
| 1228 | + cfg.getBundleLocation(), null ); |
| 1229 | |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1230 | continue; |
| 1231 | } |
| 1232 | |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1233 | // 104.3 Report an error in the log if more than one service |
| 1234 | // with the same PID asks for the configuration |
| 1235 | if ( cfg.getServiceReference() == null ) |
| 1236 | { |
| 1237 | // assign the configuration to the service |
| 1238 | cfg.setServiceReference( sr ); |
| 1239 | } |
| 1240 | else if ( !sr.equals( cfg.getServiceReference() ) ) |
| 1241 | { |
| 1242 | log( LogService.LOG_ERROR, "Configuration for " + cfg.getPid() + " (factory " + factoryPid |
| 1243 | + ") has already been used for service " |
| 1244 | + ConfigurationManager.toString( cfg.getServiceReference() ) |
| 1245 | + " and will now also be given to " + ConfigurationManager.toString( sr ), null ); |
| 1246 | } |
| 1247 | |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1248 | // prepare the configuration for the service (call plugins) |
Felix Meschberger | 5dfaa96 | 2009-08-14 19:26:01 +0000 | [diff] [blame] | 1249 | // call the plugins with cm.target set to the service's factory PID |
| 1250 | // (clarification in Section 104.9.1 of Compendium 4.2) |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1251 | callPlugins( properties, factoryPid, sr, cfg ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1252 | |
| 1253 | // update the service with the configuration |
| 1254 | try |
| 1255 | { |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 1256 | // only, if there is non-null configuration data |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1257 | if ( properties != null ) |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 1258 | { |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1259 | log( LogService.LOG_DEBUG, sr + ": Updating configuration pid=" + cfg.getPid(), null ); |
| 1260 | service.updated( cfg.getPid(), properties ); |
Felix Meschberger | 2941ef9 | 2007-08-20 13:15:16 +0000 | [diff] [blame] | 1261 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1262 | } |
| 1263 | catch ( ConfigurationException ce ) |
| 1264 | { |
| 1265 | if ( ce.getProperty() != null ) |
| 1266 | { |
| 1267 | log( LogService.LOG_ERROR, sr + ": Updating configuration property " + ce.getProperty() |
| 1268 | + " caused a problem: " + ce.getReason(), ce ); |
| 1269 | } |
| 1270 | else |
| 1271 | { |
| 1272 | log( LogService.LOG_ERROR, sr + ": Updating configuration caused a problem: " + ce.getReason(), |
| 1273 | ce ); |
| 1274 | |
| 1275 | } |
| 1276 | } |
| 1277 | catch ( Throwable t ) |
| 1278 | { |
| 1279 | log( LogService.LOG_ERROR, sr + ": Unexpected problem updating configuration", t ); |
| 1280 | } |
| 1281 | } |
| 1282 | } |
Felix Meschberger | 5dfaa96 | 2009-08-14 19:26:01 +0000 | [diff] [blame] | 1283 | |
| 1284 | |
Felix Meschberger | 432e387 | 2008-03-07 14:58:57 +0000 | [diff] [blame] | 1285 | public String toString() |
| 1286 | { |
| 1287 | return "ManagedServiceFactory Update: factoryPid=" + factoryPid; |
| 1288 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | private class UpdateConfiguration implements Runnable |
| 1292 | { |
| 1293 | |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1294 | private final ConfigurationImpl config; |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1295 | private final Dictionary properties; |
Felix Meschberger | 6f5b69e | 2009-08-19 09:39:21 +0000 | [diff] [blame] | 1296 | private final boolean fireEvent; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1297 | |
| 1298 | |
Felix Meschberger | 6f5b69e | 2009-08-19 09:39:21 +0000 | [diff] [blame] | 1299 | UpdateConfiguration( final ConfigurationImpl config, boolean fireEvent ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1300 | { |
| 1301 | this.config = config; |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1302 | this.properties = config.getProperties( true ); |
Felix Meschberger | 6f5b69e | 2009-08-19 09:39:21 +0000 | [diff] [blame] | 1303 | this.fireEvent = fireEvent; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | |
| 1307 | public void run() |
| 1308 | { |
| 1309 | try |
| 1310 | { |
| 1311 | if ( config.getFactoryPid() == null ) |
| 1312 | { |
Felix Meschberger | 5d3e7ac | 2009-08-14 21:45:10 +0000 | [diff] [blame] | 1313 | final ServiceReference[] srList = bundleContext.getServiceReferences( ManagedService.class |
| 1314 | .getName(), "(" + Constants.SERVICE_PID + "=" + config.getPid() + ")" ); |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1315 | if ( srList != null ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1316 | { |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1317 | // find the primary configuration owner |
| 1318 | final ServiceReference ownerRef = getOwner( config, srList ); |
Felix Meschberger | 6f5b69e | 2009-08-19 09:39:21 +0000 | [diff] [blame] | 1319 | final String bundleLocation = ( ownerRef != null ) ? ownerRef.getBundle().getLocation() |
| 1320 | : config.getBundleLocation(); |
Felix Meschberger | 5d3e7ac | 2009-08-14 21:45:10 +0000 | [diff] [blame] | 1321 | |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1322 | // if the configuration is unbound, bind to owner |
| 1323 | if ( config.getBundleLocation() == null ) |
Felix Meschberger | 5d3e7ac | 2009-08-14 21:45:10 +0000 | [diff] [blame] | 1324 | { |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1325 | config.setDynamicBundleLocation( bundleLocation ); |
| 1326 | } |
| 1327 | final String configBundleLocation = config.getBundleLocation(); |
| 1328 | |
| 1329 | // provide configuration to all services from the |
| 1330 | // correct bundle |
| 1331 | for ( int i = 0; i < srList.length; i++ ) |
| 1332 | { |
| 1333 | |
| 1334 | final ServiceReference userRef = srList[i]; |
| 1335 | final String userRefLocation = userRef.getBundle().getLocation(); |
| 1336 | |
| 1337 | // only consider the entry if in the same bundle |
| 1338 | if ( !userRefLocation.equals( configBundleLocation ) ) |
| 1339 | { |
| 1340 | log( LogService.LOG_ERROR, "Cannot use configuration " + config.getPid() + " for " |
| 1341 | + ConfigurationManager.toString( userRef ) + ": Configuration bound to bundle " |
| 1342 | + configBundleLocation, null ); |
| 1343 | |
| 1344 | continue; |
| 1345 | } |
| 1346 | |
| 1347 | // 104.3 Report an error in the log if more than one |
| 1348 | // service with the same PID asks for the |
| 1349 | // configuration |
| 1350 | if ( userRef != ownerRef ) |
Felix Meschberger | 5d3e7ac | 2009-08-14 21:45:10 +0000 | [diff] [blame] | 1351 | { |
| 1352 | log( LogService.LOG_ERROR, "Configuration for " + config.getPid() |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1353 | + " has already been used for service " + ConfigurationManager.toString( ownerRef ) |
| 1354 | + " and will now also be given to " + ConfigurationManager.toString( userRef ), null ); |
Felix Meschberger | 5d3e7ac | 2009-08-14 21:45:10 +0000 | [diff] [blame] | 1355 | } |
Felix Meschberger | 5d3e7ac | 2009-08-14 21:45:10 +0000 | [diff] [blame] | 1356 | |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1357 | try |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1358 | { |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1359 | final ManagedService srv = ( ManagedService ) bundleContext.getService( userRef ); |
| 1360 | if ( srv != null ) |
| 1361 | { |
| 1362 | Dictionary props = new CaseInsensitiveDictionary( properties ); |
| 1363 | callPlugins( props, config.getPid(), userRef, config ); |
| 1364 | srv.updated( props ); |
| 1365 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1366 | } |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1367 | finally |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1368 | { |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1369 | bundleContext.ungetService( userRef ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1370 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1371 | } |
| 1372 | } |
| 1373 | } |
| 1374 | else |
| 1375 | { |
Felix Meschberger | 5d3e7ac | 2009-08-14 21:45:10 +0000 | [diff] [blame] | 1376 | ServiceReference[] srList = bundleContext.getServiceReferences( ManagedServiceFactory.class |
| 1377 | .getName(), "(" + Constants.SERVICE_PID + "=" + config.getFactoryPid() + ")" ); |
| 1378 | if ( srList != null && srList.length > 0 ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1379 | { |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1380 | // find the primary configuration owner |
| 1381 | final ServiceReference ownerRef = getOwner( config, srList ); |
Felix Meschberger | 6f5b69e | 2009-08-19 09:39:21 +0000 | [diff] [blame] | 1382 | final String bundleLocation = ( ownerRef != null ) ? ownerRef.getBundle().getLocation() |
| 1383 | : config.getBundleLocation(); |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1384 | |
| 1385 | // if the configuration is unbound, bind to owner |
| 1386 | if ( config.getBundleLocation() == null ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1387 | { |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1388 | config.setDynamicBundleLocation( bundleLocation ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1389 | } |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1390 | |
| 1391 | // provide configuration to all services from the |
| 1392 | // correct bundle |
| 1393 | for ( int i = 0; i < srList.length; i++ ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1394 | { |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1395 | final ServiceReference ref = srList[i]; |
| 1396 | final String refLocation = ref.getBundle().getLocation(); |
| 1397 | |
| 1398 | // only consider the entry if in the same bundle |
| 1399 | if ( !refLocation.equals( config.getBundleLocation() ) ) |
| 1400 | { |
| 1401 | log( LogService.LOG_ERROR, "Cannot use configuration " + config.getPid() + " (factory " |
| 1402 | + config.getFactoryPid() + ") for " + ConfigurationManager.toString( ref ) |
| 1403 | + ": Configuration bound to bundle " + config.getBundleLocation(), null ); |
| 1404 | |
| 1405 | continue; |
| 1406 | } |
| 1407 | |
| 1408 | // 104.3 Report an error in the log if more than one |
| 1409 | // service with the same PID asks for the |
| 1410 | // configuration |
| 1411 | if ( ref != ownerRef ) |
| 1412 | { |
| 1413 | log( LogService.LOG_ERROR, "Configuration for " + config.getPid() + " (factory " |
| 1414 | + config.getFactoryPid() + ") has already been used for service " |
| 1415 | + ConfigurationManager.toString( ownerRef ) + " and will now also be given to " |
| 1416 | + ConfigurationManager.toString( ref ), null ); |
| 1417 | } |
| 1418 | |
| 1419 | try |
| 1420 | { |
| 1421 | final ManagedServiceFactory srv = ( ManagedServiceFactory ) bundleContext |
| 1422 | .getService( ref ); |
| 1423 | if ( srv != null && properties != null ) |
| 1424 | { |
| 1425 | Dictionary props = new CaseInsensitiveDictionary( properties ); |
| 1426 | callPlugins( props, config.getFactoryPid(), ref, config ); |
| 1427 | srv.updated( config.getPid(), props ); |
| 1428 | } |
| 1429 | } |
| 1430 | finally |
| 1431 | { |
| 1432 | bundleContext.ungetService( ref ); |
| 1433 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1434 | } |
| 1435 | } |
| 1436 | } |
| 1437 | } |
| 1438 | catch ( ConfigurationException ce ) |
| 1439 | { |
| 1440 | if ( ce.getProperty() != null ) |
| 1441 | { |
| 1442 | log( LogService.LOG_ERROR, "Updating configuration property " + ce.getProperty() |
| 1443 | + " caused a problem: " + ce.getReason(), ce ); |
| 1444 | } |
| 1445 | else |
| 1446 | { |
| 1447 | log( LogService.LOG_ERROR, "Updating configuration caused a problem: " + ce.getReason(), ce ); |
| 1448 | |
| 1449 | } |
| 1450 | } |
| 1451 | catch ( Throwable t ) |
| 1452 | { |
| 1453 | log( LogService.LOG_ERROR, "Unexpected problem updating configuration", t ); |
| 1454 | } |
Felix Meschberger | 15e1c6f | 2009-08-18 07:52:13 +0000 | [diff] [blame] | 1455 | finally |
| 1456 | { |
| 1457 | // the update event has to be sent regardless of whether the |
| 1458 | // configuration was updated in a managed service or not |
Felix Meschberger | 6f5b69e | 2009-08-19 09:39:21 +0000 | [diff] [blame] | 1459 | if ( fireEvent ) |
| 1460 | { |
| 1461 | fireConfigurationEvent( ConfigurationEvent.CM_UPDATED, config.getPid(), config.getFactoryPid() ); |
| 1462 | } |
Felix Meschberger | 15e1c6f | 2009-08-18 07:52:13 +0000 | [diff] [blame] | 1463 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1464 | } |
Felix Meschberger | 5dfaa96 | 2009-08-14 19:26:01 +0000 | [diff] [blame] | 1465 | |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1466 | |
| 1467 | private ServiceReference getOwner( ConfigurationImpl config, ServiceReference[] srList ) |
| 1468 | { |
| 1469 | // find the current owner among the references (if any) |
| 1470 | if ( config.getServiceReference() != null ) |
| 1471 | { |
| 1472 | for ( int i = 0; i < srList.length; i++ ) |
| 1473 | { |
| 1474 | if ( srList[i].equals( config.getServiceReference() ) ) |
| 1475 | { |
| 1476 | return srList[i]; |
| 1477 | } |
| 1478 | } |
| 1479 | } |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1480 | // configuration has never been supplied or the binding is stale |
Felix Meschberger | 6f5b69e | 2009-08-19 09:39:21 +0000 | [diff] [blame] | 1481 | |
| 1482 | // if the configuration is location bound, find a service reference |
| 1483 | // from the same bundle |
| 1484 | final String configLocation = config.getBundleLocation(); |
| 1485 | if (configLocation != null) { |
| 1486 | for ( int i = 0; i < srList.length; i++ ) |
| 1487 | { |
| 1488 | if ( configLocation.equals(srList[i].getBundle().getLocation() ) ) |
| 1489 | { |
| 1490 | return srList[i]; |
| 1491 | } |
| 1492 | } |
| 1493 | // no service from the same bundle found, thus we cannot |
| 1494 | // find a new owner !! |
| 1495 | return null; |
| 1496 | } |
| 1497 | // configuration is not location bound (yet) |
| 1498 | |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1499 | // just use the first entry in the list as the new owner |
| 1500 | final ServiceReference ownerRef = srList[0]; |
| 1501 | config.setServiceReference( ownerRef ); |
| 1502 | return ownerRef; |
| 1503 | } |
| 1504 | |
| 1505 | |
Felix Meschberger | 432e387 | 2008-03-07 14:58:57 +0000 | [diff] [blame] | 1506 | public String toString() |
| 1507 | { |
| 1508 | return "Update: pid=" + config.getPid(); |
| 1509 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1510 | } |
| 1511 | |
| 1512 | private class DeleteConfiguration implements Runnable |
| 1513 | { |
Felix Meschberger | 6642333 | 2007-08-22 08:46:34 +0000 | [diff] [blame] | 1514 | |
Felix Meschberger | c12db8c | 2009-08-19 06:43:59 +0000 | [diff] [blame] | 1515 | private final String pid; |
| 1516 | private final String factoryPid; |
| 1517 | private final String configLocation; |
Felix Meschberger | 6f5b69e | 2009-08-19 09:39:21 +0000 | [diff] [blame] | 1518 | private final boolean fireEvent; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1519 | |
| 1520 | |
Felix Meschberger | 6f5b69e | 2009-08-19 09:39:21 +0000 | [diff] [blame] | 1521 | DeleteConfiguration( ConfigurationImpl config, boolean fireEvent ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1522 | { |
Felix Meschberger | 6642333 | 2007-08-22 08:46:34 +0000 | [diff] [blame] | 1523 | this.pid = config.getPid(); |
| 1524 | this.factoryPid = config.getFactoryPid(); |
Felix Meschberger | c12db8c | 2009-08-19 06:43:59 +0000 | [diff] [blame] | 1525 | this.configLocation = config.getBundleLocation(); |
Felix Meschberger | 6f5b69e | 2009-08-19 09:39:21 +0000 | [diff] [blame] | 1526 | this.fireEvent = fireEvent; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1527 | } |
| 1528 | |
| 1529 | |
| 1530 | public void run() |
| 1531 | { |
| 1532 | try |
| 1533 | { |
Felix Meschberger | 6642333 | 2007-08-22 08:46:34 +0000 | [diff] [blame] | 1534 | if ( factoryPid == null ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1535 | { |
Felix Meschberger | 5d3e7ac | 2009-08-14 21:45:10 +0000 | [diff] [blame] | 1536 | ServiceReference[] srList = bundleContext.getServiceReferences( ManagedService.class.getName(), "(" |
Felix Meschberger | 6642333 | 2007-08-22 08:46:34 +0000 | [diff] [blame] | 1537 | + Constants.SERVICE_PID + "=" + pid + ")" ); |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1538 | if ( srList != null ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1539 | { |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1540 | for ( int i = 0; i < srList.length; i++ ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1541 | { |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1542 | final ServiceReference sr = srList[i]; |
| 1543 | if ( sr.getBundle().getLocation().equals( configLocation ) ) |
| 1544 | { |
| 1545 | // only if the service is from the bound bundle |
| 1546 | final ManagedService srv = ( ManagedService ) bundleContext.getService( sr ); |
| 1547 | try |
| 1548 | { |
| 1549 | srv.updated( null ); |
| 1550 | } |
| 1551 | finally |
| 1552 | { |
| 1553 | bundleContext.ungetService( sr ); |
| 1554 | } |
| 1555 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1556 | } |
| 1557 | } |
| 1558 | } |
| 1559 | else |
| 1560 | { |
| 1561 | // remove the pid from the factory |
Felix Meschberger | 6642333 | 2007-08-22 08:46:34 +0000 | [diff] [blame] | 1562 | Factory factory = getFactory( factoryPid ); |
| 1563 | factory.removePID( pid ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1564 | factory.store(); |
| 1565 | |
Felix Meschberger | 5d3e7ac | 2009-08-14 21:45:10 +0000 | [diff] [blame] | 1566 | ServiceReference[] srList = bundleContext.getServiceReferences( ManagedServiceFactory.class |
| 1567 | .getName(), "(" + Constants.SERVICE_PID + "=" + factoryPid + ")" ); |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1568 | if ( srList != null) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1569 | { |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1570 | for ( int i = 0; i < srList.length; i++ ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1571 | { |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1572 | final ServiceReference sr = srList[i]; |
| 1573 | if ( sr.getBundle().getLocation().equals( configLocation ) ) |
| 1574 | { |
| 1575 | // only if the service is from the bound bundle |
| 1576 | final ManagedServiceFactory srv = ( ManagedServiceFactory ) bundleContext |
| 1577 | .getService( sr ); |
| 1578 | try |
| 1579 | { |
| 1580 | srv.deleted( pid ); |
| 1581 | } |
| 1582 | finally |
| 1583 | { |
| 1584 | bundleContext.ungetService( sr ); |
| 1585 | } |
| 1586 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1587 | } |
| 1588 | } |
| 1589 | } |
| 1590 | } |
| 1591 | catch ( ConfigurationException ce ) |
| 1592 | { |
| 1593 | if ( ce.getProperty() != null ) |
| 1594 | { |
| 1595 | log( LogService.LOG_ERROR, "Updating configuration property " + ce.getProperty() |
| 1596 | + " caused a problem: " + ce.getReason(), ce ); |
| 1597 | } |
| 1598 | else |
| 1599 | { |
| 1600 | log( LogService.LOG_ERROR, "Updating configuration caused a problem: " + ce.getReason(), ce ); |
| 1601 | |
| 1602 | } |
| 1603 | } |
| 1604 | catch ( Throwable t ) |
| 1605 | { |
| 1606 | log( LogService.LOG_ERROR, "Unexpected problem updating configuration", t ); |
| 1607 | } |
Felix Meschberger | 15e1c6f | 2009-08-18 07:52:13 +0000 | [diff] [blame] | 1608 | finally |
| 1609 | { |
| 1610 | // the delete event has to be sent regardless of whether the |
| 1611 | // configuration was updated in a managed service or not |
Felix Meschberger | 6f5b69e | 2009-08-19 09:39:21 +0000 | [diff] [blame] | 1612 | if ( fireEvent ) |
| 1613 | { |
| 1614 | fireConfigurationEvent( ConfigurationEvent.CM_DELETED, pid, factoryPid ); |
| 1615 | } |
Felix Meschberger | 15e1c6f | 2009-08-18 07:52:13 +0000 | [diff] [blame] | 1616 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1617 | } |
Felix Meschberger | 5dfaa96 | 2009-08-14 19:26:01 +0000 | [diff] [blame] | 1618 | |
Felix Meschberger | 432e387 | 2008-03-07 14:58:57 +0000 | [diff] [blame] | 1619 | public String toString() |
| 1620 | { |
| 1621 | return "Delete: pid=" + pid; |
| 1622 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1623 | } |
| 1624 | |
| 1625 | private class FireConfigurationEvent implements Runnable |
| 1626 | { |
| 1627 | private int type; |
| 1628 | |
Felix Meschberger | 6642333 | 2007-08-22 08:46:34 +0000 | [diff] [blame] | 1629 | private String pid; |
Felix Meschberger | 2fd5b58 | 2007-12-10 10:32:29 +0000 | [diff] [blame] | 1630 | |
Felix Meschberger | 6642333 | 2007-08-22 08:46:34 +0000 | [diff] [blame] | 1631 | private String factoryPid; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1632 | |
| 1633 | |
Felix Meschberger | 6642333 | 2007-08-22 08:46:34 +0000 | [diff] [blame] | 1634 | FireConfigurationEvent( int type, String pid, String factoryPid ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1635 | { |
| 1636 | this.type = type; |
Felix Meschberger | 6642333 | 2007-08-22 08:46:34 +0000 | [diff] [blame] | 1637 | this.pid = pid; |
| 1638 | this.factoryPid = factoryPid; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1639 | } |
| 1640 | |
| 1641 | |
| 1642 | public void run() |
| 1643 | { |
| 1644 | // get the listeners |
| 1645 | ServiceReference[] srs = configurationListenerTracker.getServiceReferences(); |
| 1646 | if ( srs == null || srs.length == 0 ) |
| 1647 | { |
| 1648 | return; |
| 1649 | } |
| 1650 | |
Felix Meschberger | b4f83e4 | 2009-01-15 08:53:36 +0000 | [diff] [blame] | 1651 | ConfigurationEvent event = new ConfigurationEvent( getServiceReference(), type, factoryPid, pid ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1652 | |
| 1653 | for ( int i = 0; i < srs.length; i++ ) |
| 1654 | { |
| 1655 | ConfigurationListener cl = ( ConfigurationListener ) configurationListenerTracker.getService( srs[i] ); |
| 1656 | try |
| 1657 | { |
| 1658 | cl.configurationEvent( event ); |
| 1659 | } |
| 1660 | catch ( Throwable t ) |
| 1661 | { |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1662 | log( LogService.LOG_ERROR, "Unexpected problem delivery configuration event to " |
| 1663 | + ConfigurationManager.toString( srs[i] ), t ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1664 | } |
| 1665 | } |
| 1666 | } |
Felix Meschberger | 5dfaa96 | 2009-08-14 19:26:01 +0000 | [diff] [blame] | 1667 | |
Felix Meschberger | 432e387 | 2008-03-07 14:58:57 +0000 | [diff] [blame] | 1668 | public String toString() |
| 1669 | { |
| 1670 | return "Fire ConfigurationEvent: pid=" + pid; |
| 1671 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1672 | } |
| 1673 | |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1674 | private static class ManagedServiceTracker extends ServiceTracker |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1675 | { |
Carsten Ziegeler | 4168398 | 2007-12-27 08:35:27 +0000 | [diff] [blame] | 1676 | |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1677 | private final ConfigurationManager cm; |
| 1678 | |
| 1679 | |
| 1680 | ManagedServiceTracker( ConfigurationManager cm ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1681 | { |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1682 | super( cm.bundleContext, ManagedService.class.getName(), null ); |
Carsten Ziegeler | 4168398 | 2007-12-27 08:35:27 +0000 | [diff] [blame] | 1683 | this.cm = cm; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1684 | open(); |
| 1685 | } |
| 1686 | |
| 1687 | |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1688 | public Object addingService( ServiceReference reference ) |
| 1689 | { |
Felix Meschberger | 2fd5b58 | 2007-12-10 10:32:29 +0000 | [diff] [blame] | 1690 | Object serviceObject = super.addingService( reference ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1691 | |
| 1692 | // configure the managed service |
Felix Meschberger | 2fd5b58 | 2007-12-10 10:32:29 +0000 | [diff] [blame] | 1693 | if ( serviceObject instanceof ManagedService ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1694 | { |
Carsten Ziegeler | 4168398 | 2007-12-27 08:35:27 +0000 | [diff] [blame] | 1695 | cm.configure(reference, ( ManagedService ) serviceObject); |
Felix Meschberger | 2fd5b58 | 2007-12-10 10:32:29 +0000 | [diff] [blame] | 1696 | } |
| 1697 | else |
| 1698 | { |
Carsten Ziegeler | 4168398 | 2007-12-27 08:35:27 +0000 | [diff] [blame] | 1699 | cm.log( LogService.LOG_WARNING, "Service " + serviceObject + " is not a ManagedService", null ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1700 | } |
| 1701 | |
Felix Meschberger | 2fd5b58 | 2007-12-10 10:32:29 +0000 | [diff] [blame] | 1702 | return serviceObject; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1703 | } |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1704 | |
| 1705 | |
| 1706 | public void removedService( ServiceReference reference, Object service ) |
| 1707 | { |
| 1708 | // check whether we can take back the configuration object |
| 1709 | String[] pids = getServicePid( reference ); |
| 1710 | if ( pids != null ) |
| 1711 | { |
| 1712 | for ( int i = 0; i < pids.length; i++ ) |
| 1713 | { |
| 1714 | ConfigurationImpl cfg = cm.getCachedConfiguration( pids[i] ); |
| 1715 | if ( cfg != null && reference.equals( cfg.getServiceReference() ) ) |
| 1716 | { |
| 1717 | cfg.setServiceReference( null ); |
| 1718 | } |
| 1719 | } |
| 1720 | } |
| 1721 | |
| 1722 | super.removedService( reference, service ); |
| 1723 | } |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1724 | } |
| 1725 | |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1726 | private static class ManagedServiceFactoryTracker extends ServiceTracker |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1727 | { |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1728 | private final ConfigurationManager cm; |
| 1729 | |
| 1730 | |
| 1731 | ManagedServiceFactoryTracker( ConfigurationManager cm ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1732 | { |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1733 | super( cm.bundleContext, ManagedServiceFactory.class.getName(), null ); |
| 1734 | this.cm = cm; |
| 1735 | open(); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | |
| 1739 | public Object addingService( ServiceReference reference ) |
| 1740 | { |
Felix Meschberger | 2fd5b58 | 2007-12-10 10:32:29 +0000 | [diff] [blame] | 1741 | Object serviceObject = super.addingService( reference ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1742 | |
Felix Meschberger | 2fd5b58 | 2007-12-10 10:32:29 +0000 | [diff] [blame] | 1743 | // configure the managed service factory |
| 1744 | if ( serviceObject instanceof ManagedServiceFactory ) |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1745 | { |
Carsten Ziegeler | 4168398 | 2007-12-27 08:35:27 +0000 | [diff] [blame] | 1746 | cm.configure( reference, ( ManagedServiceFactory ) serviceObject ); |
Felix Meschberger | 2fd5b58 | 2007-12-10 10:32:29 +0000 | [diff] [blame] | 1747 | } |
| 1748 | else |
| 1749 | { |
Carsten Ziegeler | 4168398 | 2007-12-27 08:35:27 +0000 | [diff] [blame] | 1750 | cm.log( LogService.LOG_WARNING, "Service " + serviceObject + " is not a ManagedServiceFactory", null ); |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1751 | } |
| 1752 | |
Felix Meschberger | 2fd5b58 | 2007-12-10 10:32:29 +0000 | [diff] [blame] | 1753 | return serviceObject; |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1754 | } |
Felix Meschberger | 5dfaa96 | 2009-08-14 19:26:01 +0000 | [diff] [blame] | 1755 | |
Felix Meschberger | 6a698df | 2009-08-16 18:38:46 +0000 | [diff] [blame] | 1756 | |
Felix Meschberger | f463132 | 2008-03-10 12:32:35 +0000 | [diff] [blame] | 1757 | public void removedService( ServiceReference reference, Object service ) |
| 1758 | { |
| 1759 | // check whether we can take back the configuration objects |
Felix Meschberger | 851c641 | 2009-08-16 18:43:26 +0000 | [diff] [blame] | 1760 | String[] factoryPids = getServicePid( reference ); |
| 1761 | if ( factoryPids != null ) |
Felix Meschberger | f463132 | 2008-03-10 12:32:35 +0000 | [diff] [blame] | 1762 | { |
Felix Meschberger | 851c641 | 2009-08-16 18:43:26 +0000 | [diff] [blame] | 1763 | for ( int i = 0; i < factoryPids.length; i++ ) |
| 1764 | { |
| 1765 | Factory factory = cm.getCachedFactory( factoryPids[i] ); |
Felix Meschberger | 6a698df | 2009-08-16 18:38:46 +0000 | [diff] [blame] | 1766 | if ( factory != null ) |
Felix Meschberger | f463132 | 2008-03-10 12:32:35 +0000 | [diff] [blame] | 1767 | { |
Felix Meschberger | 6a698df | 2009-08-16 18:38:46 +0000 | [diff] [blame] | 1768 | for ( Iterator pi = factory.getPIDs().iterator(); pi.hasNext(); ) |
Felix Meschberger | f463132 | 2008-03-10 12:32:35 +0000 | [diff] [blame] | 1769 | { |
Felix Meschberger | 6a698df | 2009-08-16 18:38:46 +0000 | [diff] [blame] | 1770 | String pid = ( String ) pi.next(); |
| 1771 | ConfigurationImpl cfg = cm.getCachedConfiguration( pid ); |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1772 | if ( cfg != null && reference.equals( cfg.getServiceReference() ) ) |
Felix Meschberger | 6a698df | 2009-08-16 18:38:46 +0000 | [diff] [blame] | 1773 | { |
Felix Meschberger | 41cce52 | 2009-08-19 05:54:40 +0000 | [diff] [blame] | 1774 | cfg.setServiceReference( null ); |
Felix Meschberger | 6a698df | 2009-08-16 18:38:46 +0000 | [diff] [blame] | 1775 | } |
Felix Meschberger | f463132 | 2008-03-10 12:32:35 +0000 | [diff] [blame] | 1776 | } |
| 1777 | } |
| 1778 | } |
Felix Meschberger | 851c641 | 2009-08-16 18:43:26 +0000 | [diff] [blame] | 1779 | } |
Felix Meschberger | f463132 | 2008-03-10 12:32:35 +0000 | [diff] [blame] | 1780 | |
| 1781 | super.removedService( reference, service ); |
| 1782 | } |
| 1783 | |
Felix Meschberger | add2b4a | 2007-04-11 18:12:33 +0000 | [diff] [blame] | 1784 | } |
| 1785 | } |