Pierre De Rop | 3a00a21 | 2015-03-01 09:27:46 +0000 | [diff] [blame] | 1 | /* |
| 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.dm; |
| 20 | |
Pierre De Rop | 43ca21b | 2015-11-16 20:55:32 +0000 | [diff] [blame^] | 21 | import aQute.bnd.annotation.ProviderType; |
| 22 | |
Pierre De Rop | 3a00a21 | 2015-03-01 09:27:46 +0000 | [diff] [blame] | 23 | /** |
| 24 | * Configuration dependency that can track the availability of a (valid) configuration. To use |
| 25 | * it, specify a PID for the configuration. The dependency is always required, because if it is |
| 26 | * not, it does not make sense to use the dependency manager. In that scenario, simply register |
| 27 | * your component as a <code>ManagedService(Factory)</code> and handle everything yourself. Also, |
Pierre De Rop | c8295c2 | 2015-06-04 10:15:35 +0000 | [diff] [blame] | 28 | * only managed services are supported, not factories. If you need support for factories, then |
| 29 | * you can use |
| 30 | * {@link DependencyManager#createFactoryConfigurationAdapterService(String, String, boolean)}. |
| 31 | * There are a couple of things you need to be aware of when implementing the |
| 32 | * <code>updated(Dictionary)</code> method: |
Pierre De Rop | 3a00a21 | 2015-03-01 09:27:46 +0000 | [diff] [blame] | 33 | * <ul> |
Pierre De Rop | c8295c2 | 2015-06-04 10:15:35 +0000 | [diff] [blame] | 34 | * <li>Make sure it throws a <code>ConfigurationException</code> or any other exception when you |
| 35 | * get a configuration that is invalid. In this case, the dependency will not change: |
| 36 | * if it was not available, it will still not be. If it was available, it will remain available |
| 37 | * and implicitly assume you keep working with your old configuration.</li> |
Pierre De Rop | 3a00a21 | 2015-03-01 09:27:46 +0000 | [diff] [blame] | 38 | * <li>This method will be called before all required dependencies are available. Make sure you |
| 39 | * do not depend on these to parse your settings.</li> |
Pierre De Rop | c8295c2 | 2015-06-04 10:15:35 +0000 | [diff] [blame] | 40 | * <li>unlike all other DM dependency callbacks, the update method is called from the CM configuration |
| 41 | * update thread, and is not serialized with the internal queue maintained by the DM component. |
| 42 | * So, take care to concurrent calls between updated callback and your other lifecycle callbacks. |
| 43 | * <li>When the configuration is lost, updated callback is invoked with a null dictionary parameter, |
| 44 | * and then the component stop lifecycle callback is invoked. |
| 45 | * <li>When the DM component is stopped, then updated(null) is not invoked. |
Pierre De Rop | 3a00a21 | 2015-03-01 09:27:46 +0000 | [diff] [blame] | 46 | * </ul> |
| 47 | * |
Pierre De Rop | c40d93f | 2015-05-04 20:25:57 +0000 | [diff] [blame] | 48 | * The callback invoked when a configuration dependency is updated can supports the following signatures:<p> |
| 49 | * <ul><li> updated(Dictionary) |
| 50 | * <li> updated(Component, Dictionary) |
| 51 | * </ul> |
| 52 | * |
Pierre De Rop | 3a00a21 | 2015-03-01 09:27:46 +0000 | [diff] [blame] | 53 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
| 54 | */ |
Pierre De Rop | 43ca21b | 2015-11-16 20:55:32 +0000 | [diff] [blame^] | 55 | @ProviderType |
Pierre De Rop | 3a00a21 | 2015-03-01 09:27:46 +0000 | [diff] [blame] | 56 | public interface ConfigurationDependency extends Dependency, ComponentDependencyDeclaration { |
| 57 | /** |
| 58 | * Sets the name of the callback method that should be invoked when a configuration |
| 59 | * is available. The contract for this method is identical to that of |
| 60 | * <code>ManagedService.updated(Dictionary) throws ConfigurationException</code>. |
Pierre De Rop | c8295c2 | 2015-06-04 10:15:35 +0000 | [diff] [blame] | 61 | * By default, if this method is not called, the callback name is "updated". |
Pierre De Rop | 43ca21b | 2015-11-16 20:55:32 +0000 | [diff] [blame^] | 62 | * The callback is always invoked with an already instantiated component (the component implementation class(es) are |
| 63 | * always instantiated before the updated callback is invoked). |
Pierre De Rop | 3a00a21 | 2015-03-01 09:27:46 +0000 | [diff] [blame] | 64 | * |
| 65 | * @param callback the name of the callback method |
| 66 | */ |
| 67 | ConfigurationDependency setCallback(String callback); |
| 68 | |
| 69 | /** |
| 70 | * Sets the name of the callback method that should be invoked when a configuration |
| 71 | * is available. The contract for this method is identical to that of |
| 72 | * <code>ManagedService.updated(Dictionary) throws ConfigurationException</code>. |
Pierre De Rop | 43ca21b | 2015-11-16 20:55:32 +0000 | [diff] [blame^] | 73 | * The callback is called with a component that is not yet instantiated. This allows factory objects to get |
| 74 | * injected with a configuration before its <code>create</code> method is called. |
Pierre De Rop | 3a00a21 | 2015-03-01 09:27:46 +0000 | [diff] [blame] | 75 | * |
| 76 | * @param instance the instance to call the callbacks on |
| 77 | * @param callback the name of the callback method |
| 78 | */ |
| 79 | ConfigurationDependency setCallback(Object instance, String callback); |
| 80 | |
| 81 | /** |
Pierre De Rop | 43ca21b | 2015-11-16 20:55:32 +0000 | [diff] [blame^] | 82 | * Sets the name of the callback method that should be invoked when a configuration |
| 83 | * is available. The contract for this method is identical to that of |
| 84 | * <code>ManagedService.updated(Dictionary) throws ConfigurationException</code>. |
| 85 | * The component instance is instantiated before the callback is invoked only the the <code>needsInstance</code> parameter is set to true. |
| 86 | * |
| 87 | * @param instance the instance to call the callback on |
| 88 | * @param callback the name of the callback method |
| 89 | * @param needsInstance true if the component implementation class(es) must be created before the |
| 90 | * callback instance is invoked, else false. |
| 91 | */ |
| 92 | ConfigurationDependency setCallback(Object instance, String callback, boolean needsInstance); |
| 93 | |
| 94 | /** |
Pierre De Rop | 3a00a21 | 2015-03-01 09:27:46 +0000 | [diff] [blame] | 95 | * Sets the <code>service.pid</code> of the configuration you are depending |
| 96 | * on. |
| 97 | */ |
| 98 | ConfigurationDependency setPid(String pid); |
| 99 | |
| 100 | /** |
| 101 | * Sets propagation of the configuration properties to the service |
| 102 | * properties. Any additional service properties specified directly are |
| 103 | * merged with these. |
| 104 | */ |
| 105 | ConfigurationDependency setPropagate(boolean propagate); |
| 106 | |
| 107 | /** |
| 108 | * The label used to display the tab name (or section) where the properties |
| 109 | * are displayed. Example: "Printer Service". |
| 110 | * |
| 111 | * @return The label used to display the tab name where the properties are |
| 112 | * displayed (may be localized) |
| 113 | */ |
| 114 | ConfigurationDependency setHeading(String heading); |
| 115 | |
| 116 | /** |
| 117 | * A human readable description of the PID this configuration is associated |
| 118 | * with. Example: "Configuration for the PrinterService bundle". |
| 119 | * |
| 120 | * @return A human readable description of the PID this configuration is |
| 121 | * associated with (may be localized) |
| 122 | */ |
| 123 | ConfigurationDependency setDescription(String description); |
| 124 | |
| 125 | /** |
| 126 | * Points to the basename of the Properties file that can localize the Meta |
| 127 | * Type informations. The default localization base name for the properties |
| 128 | * is OSGI-INF/l10n/bundle, but can be overridden by the manifest |
| 129 | * Bundle-Localization header (see core specification, in section |
| 130 | * Localization on page 68). You can specify a specific localization |
| 131 | * basename file using this method (e.g. |
| 132 | * <code>setLocalization("person")</code> will match person_du_NL.properties |
| 133 | * in the root bundle directory. |
| 134 | */ |
| 135 | ConfigurationDependency setLocalization(String path); |
| 136 | |
| 137 | /** |
| 138 | * Adds a MetaData regarding a given configuration property. |
| 139 | */ |
| 140 | ConfigurationDependency add(PropertyMetaData properties); |
| 141 | } |