Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 1 | package org.apache.felix.dm.lambda; |
| 2 | |
| 3 | import java.util.Dictionary; |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 4 | import java.util.function.Function; |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 5 | |
| 6 | import org.apache.felix.dm.BundleDependency; |
| 7 | import org.apache.felix.dm.lambda.callbacks.CbBundle; |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 8 | import org.apache.felix.dm.lambda.callbacks.CbBundleComponent; |
| 9 | import org.apache.felix.dm.lambda.callbacks.InstanceCbBundle; |
| 10 | import org.apache.felix.dm.lambda.callbacks.InstanceCbBundleComponent; |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 11 | import org.osgi.framework.Bundle; |
| 12 | |
| 13 | /** |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 14 | * Builds a Dependency Manager Bundle Dependency. |
| 15 | * The Dependency is required by default, but you can |
| 16 | * control the default mode (required or optional) using the "org.apache.felix.dependencymanager.lambda.dependencymode" |
| 17 | * system property which can be set to either "required" or "optional" ("required" by default). |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 18 | * |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 19 | * <p> Example of a Pojo Component which tracks a started bundle having a given bundle symbolic name: |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 20 | * |
| 21 | * <pre> {@code |
| 22 | * public class Activator extends DependencyManagerActivator { |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 23 | * public void init(BundleContext ctx, DependencyManager dm) throws Exception { |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 24 | * String BSN = "org.apache.felix.dependencymanager"; |
| 25 | * component(comp -> comp |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 26 | * .impl(Pojo.class) |
| 27 | * .withBundle(b -> b.mask(Bundle.ACTIVE).filter("(Bundle-SymbolicName=" + BSN + ")").add(Pojo::add).remove(Pojo::remove))); |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 28 | * |
| 29 | * } |
| 30 | * } |
| 31 | * } </pre> |
| 32 | * |
| 33 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
| 34 | */ |
| 35 | public interface BundleDependencyBuilder extends DependencyBuilder<BundleDependency> { |
| 36 | /** |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 37 | * Enables auto configuration for this dependency. This means the component implementation class fields will be |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 38 | * injected with this bundle dependency automatically. |
| 39 | * |
| 40 | * @param autoConfig <code>true</code> to enable auto configuration |
| 41 | * @return the bundle dependency builder |
| 42 | */ |
| 43 | public BundleDependencyBuilder autoConfig(boolean autoConfig); |
| 44 | |
| 45 | /** |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 46 | * Enables auto configuration for this dependency. This means the component implementation class fields will be |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 47 | * injected with this bundle dependency automatically. |
| 48 | * |
| 49 | * @return the bundle dependency builder |
| 50 | */ |
| 51 | public BundleDependencyBuilder autoConfig(); |
| 52 | |
| 53 | /** |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 54 | * Sets the dependency to be required. By default, the dependency is required, but you can specify the default mode |
| 55 | * using the "org.apache.felix.dependencymanager.lambda.dependencymode" system property. |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 56 | * |
| 57 | * @param required <code>true</code> if this bundle dependency is required (true by default). |
| 58 | * @return the bundle dependency builder |
| 59 | */ |
| 60 | public BundleDependencyBuilder required(boolean required); |
| 61 | |
| 62 | /** |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 63 | * Sets the dependency to be required. By default, the dependency is required, but you can specify the default mode |
| 64 | * using the "org.apache.felix.dependencymanager.lambda.dependencymode" system property. |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 65 | * |
| 66 | * @return the bundle dependency builder |
| 67 | */ |
| 68 | public BundleDependencyBuilder required(); |
| 69 | |
| 70 | /** |
| 71 | * Sets the bundle to depend on directly. |
| 72 | * |
| 73 | * @param bundle the bundle to depend on |
| 74 | * @return the bundle dependency builder |
| 75 | */ |
| 76 | public BundleDependencyBuilder bundle(Bundle bundle); |
| 77 | |
| 78 | /** |
| 79 | * Sets the filter condition to depend on. Filters are matched against the full manifest of a bundle. |
| 80 | * |
| 81 | * @param filter the filter condition |
| 82 | * @return the bundle dependency builder |
| 83 | */ |
| 84 | public BundleDependencyBuilder filter(String filter); |
| 85 | |
| 86 | /** |
| 87 | * Sets the bundle state mask to depend on. The OSGi BundleTracker explains this mask in more detail, but |
| 88 | * it is basically a mask with flags for each potential state a bundle can be in. |
| 89 | * |
| 90 | * @param mask the mask to use |
| 91 | * @return the bundle dependency builder |
| 92 | */ |
| 93 | public BundleDependencyBuilder mask(int mask); |
| 94 | |
| 95 | /** |
| 96 | * Sets property propagation. If set to <code>true</code> any bundle manifest properties will be added |
| 97 | * to the service properties of the component that has this dependency (if it registers as a service). |
| 98 | * |
| 99 | * @param propagate <code>true</code> to propagate the bundle manifest properties |
| 100 | * @return the bundle dependency builder |
| 101 | */ |
| 102 | public BundleDependencyBuilder propagate(boolean propagate); |
| 103 | |
| 104 | /** |
| 105 | * Sets property propagation. any bundle manifest properties will be added |
| 106 | * to the service properties of the component that has this dependency (if it registers as a service). |
| 107 | * |
| 108 | * @return the bundle dependency builder |
| 109 | */ |
| 110 | public BundleDependencyBuilder propagate(); |
| 111 | |
| 112 | /** |
| 113 | * Sets an Object instance and a callback method used to propagate some properties to the provided service properties. |
| 114 | * The method will be invoked on the specified object instance and must have one of the following signatures: |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 115 | * |
| 116 | * <p><ul><li>Dictionary callback(Bundle bundle)</ul> |
| 117 | * |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 118 | * @param instance the Object instance which is used to retrieve propagated service properties |
| 119 | * @param method the method to invoke for retrieving the properties to be propagated to the service properties. |
| 120 | * @return this service dependency. builder |
| 121 | */ |
| 122 | public BundleDependencyBuilder propagate(Object instance, String method); |
| 123 | |
| 124 | /** |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 125 | * Sets a reference to a method on an Object instance used to propagate some bundle properties to the provided service properties. |
| 126 | * |
| 127 | * @param propagate a function which accepts a Bundle argument and which returns some properties that will be |
| 128 | * propagated to the provided component service properties. |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 129 | * @return this service dependency. builder |
| 130 | */ |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 131 | public BundleDependencyBuilder propagate(Function<Bundle, Dictionary<?, ?>> propagate); |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 132 | |
| 133 | /** |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 134 | * Sets a "add" <code>callback</code> method to invoke on the component implementation instance(s). |
| 135 | * The callback is invoked when the bundle is added, and the following signatures are supported: |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 136 | * |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 137 | * <p><ol> |
| 138 | * <li>method(Bundle)</li> |
| 139 | * <li>method(Component, Bundle)</li> |
| 140 | * </ol> |
| 141 | * |
| 142 | * @param callback the add callback |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 143 | * @return this builder |
| 144 | */ |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 145 | BundleDependencyBuilder add(String callback); |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 146 | |
| 147 | /** |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 148 | * Sets a "change" <code>callback</code> method to invoke on the component implementation instance(s). |
| 149 | * The callback is invoked when the bundle state has changed, and the following signatures are supported: |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 150 | * |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 151 | * <p><ol> |
| 152 | * <li>method(Bundle)</li> |
| 153 | * <li>method(Component, Bundle)</li> |
| 154 | * </ol> |
| 155 | * |
| 156 | * @param callback the change callback |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 157 | * @return this builder |
| 158 | */ |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 159 | BundleDependencyBuilder change(String callback); |
| 160 | |
| 161 | /** |
| 162 | * Sets a "remove" <code>callback</code> method to invoke on the component implementation instance(s). |
| 163 | * The callback is invoked when the bundle is removed, and the following signatures are supported: |
| 164 | * <p><ol> |
| 165 | * <li>method(Bundle)</li> |
| 166 | * <li>method(Component, Bundle)</li> |
| 167 | * </ol> |
| 168 | * |
| 169 | * @param callback the remove callback |
| 170 | * @return this builder |
| 171 | */ |
| 172 | BundleDependencyBuilder remove(String callback); |
| 173 | |
| 174 | /** |
| 175 | * Specifies a callback instance used to invoke the reflection based callbacks on it. |
| 176 | * @param callbackInstance the instance to invoke the callbacks on |
| 177 | * @return this builder |
| 178 | * @see #add(String) |
| 179 | * @see #change(String) |
| 180 | * @see #remove(String) |
| 181 | */ |
| 182 | BundleDependencyBuilder callbackInstance(Object callbackInstance); |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 183 | |
| 184 | /** |
| 185 | * Sets a <code>callback</code> method reference which is invoked when a bundle is added. |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 186 | * The method reference must point to a Component implementation class method, and takes as argument a Bundle. |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 187 | * |
| 188 | * @param <T> the type of the component implementation class on which the callback is invoked on. |
| 189 | * @param add the method reference invoked when a bundle is added. |
| 190 | * @return this builder |
| 191 | */ |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 192 | <T> BundleDependencyBuilder add(CbBundle<T> add); |
| 193 | |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 194 | /** |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 195 | * Sets a <code>callback</code> method reference which is invoked when a bundle is changed. |
| 196 | * The method reference must point to a Component implementation class method, and takes as argument a Bundle. |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 197 | * |
| 198 | * @param <T> the type of the component implementation class on which the callback is invoked on. |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 199 | * @param change the method reference invoked when a bundle has changed. |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 200 | * @return this builder |
| 201 | */ |
| 202 | <T> BundleDependencyBuilder change(CbBundle<T> change); |
| 203 | |
| 204 | /** |
| 205 | * Sets a <code>callback</code> method reference which is invoked when a bundle is removed. |
| 206 | * The method reference must point to a Component implementation class method, and takes as argument a Bundle. |
| 207 | * |
| 208 | * @param <T> the type of the component implementation class on which the callback is invoked on. |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 209 | * @param remove the method reference invoked when a bundle is removed. |
| 210 | * @return this builder |
| 211 | */ |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 212 | <T> BundleDependencyBuilder remove(CbBundle<T> remove); |
| 213 | |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 214 | /** |
| 215 | * Sets a <code>callback</code> method reference which is invoked when a bundle is added. |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 216 | * The method reference must point to a Component implementation class method, and takes as argument a Bundle and a Component. |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 217 | * |
| 218 | * @param <T> the type of the component implementation class on which the callback is invoked on. |
| 219 | * @param add the method reference invoked when a bundle is added. |
| 220 | * @return this builder |
| 221 | */ |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 222 | <T> BundleDependencyBuilder add(CbBundleComponent<T> add); |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 223 | |
| 224 | /** |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 225 | * Sets a <code>callback</code> method reference which is invoked when a bundle is changed. |
| 226 | * The method reference must point to a Component implementation class method, and takes as argument a Bundle and a Component. |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 227 | * |
| 228 | * @param <T> the type of the component implementation class on which the callback is invoked on. |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 229 | * @param change the method reference invoked when a bundle has changed. |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 230 | * @return this builder |
| 231 | */ |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 232 | <T> BundleDependencyBuilder change(CbBundleComponent<T> change); |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 233 | |
| 234 | /** |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 235 | * Sets a <code>callback</code> method reference which is invoked when a bundle is removed. |
| 236 | * The method reference must point to a Component implementation class method, and takes as argument a Bundle and a Component. |
| 237 | * |
| 238 | * @param <T> the type of the component implementation class on which the callback is invoked on. |
| 239 | * @param remove the method reference invoked when a bundle is removed. |
| 240 | * @return this builder |
| 241 | */ |
| 242 | <T> BundleDependencyBuilder remove(CbBundleComponent<T> remove); |
| 243 | |
| 244 | /** |
| 245 | * Sets a method reference on an Object instance which is invoked when a bundle is added. |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 246 | * The method reference must point to an Object instance method, and takes as argument a Bundle parameter. |
| 247 | * |
| 248 | * @param add the method reference invoked when a bundle is added. |
| 249 | * @return this builder |
| 250 | */ |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 251 | BundleDependencyBuilder add(InstanceCbBundle add); |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 252 | |
| 253 | /** |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 254 | * Sets a method reference on an Object instance which is invoked when a bundle is changed. |
| 255 | * The method reference must point to an Object instance method, and takes as argument a Bundle parameter. |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 256 | * |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 257 | * @param change the method reference invoked when a bundle is changed. |
| 258 | * @return this builder |
| 259 | */ |
| 260 | BundleDependencyBuilder change(InstanceCbBundle change); |
| 261 | |
| 262 | /** |
| 263 | * Sets a method reference on an Object instance which is invoked when a bundle is removed. |
| 264 | * The method reference must point to an Object instance method, and takes as argument a Bundle parameter. |
| 265 | * |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 266 | * @param remove the method reference invoked when a bundle is removed. |
| 267 | * @return this builder |
| 268 | */ |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 269 | BundleDependencyBuilder remove(InstanceCbBundle remove); |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 270 | |
| 271 | /** |
| 272 | * Sets a <code>callback instance</code> method reference which is invoked when a bundle is added. |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 273 | * The method reference must point to an Object instance method, and takes as arguments a Bundle and a Component. |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 274 | * |
| 275 | * @param add the method reference invoked when a bundle is added. |
| 276 | * @return this builder |
| 277 | */ |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 278 | BundleDependencyBuilder add(InstanceCbBundleComponent add); |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 279 | |
| 280 | /** |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 281 | * Sets a <code>callback instance</code> method reference which is invoked when a bundle is changed. |
| 282 | * The method reference must point to an Object instance method, and takes as argument a Bundle and a Component. |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 283 | * |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 284 | * @param change the method reference invoked when a bundle is changed. |
| 285 | * @return this builder |
| 286 | */ |
| 287 | BundleDependencyBuilder change(InstanceCbBundleComponent change); |
| 288 | |
| 289 | /** |
| 290 | * Sets a <code>callback instance</code> method reference which is invoked when a bundle is removed. |
| 291 | * The method reference must point to an Object instance method, and takes as argument a Bundle and a Component. |
| 292 | * |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 293 | * @param remove the method reference invoked when a bundle is removed. |
| 294 | * @return this builder |
| 295 | */ |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 296 | BundleDependencyBuilder remove(InstanceCbBundleComponent remove); |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 297 | } |