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