blob: 95a9803382c8211c3dba26a3241eff9f2a32237f [file] [log] [blame]
Pierre De Ropfaca2892016-01-31 23:27:05 +00001package org.apache.felix.dm.lambda;
2
3import java.util.Dictionary;
4import java.util.function.BiFunction;
5import java.util.function.Function;
6
7import org.apache.felix.dm.ServiceDependency;
8import org.osgi.framework.ServiceReference;
9
10/**
Pierre De Rop11527502016-02-18 21:07:16 +000011 * Builds a Dependency Manager Service Dependency.
12 * The Dependency is required by default, but you can
13 * control the default mode (required or optional) using the "org.apache.felix.dependencymanager.lambda.dependencymode"
14 * system property which can be set to either "required" or "optional" ("required" by default).
Pierre De Ropfaca2892016-01-31 23:27:05 +000015 *
Pierre De Ropfaca2892016-01-31 23:27:05 +000016 * @param <S> the type of the service dependency
17 */
18public interface ServiceDependencyBuilder<S> extends DependencyBuilder<ServiceDependency>, ServiceCallbacksBuilder<S, ServiceDependencyBuilder<S>> {
19 /**
20 * Configures the service dependency filter
21 * @param filter the service filter
22 * @return this builder
23 */
24 ServiceDependencyBuilder<S> filter(String filter);
25
26 /**
27 * Configures this dependency with the given ServiceReference.
28 * @param ref the service reference
29 * @return this builder
30 */
31 ServiceDependencyBuilder<S> ref(ServiceReference<S> ref);
32
33 /**
Pierre De Rop11527502016-02-18 21:07:16 +000034 * Configures this dependency as optional. By default, the dependency is required, but you can specify the default mode
35 * using the "org.apache.felix.dependencymanager.lambda.dependencymode" system property.
Pierre De Ropfaca2892016-01-31 23:27:05 +000036 * @return this builder
37 */
38 ServiceDependencyBuilder<S> optional();
39
40 /**
Pierre De Rop11527502016-02-18 21:07:16 +000041 * Configures this dependency as required. By default, the dependency is required, but you can specify the default mode
42 * using the "org.apache.felix.dependencymanager.lambda.dependencymode" system property.
Pierre De Ropfaca2892016-01-31 23:27:05 +000043 * @return this builder
44 */
45 ServiceDependencyBuilder<S> required();
46
47 /**
Pierre De Rop11527502016-02-18 21:07:16 +000048 * Configures whether this dependency is required or not. By default, the dependency is required, but you can specify the default mode
49 * using the "org.apache.felix.dependencymanager.lambda.dependencymode" system property.
Pierre De Ropfaca2892016-01-31 23:27:05 +000050 *
51 * @param required true if the dependency is required, false if not. Unlike with the original DM API, service dependencies are required by default.
52 * @return this builder
53 */
54 ServiceDependencyBuilder<S> required(boolean required);
55
56 /**
57 * Configures debug mode
58 * @param label the label used by debug messages
59 * @return this builder
60 */
61 ServiceDependencyBuilder<S> debug(String label);
62
63 /**
64 * Propagates the dependency properties to the component service properties.
65 * @return this builder
66 */
67 ServiceDependencyBuilder<S> propagate();
68
69 /**
70 * Configures whether the dependency properties must be propagated or not to the component service properties.
71 *
72 * @param propagate true if the service dependency properties should be propagated to the properties provided by the component using this dependency.
73 * @return this builder
74 */
75 ServiceDependencyBuilder<S> propagate(boolean propagate);
76
77 /**
78 * Configures a method that can is called in order to get propagated service properties.
79 *
80 * @param instance an object instance
81 * @param method the method name to call on the object instance. This method returns the propagated service properties.
82 * @return this builder
83 */
84 ServiceDependencyBuilder<S> propagate(Object instance, String method);
85
86 /**
87 * Specifies a function that is called to get the propagated service properties for this service dependency.
88 * @param propagate a function that is called to get the propagated service properties for this service dependency.
89 * @return this builder
90 */
91 ServiceDependencyBuilder<S> propagate(Function<ServiceReference<S>, Dictionary<String, Object>> propagate);
92
93 /**
94 * Specifies a function that is called to get the propagated service properties for this service dependency.
95 * @param propagate a function that is called to get the propagated service properties for this service dependency.
96 * @return this builder
97 */
98 ServiceDependencyBuilder<S> propagate(BiFunction<ServiceReference<S>, S, Dictionary<String, Object>> propagate);
99
100 /**
101 * Sets the default implementation if the service is not available.
102 * @param defaultImpl the implementation used by default when the service is not available.
103 * @return this builder
104 */
105 ServiceDependencyBuilder<S> defImpl(Object defaultImpl);
106
107 /**
Pierre De Rop57ffa3f2016-02-19 12:54:30 +0000108 * Sets a timeout for this dependency. A timed dependency blocks the invoker thread if the required dependency is currently unavailable, until it comes up again.
Pierre De Ropfaca2892016-01-31 23:27:05 +0000109 * @param timeout the timeout to wait in milliseconds when the service disappears. If the timeout expires, an IllegalStateException is thrown
110 * when the missing service is invoked.
111 *
112 * @return this builder
113 */
114 ServiceDependencyBuilder<S> timeout(long timeout);
115
116 /**
117 * Injects this dependency in all fields matching the dependency type.
118 * @return this builder
119 */
120 ServiceDependencyBuilder<S> autoConfig();
121
122 /**
123 * Configures whether or not the dependency can be injected in all fields matching the dependency type.
124 * @param autoConfig true if the dependency can be injected in all fields matching the dependency type
125 * @return this builder
126 */
127 ServiceDependencyBuilder<S> autoConfig(boolean autoConfig);
128
129 /**
130 * Injects this dependency on the field with the given name
131 * @param field the field name where the dependency must be injected
132 * @return this builder
133 */
134 ServiceDependencyBuilder<S> autoConfig(String field);
135}