blob: 02dab2cc3936d6829df279c09f1ee9531dde033b [file] [log] [blame]
Pierre De Rop6e8f9212016-02-20 21:44:59 +00001/*
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 */
Pierre De Ropfaca2892016-01-31 23:27:05 +000019package org.apache.felix.dm.lambda;
20
21import java.util.Dictionary;
Pierre De Rop11527502016-02-18 21:07:16 +000022import java.util.function.Function;
Pierre De Ropfaca2892016-01-31 23:27:05 +000023
24import org.apache.felix.dm.BundleDependency;
25import org.apache.felix.dm.lambda.callbacks.CbBundle;
Pierre De Rop11527502016-02-18 21:07:16 +000026import org.apache.felix.dm.lambda.callbacks.CbBundleComponent;
27import org.apache.felix.dm.lambda.callbacks.InstanceCbBundle;
28import org.apache.felix.dm.lambda.callbacks.InstanceCbBundleComponent;
Pierre De Ropfaca2892016-01-31 23:27:05 +000029import org.osgi.framework.Bundle;
30
31/**
Pierre De Rop11527502016-02-18 21:07:16 +000032 * Builds a Dependency Manager Bundle Dependency.
Pierre De Rop6e8f9212016-02-20 21:44:59 +000033 * When a bundle dependency is not explicitly defined as "required" or "optional", then it is assumed to be required by default.
Pierre De Ropfaca2892016-01-31 23:27:05 +000034 *
Pierre De Rop11527502016-02-18 21:07:16 +000035 * <p> Example of a Pojo Component which tracks a started bundle having a given bundle symbolic name:
Pierre De Ropfaca2892016-01-31 23:27:05 +000036 *
37 * <pre> {@code
38 * public class Activator extends DependencyManagerActivator {
Pierre De Rop11527502016-02-18 21:07:16 +000039 * public void init(BundleContext ctx, DependencyManager dm) throws Exception {
Pierre De Ropfaca2892016-01-31 23:27:05 +000040 * String BSN = "org.apache.felix.dependencymanager";
41 * component(comp -> comp
Pierre De Rop11527502016-02-18 21:07:16 +000042 * .impl(Pojo.class)
43 * .withBundle(b -> b.mask(Bundle.ACTIVE).filter("(Bundle-SymbolicName=" + BSN + ")").add(Pojo::add).remove(Pojo::remove)));
Pierre De Ropfaca2892016-01-31 23:27:05 +000044 * }
45 * }
46 * } </pre>
47 *
48 * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
49 */
50public interface BundleDependencyBuilder extends DependencyBuilder<BundleDependency> {
51 /**
Pierre De Rop11527502016-02-18 21:07:16 +000052 * Enables auto configuration for this dependency. This means the component implementation class fields will be
Pierre De Ropfaca2892016-01-31 23:27:05 +000053 * injected with this bundle dependency automatically.
54 *
55 * @param autoConfig <code>true</code> to enable auto configuration
56 * @return the bundle dependency builder
57 */
58 public BundleDependencyBuilder autoConfig(boolean autoConfig);
59
60 /**
Pierre De Rop11527502016-02-18 21:07:16 +000061 * Enables auto configuration for this dependency. This means the component implementation class fields will be
Pierre De Ropfaca2892016-01-31 23:27:05 +000062 * injected with this bundle dependency automatically.
63 *
64 * @return the bundle dependency builder
65 */
66 public BundleDependencyBuilder autoConfig();
67
68 /**
Pierre De Rop6e8f9212016-02-20 21:44:59 +000069 * Sets the dependency to be required.
70 * @param required <code>true</code> if this bundle dependency is required.
Pierre De Ropfaca2892016-01-31 23:27:05 +000071 * @return the bundle dependency builder
72 */
73 public BundleDependencyBuilder required(boolean required);
74
75 /**
Pierre De Rop6e8f9212016-02-20 21:44:59 +000076 * Sets the dependency to be required.
Pierre De Ropfaca2892016-01-31 23:27:05 +000077 *
78 * @return the bundle dependency builder
79 */
80 public BundleDependencyBuilder required();
81
82 /**
83 * Sets the bundle to depend on directly.
84 *
85 * @param bundle the bundle to depend on
86 * @return the bundle dependency builder
87 */
88 public BundleDependencyBuilder bundle(Bundle bundle);
89
90 /**
91 * Sets the filter condition to depend on. Filters are matched against the full manifest of a bundle.
92 *
93 * @param filter the filter condition
94 * @return the bundle dependency builder
95 */
96 public BundleDependencyBuilder filter(String filter);
97
98 /**
99 * Sets the bundle state mask to depend on. The OSGi BundleTracker explains this mask in more detail, but
100 * it is basically a mask with flags for each potential state a bundle can be in.
101 *
102 * @param mask the mask to use
103 * @return the bundle dependency builder
104 */
105 public BundleDependencyBuilder mask(int mask);
106
107 /**
108 * Sets property propagation. If set to <code>true</code> any bundle manifest properties will be added
Pierre De Rop57ffa3f2016-02-19 12:54:30 +0000109 * to the service properties of the component that declares this dependency (if it provides a service).
Pierre De Ropfaca2892016-01-31 23:27:05 +0000110 *
111 * @param propagate <code>true</code> to propagate the bundle manifest properties
112 * @return the bundle dependency builder
113 */
114 public BundleDependencyBuilder propagate(boolean propagate);
115
116 /**
117 * Sets property propagation. any bundle manifest properties will be added
118 * to the service properties of the component that has this dependency (if it registers as a service).
119 *
120 * @return the bundle dependency builder
121 */
122 public BundleDependencyBuilder propagate();
123
124 /**
125 * Sets an Object instance and a callback method used to propagate some properties to the provided service properties.
126 * The method will be invoked on the specified object instance and must have one of the following signatures:
Pierre De Rop11527502016-02-18 21:07:16 +0000127 *
128 * <p><ul><li>Dictionary callback(Bundle bundle)</ul>
129 *
Pierre De Ropfaca2892016-01-31 23:27:05 +0000130 * @param instance the Object instance which is used to retrieve propagated service properties
131 * @param method the method to invoke for retrieving the properties to be propagated to the service properties.
132 * @return this service dependency. builder
133 */
134 public BundleDependencyBuilder propagate(Object instance, String method);
135
136 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000137 * Sets a reference to a method on an Object instance used to propagate some bundle properties to the provided service properties.
138 *
139 * @param propagate a function which accepts a Bundle argument and which returns some properties that will be
140 * propagated to the provided component service properties.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000141 * @return this service dependency. builder
142 */
Pierre De Rop11527502016-02-18 21:07:16 +0000143 public BundleDependencyBuilder propagate(Function<Bundle, Dictionary<?, ?>> propagate);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000144
145 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000146 * Sets a "add" <code>callback</code> method to invoke on the component implementation instance(s).
147 * The callback is invoked when the bundle is added, and the following signatures are supported:
Pierre De Ropfaca2892016-01-31 23:27:05 +0000148 *
Pierre De Rop11527502016-02-18 21:07:16 +0000149 * <p><ol>
150 * <li>method(Bundle)</li>
151 * <li>method(Component, Bundle)</li>
152 * </ol>
153 *
154 * @param callback the add callback
Pierre De Ropfaca2892016-01-31 23:27:05 +0000155 * @return this builder
156 */
Pierre De Rop11527502016-02-18 21:07:16 +0000157 BundleDependencyBuilder add(String callback);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000158
159 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000160 * Sets a "change" <code>callback</code> method to invoke on the component implementation instance(s).
161 * The callback is invoked when the bundle state has changed, and the following signatures are supported:
Pierre De Ropfaca2892016-01-31 23:27:05 +0000162 *
Pierre De Rop11527502016-02-18 21:07:16 +0000163 * <p><ol>
164 * <li>method(Bundle)</li>
165 * <li>method(Component, Bundle)</li>
166 * </ol>
167 *
168 * @param callback the change callback
Pierre De Ropfaca2892016-01-31 23:27:05 +0000169 * @return this builder
170 */
Pierre De Rop11527502016-02-18 21:07:16 +0000171 BundleDependencyBuilder change(String callback);
172
173 /**
174 * Sets a "remove" <code>callback</code> method to invoke on the component implementation instance(s).
175 * The callback is invoked when the bundle is removed, and the following signatures are supported:
176 * <p><ol>
177 * <li>method(Bundle)</li>
178 * <li>method(Component, Bundle)</li>
179 * </ol>
180 *
181 * @param callback the remove callback
182 * @return this builder
183 */
184 BundleDependencyBuilder remove(String callback);
185
186 /**
187 * Specifies a callback instance used to invoke the reflection based callbacks on it.
Pierre De Rop57ffa3f2016-02-19 12:54:30 +0000188 * @param callbackInstance the instance to invoke the reflection based callbacks on
Pierre De Rop11527502016-02-18 21:07:16 +0000189 * @return this builder
190 * @see #add(String)
191 * @see #change(String)
192 * @see #remove(String)
193 */
194 BundleDependencyBuilder callbackInstance(Object callbackInstance);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000195
196 /**
197 * Sets a <code>callback</code> method reference which is invoked when a bundle is added.
Pierre De Rop11527502016-02-18 21:07:16 +0000198 * The method reference must point to a Component implementation class method, and takes as argument a Bundle.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000199 *
200 * @param <T> the type of the component implementation class on which the callback is invoked on.
201 * @param add the method reference invoked when a bundle is added.
202 * @return this builder
203 */
Pierre De Rop11527502016-02-18 21:07:16 +0000204 <T> BundleDependencyBuilder add(CbBundle<T> add);
205
Pierre De Ropfaca2892016-01-31 23:27:05 +0000206 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000207 * Sets a <code>callback</code> method reference which is invoked when a bundle is changed.
208 * The method reference must point to a Component implementation class method, and takes as argument a Bundle.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000209 *
210 * @param <T> the type of the component implementation class on which the callback is invoked on.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000211 * @param change the method reference invoked when a bundle has changed.
Pierre De Rop11527502016-02-18 21:07:16 +0000212 * @return this builder
213 */
214 <T> BundleDependencyBuilder change(CbBundle<T> change);
215
216 /**
217 * Sets a <code>callback</code> method reference which is invoked when a bundle is removed.
218 * The method reference must point to a Component implementation class method, and takes as argument a Bundle.
219 *
220 * @param <T> the type of the component implementation class on which the callback is invoked on.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000221 * @param remove the method reference invoked when a bundle is removed.
222 * @return this builder
223 */
Pierre De Rop11527502016-02-18 21:07:16 +0000224 <T> BundleDependencyBuilder remove(CbBundle<T> remove);
225
Pierre De Ropfaca2892016-01-31 23:27:05 +0000226 /**
227 * Sets a <code>callback</code> method reference which is invoked when a bundle is added.
Pierre De Rop11527502016-02-18 21:07:16 +0000228 * The method reference must point to a Component implementation class method, and takes as argument a Bundle and a Component.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000229 *
230 * @param <T> the type of the component implementation class on which the callback is invoked on.
231 * @param add the method reference invoked when a bundle is added.
232 * @return this builder
233 */
Pierre De Rop11527502016-02-18 21:07:16 +0000234 <T> BundleDependencyBuilder add(CbBundleComponent<T> add);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000235
236 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000237 * Sets a <code>callback</code> method reference which is invoked when a bundle is changed.
238 * The method reference must point to a Component implementation class method, and takes as argument a Bundle and a Component.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000239 *
240 * @param <T> the type of the component implementation class on which the callback is invoked on.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000241 * @param change the method reference invoked when a bundle has changed.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000242 * @return this builder
243 */
Pierre De Rop11527502016-02-18 21:07:16 +0000244 <T> BundleDependencyBuilder change(CbBundleComponent<T> change);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000245
246 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000247 * Sets a <code>callback</code> method reference which is invoked when a bundle is removed.
248 * The method reference must point to a Component implementation class method, and takes as argument a Bundle and a Component.
249 *
250 * @param <T> the type of the component implementation class on which the callback is invoked on.
251 * @param remove the method reference invoked when a bundle is removed.
252 * @return this builder
253 */
254 <T> BundleDependencyBuilder remove(CbBundleComponent<T> remove);
255
256 /**
257 * Sets a method reference on an Object instance which is invoked when a bundle is added.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000258 * The method reference must point to an Object instance method, and takes as argument a Bundle parameter.
259 *
260 * @param add the method reference invoked when a bundle is added.
261 * @return this builder
262 */
Pierre De Rop11527502016-02-18 21:07:16 +0000263 BundleDependencyBuilder add(InstanceCbBundle add);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000264
265 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000266 * Sets a method reference on an Object instance which is invoked when a bundle is changed.
267 * The method reference must point to an Object instance method, and takes as argument a Bundle parameter.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000268 *
Pierre De Rop11527502016-02-18 21:07:16 +0000269 * @param change the method reference invoked when a bundle is changed.
270 * @return this builder
271 */
272 BundleDependencyBuilder change(InstanceCbBundle change);
273
274 /**
275 * Sets a method reference on an Object instance which is invoked when a bundle is removed.
276 * The method reference must point to an Object instance method, and takes as argument a Bundle parameter.
277 *
Pierre De Ropfaca2892016-01-31 23:27:05 +0000278 * @param remove the method reference invoked when a bundle is removed.
279 * @return this builder
280 */
Pierre De Rop11527502016-02-18 21:07:16 +0000281 BundleDependencyBuilder remove(InstanceCbBundle remove);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000282
283 /**
284 * Sets a <code>callback instance</code> method reference which is invoked when a bundle is added.
Pierre De Rop11527502016-02-18 21:07:16 +0000285 * The method reference must point to an Object instance method, and takes as arguments a Bundle and a Component.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000286 *
287 * @param add the method reference invoked when a bundle is added.
288 * @return this builder
289 */
Pierre De Rop11527502016-02-18 21:07:16 +0000290 BundleDependencyBuilder add(InstanceCbBundleComponent add);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000291
292 /**
Pierre De Rop11527502016-02-18 21:07:16 +0000293 * Sets a <code>callback instance</code> method reference which is invoked when a bundle is changed.
294 * The method reference must point to an Object instance method, and takes as argument a Bundle and a Component.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000295 *
Pierre De Rop11527502016-02-18 21:07:16 +0000296 * @param change the method reference invoked when a bundle is changed.
297 * @return this builder
298 */
299 BundleDependencyBuilder change(InstanceCbBundleComponent change);
300
301 /**
302 * Sets a <code>callback instance</code> method reference which is invoked when a bundle is removed.
303 * The method reference must point to an Object instance method, and takes as argument a Bundle and a Component.
304 *
Pierre De Ropfaca2892016-01-31 23:27:05 +0000305 * @param remove the method reference invoked when a bundle is removed.
306 * @return this builder
307 */
Pierre De Rop11527502016-02-18 21:07:16 +0000308 BundleDependencyBuilder remove(InstanceCbBundleComponent remove);
Pierre De Ropfaca2892016-01-31 23:27:05 +0000309}