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