Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/Functions.java URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/Functions.java?rev=1724333&r1=1724332&r2=1724333&view=diff ============================================================================== --- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/Functions.java (original) +++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/Functions.java Tue Jan 12 22:45:36 2016 @@ -1,15 +1,21 @@ package org.apache.felix.dm.builder.lambda; import java.io.Serializable; +import java.util.Dictionary; +import java.util.Map; import java.util.Objects; +import org.apache.felix.dm.Component; +import org.osgi.framework.Bundle; +import org.osgi.framework.ServiceReference; + /** - * This class regroups some reuisable functional interfaces. + * This class provides some reusable functional interfaces. */ public class Functions { /** - * Base interface for serializable functions. Any lambda which generic types need to be introspected must extends this interface. + * Base interface for serializable lambdas. Some lambda must be serializable in order to allow to introspect their type and method signatures. */ public interface SerializableLambda extends Serializable { } @@ -18,80 +24,408 @@ public class Functions { * Lambda allowing to define fluent service properties, like param1 -> "value1", etc ... */ @FunctionalInterface - public interface FluentProperties extends Functions.SerializableLambda { + public interface FluentProperties extends SerializableLambda { public Object apply(String name); } - - /** - * A function that accepts a single input argument and returns no result. - */ - @FunctionalInterface - public interface Consumer<T> extends SerializableLambda { - /** - * Performs this operation on the given argument. - * @param t the input argument - */ - void accept(T t); - - /** - * Returns a composed {@code Consumer} that performs, in sequence, this - * operation followed by the {@code after} operation. - */ - default Consumer<T> andThen(Consumer<? super T> after) { - Objects.requireNonNull(after); - return (T t) -> { accept(t); after.accept(t); }; - } - } - /** - * A function that accepts two input arguments and returns no result. - */ - @FunctionalInterface - public interface Consumer2<T, U> extends SerializableLambda { - /** - * Performs this operation on the given arguments. - * @param t the first input argument - * @param u the second input argument - */ - void accept(T t, U u); - - /** - * Returns a composed {@code BiConsumer} that performs, in sequence, this - * operation followed by the {@code after} operation. - */ - default Consumer2<T, U> andThen(Consumer2<? super T, ? super U> after) { - Objects.requireNonNull(after); - return (t, u) -> { - accept(t, u); - after.accept(t, u); - }; - } - } - - /** - * A function that accepts three input arguments and returns no result. - */ - @FunctionalInterface - public interface Consumer3<T, U, V> extends SerializableLambda { - /** - * Performs this operation on the given arguments. - * @param t the first input argument - * @param u the second input argument - * @param v the third input argument - */ - void accept(T t, U u, V v); - - /** - * Returns a composed {@code BiConsumer} that performs, in sequence, this - * operation followed by the {@code after} operation. - */ - default Consumer3<T, U, V> andThen(Consumer3<? super T, ? super U, ? super V> after) { - Objects.requireNonNull(after); - return (t, u, v) -> { - accept(t, u, v); - after.accept(t, u, v); - }; - } - } - + @FunctionalInterface + public interface CbFuture<F> { + void accept(F future); + + default CbFuture<F> andThen(CbFuture<? super F> after) { + Objects.requireNonNull(after); + return (F f) -> { accept(f); after.accept(f); }; + } + } + + @FunctionalInterface + public interface CbTypeFuture<T, F> extends SerializableLambda { + void accept(T instance, F future); + + default CbTypeFuture<T, F> andThen(CbTypeFuture<? super T, F> after) { + Objects.requireNonNull(after); + return (T instance, F future) -> { accept(instance, future); after.accept(instance, future); }; + } + } + + @FunctionalInterface + public interface CbTypeDictionary<T> extends SerializableLambda { + void accept(T instance, Dictionary<String, Object> conf); + + default CbTypeDictionary<T> andThen(CbTypeDictionary<? super T> after) { + Objects.requireNonNull(after); + return (T instance, Dictionary<String, Object> conf) -> { accept(instance, conf); after.accept(instance, conf); }; + } + } + + @FunctionalInterface + public interface CbTypeComponentDictionary<T> extends SerializableLambda { + void accept(T instance, Component component, Dictionary<String, Object> conf); + + default CbTypeComponentDictionary<T> andThen(CbTypeComponentDictionary<? super T> after) { + Objects.requireNonNull(after); + return (T instance, Component component, Dictionary<String, Object> conf) -> { accept(instance, component, conf); after.accept(instance, component, conf); }; + } + } + + @FunctionalInterface + public interface CbDictionary { + void accept(Dictionary<String, Object> conf); + + default CbDictionary andThen(CbDictionary after) { + Objects.requireNonNull(after); + return (Dictionary<String, Object> conf) -> { accept(conf); after.accept(conf); }; + } + } + + @FunctionalInterface + public interface CbTypeBundle<T> extends SerializableLambda { + void accept(T type, Bundle bundle); + + default CbTypeBundle<T> andThen(CbTypeBundle<? super T> after) { + Objects.requireNonNull(after); + return (T type, Bundle bundle) -> { accept(type, bundle); after.accept(type, bundle); }; + } + } + + @FunctionalInterface + public interface CbTypeComponentBundle<T> extends SerializableLambda { + void accept(T type, Component component, Bundle bundle); + + default CbTypeComponentBundle<T> andThen(CbTypeComponentBundle<? super T> after) { + Objects.requireNonNull(after); + return (T type, Component component, Bundle bundle) -> { accept(type, component, bundle); after.accept(type, component, bundle); }; + } + } + + @FunctionalInterface + public interface CbBundle { + void accept(Bundle bundle); + + default CbBundle andThen(CbBundle after) { + Objects.requireNonNull(after); + return (Bundle bundle) -> { accept(bundle); after.accept(bundle); }; + } + } + + @FunctionalInterface + public interface CbComponentBundle { + void accept(Component component, Bundle bundle); + + default CbComponentBundle andThen(CbComponentBundle after) { + Objects.requireNonNull(after); + return (Component component, Bundle bundle) -> { accept(component, bundle); after.accept(component, bundle); }; + } + } + + @FunctionalInterface + public interface CbComponentDictionary { + void accept(Component component, Dictionary<String, Object> properties); + + default CbComponentDictionary andThen(CbComponentDictionary after) { + Objects.requireNonNull(after); + return (Component component, Dictionary<String, Object> properties) -> { accept(component, properties); after.accept(component, properties); }; + } + } + + @FunctionalInterface + public interface CbService<S> { + void accept(S service); + + default CbService<S> andThen(CbService<S> after) { + Objects.requireNonNull(after); + return (S service) -> { accept(service); after.accept(service); }; + } + } + + @FunctionalInterface + public interface CbServiceMap<S> { + void accept(S service, Map<String, Object> properties); + + default CbServiceMap<S> andThen(CbServiceMap<S> after) { + Objects.requireNonNull(after); + return (S service, Map<String, Object> properties) -> { accept(service, properties); after.accept(service, properties); }; + } + } + + @FunctionalInterface + public interface CbServiceDict<S> { + void accept(S service, Dictionary<String, Object> properties); + + default CbServiceDict<S> andThen(CbServiceDict<S> after) { + Objects.requireNonNull(after); + return (S service, Dictionary<String, Object> properties) -> { accept(service, properties); after.accept(service, properties); }; + } + } + + @FunctionalInterface + public interface CbRefService<S> { + void accept(ServiceReference<S> ref, S service); + + default CbRefService<S> andThen(CbRefService<S> after) { + Objects.requireNonNull(after); + return (ServiceReference<S> ref, S service) -> { accept(ref, service); after.accept(ref, service); }; + } + } + + @FunctionalInterface + public interface CbRef<S> { + void accept(ServiceReference<S> ref); + + default CbRef<S> andThen(CbRef<S> after) { + Objects.requireNonNull(after); + return (ServiceReference<S> ref) -> { after.accept(ref); }; + } + } + + @FunctionalInterface + public interface CbTypeService<T, S> extends SerializableLambda { + void accept(T instance, S service); + + default CbTypeFuture<T, S> andThen(CbTypeFuture<? super T, S> after) { + Objects.requireNonNull(after); + return (T instance, S service) -> { accept(instance, service); after.accept(instance, service); }; + } + } + + @FunctionalInterface + public interface CbTypeServiceMap<T, S> extends SerializableLambda { + void accept(T instance, S service, Map<String, Object> properties); + + default CbTypeServiceMap<T, S> andThen(CbTypeServiceMap<? super T, S> after) { + Objects.requireNonNull(after); + return (T instance, S service, Map<String, Object> properties) -> { accept(instance, service, properties); after.accept(instance, service, properties); }; + } + } + + @FunctionalInterface + public interface CbTypeServiceDict<T, S> extends SerializableLambda { + void accept(T instance, S service, Dictionary<String, Object> properties); + + default CbTypeServiceDict<T, S> andThen(CbTypeServiceDict<? super T, S> after) { + Objects.requireNonNull(after); + return (T instance, S service, Dictionary<String, Object> properties) -> { accept(instance, service, properties); after.accept(instance, service, properties); }; + } + } + + @FunctionalInterface + public interface CbTypeRef<T, S> extends SerializableLambda { + void accept(T instance, ServiceReference<S> service); + + default CbTypeRef<T, S> andThen(CbTypeRef<? super T, S> after) { + Objects.requireNonNull(after); + return (T instance, ServiceReference<S> ref) -> { accept(instance, ref); after.accept(instance, ref); }; + } + } + + @FunctionalInterface + public interface CbTypeRefService<T, S> extends SerializableLambda { + void accept(T instance, ServiceReference<S> ref, S service); + + default CbTypeRefService<T, S> andThen(CbTypeRefService<? super T, S> after) { + Objects.requireNonNull(after); + return (T instance, ServiceReference<S> ref, S service) -> { accept(instance, ref, service); after.accept(instance, ref, service); }; + } + } + + @FunctionalInterface + public interface CbTypeServiceService<T, S> extends SerializableLambda { + void accept(T instance, S old, S replace); + + default CbTypeServiceService<T, S> andThen(CbTypeServiceService<? super T, S> after) { + Objects.requireNonNull(after); + return (T instance, S old, S replace) -> { accept(instance, old, replace); after.accept(instance, old, replace); }; + } + } + + @FunctionalInterface + public interface CbTypeRefServiceRefService<T, S> extends SerializableLambda { + void accept(T instance, ServiceReference<S> oldRef, S old, ServiceReference<S> replaceRef, S replace); + + default CbTypeRefServiceRefService<T, S> andThen(CbTypeRefServiceRefService<? super T, S> after) { + Objects.requireNonNull(after); + return (T instance, ServiceReference<S> oldRef, S old, ServiceReference<S> replaceRef, S replace) -> { accept(instance, oldRef, old, replaceRef, replace); after.accept(instance, oldRef, old, replaceRef, replace); }; + } + } + + @FunctionalInterface + public interface CbTypeMapServiceMapService<T, S> extends SerializableLambda { + void accept(T instance, Map<String, Object> oldProps, S old, Map<String, Object> replaceProps, S replace); + + default CbTypeMapServiceMapService<T, S> andThen(CbTypeMapServiceMapService<? super T, S> after) { + Objects.requireNonNull(after); + return (T instance, Map<String, Object> oldProps, S old, Map<String, Object> replaceProps, S replace) -> { accept(instance, oldProps, old, replaceProps, replace); after.accept(instance, oldProps, old, replaceProps, replace); }; + } + } + + @FunctionalInterface + public interface CbTypeDictServiceDictService<T, S> extends SerializableLambda { + void accept(T instance, Dictionary<String, Object> oldProps, S old, Dictionary<String, Object> replaceProps, S replace); + + default CbTypeDictServiceDictService<T, S> andThen(CbTypeDictServiceDictService<? super T, S> after) { + Objects.requireNonNull(after); + return (T instance, Dictionary<String, Object> oldProps, S old, Dictionary<String, Object> replaceProps, S replace) -> { accept(instance, oldProps, old, replaceProps, replace); after.accept(instance, oldProps, old, replaceProps, replace); }; + } + } + + @FunctionalInterface + public interface CbServiceService<S> extends SerializableLambda { + void accept(S old, S replace); + + default CbServiceService<S> andThen(CbServiceService<S> after) { + Objects.requireNonNull(after); + return (S old, S replace) -> { accept(old, replace); after.accept(old, replace); }; + } + } + + @FunctionalInterface + public interface CbRefServiceRefService<S> { + void accept(ServiceReference<S> oldRef, S old, ServiceReference<S> replaceRef, S replace); + + default CbRefServiceRefService<S> andThen(CbRefServiceRefService<S> after) { + Objects.requireNonNull(after); + return (ServiceReference<S> oldRef, S old, ServiceReference<S> replaceRef, S replace) -> { accept(oldRef, old, replaceRef, replace); after.accept(oldRef, old, replaceRef, replace); }; + } + } + + @FunctionalInterface + public interface CbMapServiceMapService<S> { + void accept(Map<String, Object> oldProps, S old, Map<String, Object> replaceProps, S replace); + + default CbMapServiceMapService<S> andThen(CbMapServiceMapService<S> after) { + Objects.requireNonNull(after); + return (Map<String, Object> oldProps, S old, Map<String, Object> replaceProps, S replace) -> { accept(oldProps, old, replaceProps, replace); after.accept(oldProps, old, replaceProps, replace); }; + } + } + + @FunctionalInterface + public interface CbDictServiceDictService<S> { + void accept(Dictionary<String, Object> oldProps, S old, Dictionary<String, Object> replaceProps, S replace); + + default CbDictServiceDictService<S> andThen(CbDictServiceDictService<S> after) { + Objects.requireNonNull(after); + return (Dictionary<String, Object> oldProps, S old, Dictionary<String, Object> replaceProps, S replace) -> { accept(oldProps, old, replaceProps, replace); after.accept(oldProps, old, replaceProps, replace); }; + } + } + + @FunctionalInterface + public interface CbComponent { + void accept(Component component); + + default CbComponent andThen(CbComponent after) { + Objects.requireNonNull(after); + return (Component component) -> { accept(component); after.accept(component); }; + } + } + + @FunctionalInterface + public interface CbTypeComponent<T> extends SerializableLambda { + void accept(T instance, Component c); + + default CbTypeComponent<T> andThen(CbTypeComponent<T> after) { + Objects.requireNonNull(after); + return (T instance, Component component) -> { accept(instance, component); after.accept(instance, component); }; + } + } + + @FunctionalInterface + public interface CbTypeComponentService<T, S> extends SerializableLambda { + void accept(T instance, Component c, S service); + + default CbTypeComponentService<T, S> andThen(CbTypeComponentService<T, S> after) { + Objects.requireNonNull(after); + return (T instance, Component c, S s) -> { accept(instance, c, s); after.accept(instance, c, s); }; + } + } + + @FunctionalInterface + public interface CbTypeComponentServiceMap<T, S> extends SerializableLambda { + void accept(T instance, Component c, S service, Map<String, Object> props); + + default CbTypeComponentServiceMap<T, S> andThen(CbTypeComponentServiceMap<T, S> after) { + Objects.requireNonNull(after); + return (T instance, Component c, S s, Map<String, Object> props) -> { accept(instance, c, s, props); after.accept(instance, c, s, props); }; + } + } + + @FunctionalInterface + public interface CbTypeComponentServiceDict<T, S> extends SerializableLambda { + void accept(T instance, Component c, S service, Dictionary<String, Object> props); + + default CbTypeComponentServiceDict<T, S> andThen(CbTypeComponentServiceDict<T, S> after) { + Objects.requireNonNull(after); + return (T instance, Component c, S s, Dictionary<String, Object> props) -> { accept(instance, c, s, props); after.accept(instance, c, s, props); }; + } + } + + @FunctionalInterface + public interface CbTypeComponentRef<T, S> extends SerializableLambda { + void accept(T instance, Component c, ServiceReference<S> ref); + + default CbTypeComponentRef<T, S> andThen(CbTypeComponentRef<T, S> after) { + Objects.requireNonNull(after); + return (T instance, Component c, ServiceReference<S> ref) -> { accept(instance, c, ref); after.accept(instance, c, ref); }; + } + } + + @FunctionalInterface + public interface CbTypeComponentRefService<T, S> extends SerializableLambda { + void accept(T instance, Component c, ServiceReference<S> ref, S service); + + default CbTypeComponentRefService<T, S> andThen(CbTypeComponentRefService<T, S> after) { + Objects.requireNonNull(after); + return (T instance, Component c, ServiceReference<S> ref, S service) -> { accept(instance, c, ref, service); after.accept(instance, c, ref, service); }; + } + } + + @FunctionalInterface + public interface CbComponentService<S> { + void accept(Component c, S service); + + default CbComponentService<S> andThen(CbComponentService<S> after) { + Objects.requireNonNull(after); + return (Component c, S service) -> { accept(c, service); after.accept(c, service); }; + } + } + + @FunctionalInterface + public interface CbComponentServiceMap<S> { + void accept(Component c, S service, Map<String, Object> props); + + default CbComponentServiceMap<S> andThen(CbComponentServiceMap<S> after) { + Objects.requireNonNull(after); + return (Component c, S s, Map<String, Object> props) -> { accept(c, s, props); after.accept(c, s, props); }; + } + } + + @FunctionalInterface + public interface CbComponentServiceDict<S> { + void accept(Component c, S service, Dictionary<String, Object> props); + + default CbComponentServiceDict<S> andThen(CbComponentServiceDict<S> after) { + Objects.requireNonNull(after); + return (Component c, S s, Dictionary<String, Object> props) -> { accept(c, s, props); after.accept(c, s, props); }; + } + } + + @FunctionalInterface + public interface CbComponentRef<S> { + void accept(Component c, ServiceReference<S> ref); + + default CbComponentRef<S> andThen(CbComponentRef<S> after) { + Objects.requireNonNull(after); + return (Component c, ServiceReference<S> ref) -> { accept(c, ref); after.accept(c, ref); }; + } + } + + @FunctionalInterface + public interface CbComponentRefService<S> { + void accept(Component c, ServiceReference<S> ref, S service); + + default CbComponentRefService<S> andThen(CbComponentRefService<S> after) { + Objects.requireNonNull(after); + return (Component c, ServiceReference<S> ref, S service) -> { accept(c, ref, service); after.accept(c, ref, service); }; + } + } + }
Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/FutureDependencyBuilder.java URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/FutureDependencyBuilder.java?rev=1724333&r1=1724332&r2=1724333&view=diff ============================================================================== --- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/FutureDependencyBuilder.java (original) +++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/FutureDependencyBuilder.java Tue Jan 12 22:45:36 2016 @@ -3,8 +3,8 @@ package org.apache.felix.dm.builder.lamb import java.util.concurrent.Executor; import org.apache.felix.dm.Dependency; -import org.apache.felix.dm.builder.lambda.Functions.Consumer; -import org.apache.felix.dm.builder.lambda.Functions.Consumer2; +import org.apache.felix.dm.builder.lambda.Functions.CbFuture; +import org.apache.felix.dm.builder.lambda.Functions.CbTypeFuture; /** * Defines a builder for DependencyManager CompletableFuture dependency. @@ -37,50 +37,47 @@ import org.apache.felix.dm.builder.lambd * </pre> * </blockquote> * - * @param <T> the type of the CompletableFuture result. + * @param <F> the type of the CompletableFuture result. */ -public interface FutureDependencyBuilder<T> extends DependencyBuilder<Dependency> { - /** - * Sets the action to perform when the future task has completed. The action is a Consumer instance which accepts the - * result of the completed future. - * @param action the action to perform when the future task as completed. - * @return this dependency - */ - FutureDependencyBuilder<T> thenAccept(Consumer<? super T> action); - +public interface FutureDependencyBuilder<T, F> extends DependencyBuilder<Dependency> { + + /** + * Sets the action to perform when the future task has completed. The action is a Consumer instance which accepts the + * result of the completed future. + * @param action the action to perform when the future task as completed. + * @return this dependency + */ + FutureDependencyBuilder<T, F> cb(CbFuture<? super F> action); + + /** + * Sets the action to perform asynchronously when the future task has completed. The action is a Consumer instance which accepts the + * result of the completed future. + * @param action the action to perform when the future task as completed. + * @return this dependency + */ + FutureDependencyBuilder<T, F> cb(CbFuture<? super F> action, boolean async); + + /** + * Sets the action to perform asynchronously when the future task has completed. The action is a Consumer instance which accepts the + * result of the completed future. + * @param action the action to perform when the future task as completed. + * @param executor the executor to use for asynchronous execution of the action. + * @return this dependency + */ + FutureDependencyBuilder<T, F> cb(CbFuture<? super F> action, Executor executor); + /** * Sets the action to perform when the future task has completed. The action is one of the Component instance method that accepts the * result of the completed future. * @param action the action to perform when the future task as completed. * @return this dependency */ - <I> FutureDependencyBuilder<T> thenAccept(Consumer2<I, ? super T> action); - - /** - * Sets the action to perform asynchronously when the future task has completed. The action is a Consumer instance which accepts the - * result of the completed future. - * @param action the action to perform when the future task as completed. - * @return this dependency - */ - FutureDependencyBuilder<T> thenAcceptAsync(Consumer<? super T> action); + FutureDependencyBuilder<T, F> cb(CbTypeFuture<T, ? super F> action); - /** - * Sets the action to perform asynchronously when the future task has completed. The action is one of the Component instance method that accepts the - * result of the completed future. - * @param action the action to perform when the future task as completed. - * @return this dependency - */ - <I> FutureDependencyBuilder<T> thenAcceptAsync(Consumer2<I, ? super T> action); + FutureDependencyBuilder<T, F> cb(CbTypeFuture<T, ? super F> action, boolean async); + + FutureDependencyBuilder<T, F> cb(CbTypeFuture<T, ? super F> action, Executor executor); - /** - * Sets the action to perform asynchronously when the future task has completed. The action is a Consumer instance which accepts the - * result of the completed future. - * @param action the action to perform when the future task as completed. - * @param executor the executor to use for asynchronous execution of the action. - * @return this dependency - */ - FutureDependencyBuilder<T> thenAcceptAsync(Consumer<? super T> action, Executor executor); - /** * Sets the action to perform asynchronously when the future task has completed. The action is one of the Component instance method that accepts the * result of the completed future. @@ -88,5 +85,7 @@ public interface FutureDependencyBuilder * @param executor the executor to use for asynchronous execution of the action. * @return this dependency */ - <I> FutureDependencyBuilder<T> thenAcceptAsync(Consumer2<I, ? super T> action, Executor executor); + <C> FutureDependencyBuilder<T, F> compositeCb(CbTypeFuture<C, ? super F> action); + <C> FutureDependencyBuilder<T, F> compositeCb(CbTypeFuture<C, ? super F> action, boolean async); + <C> FutureDependencyBuilder<T, F> compositeCb(CbTypeFuture<C, ? super F> action, Executor executor); } Added: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ServiceAdapterBuilder.java URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ServiceAdapterBuilder.java?rev=1724333&view=auto ============================================================================== --- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ServiceAdapterBuilder.java (added) +++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ServiceAdapterBuilder.java Tue Jan 12 22:45:36 2016 @@ -0,0 +1,92 @@ +package org.apache.felix.dm.builder.lambda; + +import java.util.function.Function; +import java.util.function.Supplier; + +/** + * Defines the interface for a DependencyManager adapter builder. + * + * Code example that adapts a "Device" service to an HttpServlet service. the adapter accepts a lambda that is provided with an AdapterBuilder + * + * <pre> {@code + * public class Activator extends DependencyActivatorBase { + * public void init() throws Exception { + * adapter(Device.class, builder -> builder + * .provides(HttpServlet.class).properties("alias", "/device").impl(DeviceServlet.class).onStart(DeviceServlet::activate); + * } + * }}</pre> + * + * @param <T> the adaptee service + * TODO: add javadoc + */ +public interface ServiceAdapterBuilder<T, C> extends ComponentBuilderBase<C, ServiceAdapterBuilder<T, C>>, ServiceCallbacksBuilder<T, ServiceAdapterBuilder<T, C>> { + /** + * Configures the component implementation. Can be a class name, or a component implementation object. + * @param impl the component implementation (a class, or an Object). + * @return this builder + */ + <U> ServiceAdapterBuilder<T, U> impl(U impl); + + /** + * TODO + */ + <U> ServiceAdapterBuilder<T, U> impl(Class<U> implClass); + + /** + * Configures a factory that can be used to create this component implementation. + * Example: "factory(ComponentImpl::new)", or "factory(() -> new ComponentImpl())". + * + * @param create the factory used to create the component implementation. + * @return this builder + */ + <U> ServiceAdapterBuilder<T, U> factory(Supplier<U> create); + + /** + * Configures a factory used to create this component implementation using a Factory object and a method in the Factory object. + * Example: + * + * factory(Factory::new, Factory::create) + * + * @param factory the function used to create the Factory itself + * @param create the method reference on the Factory method that is used to create the Component implementation + * @return this builder + */ + <U, V> ServiceAdapterBuilder<T, V> factory(Supplier<U> factory, Function<U, V> create); + + /** + * Configures a factory used to create this component implementation using a Factory object and a "getComponent" factory method. + * the Factory method may then return multiple objects that will be part of this component implementation. + * + * Example: + * + * CompositionManager mngr = new CompositionManager(); + * ... + * factory(mngr::create, mngr::getComposition) + * + * @param factory + * @param getComposition + * @return this builder + */ + <U> ServiceAdapterBuilder<T, U> factory(Supplier<U> factory, Supplier<Object[]> getComposition); + + /** + * Configures a factory that also returns a composition of objects for this component implemenation. + * + * Example: + * + * factory(CompositionManager::new, CompositionManager::create, CompositionManager::getComposition). + * + * Here, the CompositionManager will act as a factory (the create method will return the component implementation object), and the + * CompositionManager.getComposition() method will return all the objects that are also part of the component implementation. + * + * @param factory the function used to create the Factory itself + * @param create the Factory method used to create the main component implementation object + * @param getComposition the Factory method used to return the list of objects that are also part of the component implementation. + * @return this builder + */ + <U, V> ServiceAdapterBuilder<T, V> factory(Supplier<U> factory, Function<U, V> create, Function<U, Object[]> getComposition); + + ServiceAdapterBuilder<T, C> filter(String adapteeFilter); + ServiceAdapterBuilder<T, C> propagate(); + ServiceAdapterBuilder<T, C> propagate(boolean propagate); +} Added: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ServiceAspectBuilder.java URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ServiceAspectBuilder.java?rev=1724333&view=auto ============================================================================== --- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ServiceAspectBuilder.java (added) +++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ServiceAspectBuilder.java Tue Jan 12 22:45:36 2016 @@ -0,0 +1,97 @@ +package org.apache.felix.dm.builder.lambda; + +import java.util.function.Function; +import java.util.function.Supplier; + +/** + * Defines the interface for a DependencyManager aspect builder. + * + * Code example that provides an aspect service for an English dictionary service: + * + * <pre> {@code + * public class Activator extends DependencyActivatorBase { + * public void init() throws Exception { + * aspect(DictionaryService.class, builder -> builder + * .filter("(lang=en)") + * .rank(10) + * .impl(DictionaryAspect.class) + * .withService(LogService.class, srv -> srv.required(false))); + * } + * }}</pre> + * + * @param <T> the aspect service + * @param <C> the type of the aspect component implementation class + * + * TODO: javadoc + */ +public interface ServiceAspectBuilder<T, C> extends ComponentBuilderBase<C, ServiceAspectBuilder<T, C>>, ServiceCallbacksBuilder<T, ServiceAspectBuilder<T, C>> { + /** + * Configures the component implementation. Can be a class name, or a component implementation object. + * @param impl the component implementation (a class, or an Object). + * @return this builder + */ + <U> ServiceAspectBuilder<T, U> impl(U impl); + + /** + * TODO + */ + <U> ServiceAspectBuilder<T, U> impl(Class<U> implClass); + + /** + * Configures a factory that can be used to create this component implementation. + * Example: "factory(ComponentImpl::new)", or "factory(() -> new ComponentImpl())". + * + * @param create the factory used to create the component implementation. + * @return this builder + */ + <U> ServiceAspectBuilder<T, U> factory(Supplier<U> create); + + /** + * Configures a factory used to create this component implementation using a Factory object and a method in the Factory object. + * Example: + * + * factory(Factory::new, Factory::create) + * + * @param factory the function used to create the Factory itself + * @param create the method reference on the Factory method that is used to create the Component implementation + * @return this builder + */ + <U, V> ServiceAspectBuilder<T, V> factory(Supplier<U> factory, Function<U, V> create); + + /** + * Configures a factory used to create this component implementation using a Factory object and a "getComponent" factory method. + * the Factory method may then return multiple objects that will be part of this component implementation. + * + * Example: + * + * CompositionManager mngr = new CompositionManager(); + * ... + * factory(mngr::create, mngr::getComposition) + * + * @param factory + * @param getComposition + * @return this builder + */ + <U> ServiceAspectBuilder<T, U> factory(Supplier<U> factory, Supplier<Object[]> getComposition); + + /** + * Configures a factory that also returns a composition of objects for this component implemenation. + * + * Example: + * + * factory(CompositionManager::new, CompositionManager::create, CompositionManager::getComposition). + * + * Here, the CompositionManager will act as a factory (the create method will return the component implementation object), and the + * CompositionManager.getComposition() method will return all the objects that are also part of the component implementation. + * + * @param factory the function used to create the Factory itself + * @param create the Factory method used to create the main component implementation object + * @param getComposition the Factory method used to return the list of objects that are also part of the component implementation. + * @return this builder + */ + <U, V> ServiceAspectBuilder<T, V> factory(Supplier<U> factory, Function<U, V> create, Function<U, Object[]> getComposition); + + ServiceAspectBuilder<T, C> filter(String filter); + + ServiceAspectBuilder<T, C> rank(int ranking); +} Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ServiceCallbacksBuilder.java URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ServiceCallbacksBuilder.java?rev=1724333&r1=1724332&r2=1724333&view=diff ============================================================================== --- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ServiceCallbacksBuilder.java (original) +++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ServiceCallbacksBuilder.java Tue Jan 12 22:45:36 2016 @@ -1,273 +1,46 @@ package org.apache.felix.dm.builder.lambda; -import java.util.Dictionary; -import java.util.Map; - -import org.apache.felix.dm.builder.lambda.Functions.SerializableLambda; -import org.osgi.framework.ServiceReference; +import org.apache.felix.dm.builder.lambda.Functions.CbComponent; +import org.apache.felix.dm.builder.lambda.Functions.CbComponentRef; +import org.apache.felix.dm.builder.lambda.Functions.CbComponentRefService; +import org.apache.felix.dm.builder.lambda.Functions.CbComponentService; +import org.apache.felix.dm.builder.lambda.Functions.CbComponentServiceDict; +import org.apache.felix.dm.builder.lambda.Functions.CbComponentServiceMap; +import org.apache.felix.dm.builder.lambda.Functions.CbDictServiceDictService; +import org.apache.felix.dm.builder.lambda.Functions.CbMapServiceMapService; +import org.apache.felix.dm.builder.lambda.Functions.CbRef; +import org.apache.felix.dm.builder.lambda.Functions.CbRefService; +import org.apache.felix.dm.builder.lambda.Functions.CbRefServiceRefService; +import org.apache.felix.dm.builder.lambda.Functions.CbService; +import org.apache.felix.dm.builder.lambda.Functions.CbServiceDict; +import org.apache.felix.dm.builder.lambda.Functions.CbServiceMap; +import org.apache.felix.dm.builder.lambda.Functions.CbServiceService; +import org.apache.felix.dm.builder.lambda.Functions.CbTypeComponent; +import org.apache.felix.dm.builder.lambda.Functions.CbTypeComponentRef; +import org.apache.felix.dm.builder.lambda.Functions.CbTypeComponentRefService; +import org.apache.felix.dm.builder.lambda.Functions.CbTypeComponentService; +import org.apache.felix.dm.builder.lambda.Functions.CbTypeComponentServiceDict; +import org.apache.felix.dm.builder.lambda.Functions.CbTypeComponentServiceMap; +import org.apache.felix.dm.builder.lambda.Functions.CbTypeDictServiceDictService; +import org.apache.felix.dm.builder.lambda.Functions.CbTypeMapServiceMapService; +import org.apache.felix.dm.builder.lambda.Functions.CbTypeRef; +import org.apache.felix.dm.builder.lambda.Functions.CbTypeRefService; +import org.apache.felix.dm.builder.lambda.Functions.CbTypeRefServiceRefService; +import org.apache.felix.dm.builder.lambda.Functions.CbTypeService; +import org.apache.felix.dm.builder.lambda.Functions.CbTypeServiceDict; +import org.apache.felix.dm.builder.lambda.Functions.CbTypeServiceMap; +import org.apache.felix.dm.builder.lambda.Functions.CbTypeServiceService; /** * Definition of method references for general service dependency callbacks. * - * @param <T> a service dependency type + * @param <S> a service dependency type * @param <B> the type of a sub interface that may extends this interface * * TODO: add javadocs + * @author <a href="mailto:[email protected]">Felix Project Team</a> */ -public interface ServiceCallbacksBuilder<T, B extends ServiceCallbacksBuilder<T, B>> { - /** - * Defines a reference on a bind method from an object instance. The bind method takes a service parameter. - * @param <T> the type of the parameter passed to the callback method. - */ - @FunctionalInterface - public interface Service<T> { - /** - * Signature of the callback method - * @param service the service injected using the callback method - */ - void call(T service); - } - - /** - * Defines a reference on a bind method from an object instance. The bind method takes a service parameter, as well as a Map - * (for service properties). - * @param <T> the type of the parameter passed to the callback method. - */ - @FunctionalInterface - public interface ServiceMap<T> { - /** - * Signature of the callback method - * @param service the service injected using the callback method - * @param properties the service properties - */ - void call(T service, Map<String, Object> properties); - } - - /** - * Defines a method reference on a bind method from an object instance. The bind method takes a service parameter, as well as a Dictionary - * (for service properties). - * @param <T> the type of the parameter passed to the callback method. - */ - @FunctionalInterface - public interface ServiceDict<T> { - /** - * Signature of the callback method - * @param service the service injected using the callback method - * @param properties the service properties - */ - void call(T service, Dictionary<String, Object> properties); - } - - /** - * Defines a method reference on a bind method from an object instance. The bind method takes an OSGi service reference parameter. - * @param <T> the type of the parameter passed to the callback method. - */ - @FunctionalInterface - public interface Ref<T> { - /** - * Signature of the callback method - * @param service the service injected using the callback method - */ - void call(ServiceReference<T> service); - } - - /** - * Defines a method reference on a bind method from an object instance. The bind method takes a service, and the corresponding OSGi service reference. - * @param <T> the type of the parameter passed to the callback method. - */ - @FunctionalInterface - public interface ServiceRef<T> { - /** - * Signature of the callback method - * @param service the service injected using the callback method - * @param ref the corresponding OSGi service reference - */ - void call(T service, ServiceReference<T> ref); - } - - /** - * Defines a method reference on a DependencManager swap callback, using ServiceReference for service properties. - * @param <T> the type of the swapped service. - */ - @FunctionalInterface - public interface RefServiceRefService<T> { - /** - * Signature of the callback method - * @param oldRef the replaced service reference - * @param old the replaced service - * @param replaceRef the reference to the new service that replaces the old service - * @param replace the new service that replaces the old service - */ - void call(ServiceReference<T> oldRef, T old, ServiceReference<T> replaceRef, T replace); - } - - /** - * Defines a method reference on a DependencManager swap callback, using Map for service properties. - * @param <T> the type of the swapped service. - */ - @FunctionalInterface - public interface MapServiceMapService<T> { - /** - * Signature of the callback method - * @param oldProps the replaced service properties - * @param old the replaced service - * @param replaceProps the new service properties that replaces the old service - * @param replace the new service that replaces the old service - */ - void call(Map<String, Object> oldProps, T old, Map<String, Object> replaceProps, T replace); - } - - /** - * Defines a method reference on a DependencManager swap callback, using Dictionary for service properties. - * @param <T> the type of the swapped service. - */ - @FunctionalInterface - public interface DictServiceDictService<T> { - /** - * Signature of the callback method - * @param oldProps the replaced service properties - * @param old the replaced service - * @param replaceProps the new service properties that replaces the old service - * @param replace the new service that replaces the old service - */ - void call(Dictionary<String, Object> oldProps, T old, Dictionary<String, Object> replaceProps, T replace); - } - - /** - * Defines a method reference on a class method, without the instance. The bind method takes an OSGi service as parameter. - * @param <I> the type of the instance on which this method reference is applied - * @param <T> the type of the parameter passed to the callback method. - */ - @FunctionalInterface - public interface InstanceService<I, T> extends SerializableLambda { - /** - * Signature of the callback method. - * @param instance the instance on which the callback has to be called - * @param service the service to inject in the instance method using this method reference - */ - void call(I instance, T service); - } - - /** - * Defines a method reference on a class method, without the instance. the bind method takes an OSGi service as parameter, and a Map - * for service properties. - * @param <I> the type of the instance on which this method reference is applied - * @param <T> the type of the method parameter. - */ - @FunctionalInterface - public interface InstanceServiceMap<I, T> extends SerializableLambda { - /** - * Signature of the callback method. - * @param instance the instance on which the callback has to be called - * @param service the service to inject in the instance method using this method reference - * @param properties the service properties - */ - void call(I instance, T service, Map<String, Object> properties); - } - - /** - * Defines a method reference on a class method, without the instance. the bind method takes an OSGi service as parameter, and a Dictionary - * for service properties. - * @param <I> the type of the instance on which this method reference is applied - * @param <T> the type of the method parameter. - */ - @FunctionalInterface - public interface InstanceServiceDict<I, T> extends SerializableLambda { - /** - * Signature of the callback method. - * @param instance the instance on which the callback has to be called - * @param service the service to inject in the instance method using this method reference - * @param properties the service properties - */ - void call(I instance, T service, Dictionary<String, Object> properties); - } - - /** - * Defines a method reference on a class method, without the instance. The bind method takes an OSGi service reference as parameter. - * for service properties. - * @param <I> the type of the instance on which this method reference is applied - * @param <T> the type of the parameter passed to the callback method. - */ - @FunctionalInterface - public interface InstanceRef<I, T> extends SerializableLambda { - /** - * Signature of the callback method. - * @param instance the instance on which the callback has to be called - * @param service the service to inject in the instance method using this method reference - */ - void call(I instance, ServiceReference<T> service); - } - - /** - * Defines a method reference on a class method, without the instance. The bind method takes a Service, and the corresponding service reference. - * @param <I> the type of the instance on which this method reference is applied - * @param <T> the type of the parameter passed to the callback method. - */ - @FunctionalInterface - public interface InstanceServiceRef<I, T> extends SerializableLambda { - /** - * Signature of the callback method. - * @param instance the instance on which the callback has to be called - * @param service the service to inject in the instance method using this method reference - * @param ref the service reference - */ - void call(I instance, T service, ServiceReference<T> ref); - } - - /** - * Defines a method reference on a DependencyManager swap callback, without the instance. The bind method takes a ServiceReference, a Service, a ServiceReference, and a Service. - * @param <I> the type of the instance on which this method reference is applied - * @param <T> the type of the parameter passed to the callback method. - */ - @FunctionalInterface - public interface InstanceRefServiceRefService<I, T> extends SerializableLambda { - /** - * Signature of the callback method - * @param instance the instance on which the callback has to be called - * @param oldRef the replaced service reference - * @param old the replaced service - * @param replaceRef the reference to the new service that replaces the old service - * @param replace the new service that replaces the old service - */ - void call(I instance, ServiceReference<T> oldRef, T old, ServiceReference<T> replaceRef, T replace); - } - - /** - * Defines a method reference on a DependencyManager swap callback, without the instance. The bind method takes a Map, a Service, a Map, and a Service. - * @param <I> the type of the instance on which this method reference is applied - * @param <T> the type of the parameter passed to the callback method. - */ - @FunctionalInterface - public interface InstanceMapServiceMapService<I, T> extends SerializableLambda { - /** - * Signature of the callback method - * @param instance the instance on which the callback has to be called - * @param oldProps the replaced service properties - * @param old the replaced service - * @param replaceProps the new service properties that replaces the old service - * @param replace the new service that replaces the old service - */ - void call(I instance, Map<String, Object> oldProps, T old, Map<String, Object> replaceProps, T replace); - } - - /** - * Defines a method reference on a DependencyManager swap callback, without the instance. The bind method takes a Dictionary, a Service, a Dictionary, and a Service. - * @param <I> the type of the instance on which this method reference is applied - * @param <T> the type of the parameter passed to the callback method. - */ - @FunctionalInterface - public interface InstanceDictServiceDictService<I, T> extends SerializableLambda { - /** - * Signature of the callback method - * @param instance the instance on which the callback has to be called - * @param oldProps the replaced service properties - * @param old the replaced service - * @param replaceProps the new service properties that replaces the old service - * @param replace the new service that replaces the old service - */ - void call(I instance, Dictionary<String, Object> oldProps, T old, Dictionary<String, Object> replaceProps, T replace); - } - +public interface ServiceCallbacksBuilder<S, B extends ServiceCallbacksBuilder<S, B>> { /** * Injects this dependency in all fields matching the dependency type. * @return this builder @@ -286,116 +59,46 @@ public interface ServiceCallbacksBuilder * @param field the field name where the dependency must be injected * @return this builder */ - B autoConfig(String field); - - /** - * Configures the dependency callback instance. - * @param instance the dependency callback instance - * @return this builder - */ - B callbackInstance(Object instance); - - /** - * Sets the callbacks for this dependency. These callbacks can be used as hooks whenever a dependency is added or - * removed. When you specify callbacks, the auto configuration feature is automatically turned off, because we're assuming - * you don't need it in this case. - * - * @param added the method to call when a service was added - * @param removed the method to call when a service was removed - * @return the bundle dependency - */ - public B callbacks(String added, String removed); - - /** - * Sets the callbacks for this dependency. These callbacks can be used as hooks whenever a dependency is added, changed or - * removed. When you specify callbacks, the auto configuration feature is automatically turned off, because we're assuming - * you don't need it in this case. - * - * @param added the method to call when a service was added - * @param changed the method to call when a service was changed - * @param removed the method to call when a service was removed - * @return the bundle dependency - */ - public B callbacks(String added, String changed, String removed); - - /** - * Sets the callbacks for this dependency. These callbacks can be used as hooks whenever a dependency is added, changed or - * removed, or swapped. When you specify callbacks, the auto configuration feature is automatically turned off, because we're assuming - * you don't need it in this case. - * - * @param added the method to call when a service was added - * @param changed the method to call when a service was changed - * @param removed the method to call when a service was removed - * @param swap the method to call when a service was swapped - * @return the bundle dependency - */ - public B callbacks(String added, String changed, String removed, String swap); - - /** - * Configures the callback to invoke when the dependency becomes available - * @param added the method name to call when the dependency is available - * @return this builder - */ - B onAdd(String added); + B autoConfig(String field); - /** - * Configures the callback to invoke when the dependency is changed. - * @param changed the method name to call when the dependency is changed - * @return this builder - */ - B onChange(String changed); + B cbInst(Object callbackInstance); - /** - * Configures the callback to invoke when the dependency is removed. - * @param changed the method name to call when the dependency is lost - * @return this builder - */ - B onRemove(String removed); - - /** - * Configures the callback to call when the service is swapped by another one - * @param swapped the method name to call on swap service event - * @return this builder - */ - B onSwap(String swapped); - - <I> B onAdd(InstanceService<I, T> add); - B onAdd(Service<T> add); - <I> B onAdd(InstanceServiceMap<I, T> add); - B onAdd(ServiceMap<T> add); - <I> B onAdd(InstanceServiceDict<I, T> add); - B onAdd(ServiceDict<T> add); - <I> B onAdd(InstanceRef<I, T> add); - B onAdd(Ref<T> add); - <I> B onAdd(InstanceServiceRef<I, T> add); - B onAdd(ServiceRef<T> add); - - <I> B onChange(InstanceService<I, T> change); - B onChange(Service<T> change); - <I> B onChange(InstanceServiceMap<I, T> change); - B onChange(ServiceMap<T> change); - <I> B onChange(InstanceServiceDict<I, T> change); - B onChange(ServiceDict<T> change); - <I> B onChange(InstanceRef<I, T> change); - B onChange(Ref<T> change); - <I> B onChange(InstanceServiceRef<I, T> add); - B onChange(ServiceRef<T> add); - - <I> B onRemove(InstanceService<I, T> remove); - B onRemove(Service<T> remove); - <I> B onRemove(InstanceServiceMap<I, T> remove); - B onRemove(ServiceMap<T> remove); - <I> B onRemove(InstanceServiceDict<I, T> remove); - B onRemove(ServiceDict<T> remove); - <I> B onRemove(InstanceRef<I, T> remove); - B onRemove(Ref<T> remove); - <I> B onRemove(InstanceServiceRef<I, T> add); - B onRemove(ServiceRef<T> add); - - <I> B onSwap(InstanceRefServiceRefService<I, T> swap); - B onSwap(RefServiceRefService<T> swap); - <I> B onSwap(InstanceMapServiceMapService<I, T> swap); - B onSwap(MapServiceMapService<T> swap); - <I> B onSwap(InstanceDictServiceDictService<I, T> swap); - B onSwap(DictServiceDictService<T> swap); + B cb(String add); + B cb(String add, String remove); + B cb(String add, String change, String remove); + B cb(String add, String change, String remove, String swap); + + <T> B cb(CB cbType, CbTypeService<T, S> callback); + <T> B cb(CB cbType, CbTypeServiceMap<T, S> callback); + <T> B cb(CB cbType, CbTypeServiceDict<T, S> callback); + <T> B cb(CB cbType, CbTypeRef<T, S> callback); + <T> B cb(CB cbType, CbTypeRefService<T, S> callback); + <T> B cb(CB cbType, CbTypeComponent<T> callback); + <T> B cb(CB cbType, CbTypeComponentService<T, S> callback); + <T> B cb(CB cbType, CbTypeComponentServiceMap<T, S> callback); + <T> B cb(CB cbType, CbTypeComponentServiceDict<T, S> callback); + <T> B cb(CB cbType, CbTypeComponentRef<T, S> callback); + <T> B cb(CB cbType, CbTypeComponentRefService<T, S> callback); + + B cbi(CB cbType, CbService<S> callback); + B cbi(CB cbType, CbServiceMap<S> callback); + B cbi(CB cbType, CbServiceDict<S> callback); + B cbi(CB cbType, CbRef<S> callback); + B cbi(CB cbType, CbRefService<S> callback); + B cbi(CB cbType, CbComponent callback); + B cbi(CB cbType, CbComponentService<S> callback); + B cbi(CB cbType, CbComponentServiceMap<S> callback); + B cbi(CB cbType, CbComponentServiceDict<S> callback); + B cbi(CB cbType, CbComponentRef<S> callback); + B cbi(CB cbType, CbComponentRefService<S> callback); + + <T> B sw(CbTypeServiceService<T, S> swap); + <T> B sw(CbTypeRefServiceRefService<T, S> swap); + <T> B sw(CbTypeMapServiceMapService<T, S> swap); + <T> B sw(CbTypeDictServiceDictService<T, S> swap); + B swi(CbServiceService<S> swap); + B swi(CbRefServiceRefService<S> swap); + B swi(CbMapServiceMapService<S> swap); + B swi(CbDictServiceDictService<S> swap); + // TODO add more swap signatures with Component param. } Modified: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ServiceDependencyBuilder.java URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ServiceDependencyBuilder.java?rev=1724333&r1=1724332&r2=1724333&view=diff ============================================================================== --- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ServiceDependencyBuilder.java (original) +++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/ServiceDependencyBuilder.java Tue Jan 12 22:45:36 2016 @@ -6,53 +6,53 @@ import org.osgi.framework.ServiceReferen /** * Defines a Service dependency. Dependency callbacks can be defined using method like (like in DependencyManager), or using method references. * - * @param <T> the type of the service dependency + * @param <S> the type of the service dependency */ -public interface ServiceDependencyBuilder<T> extends DependencyBuilder<ServiceDependency>, ServiceCallbacksBuilder<T, ServiceDependencyBuilder<T>> { +public interface ServiceDependencyBuilder<S> extends DependencyBuilder<ServiceDependency>, ServiceCallbacksBuilder<S, ServiceDependencyBuilder<S>> { /** * Configures the service dependency filter * @param filter the service filter * @return this builder */ - ServiceDependencyBuilder<T> filter(String filter); + ServiceDependencyBuilder<S> filter(String filter); /** * Configures this dependency with the given ServiceReference. * @param ref the service reference * @return this builder */ - ServiceDependencyBuilder<T> ref(ServiceReference<T> ref); + ServiceDependencyBuilder<S> ref(ServiceReference<S> ref); /** * Configures this dependency as required. By default, a dependency is required. * @return this builder */ - ServiceDependencyBuilder<T> required(); + ServiceDependencyBuilder<S> required(); /** * Configures whether this dependency is required or not. * @return this builder */ - ServiceDependencyBuilder<T> required(boolean required); + ServiceDependencyBuilder<S> required(boolean required); /** * Configures debug mode * @param label the label used by debug messages * @return this builder */ - ServiceDependencyBuilder<T> debug(String label); + ServiceDependencyBuilder<S> debug(String label); /** * Propagates the dependency properties to the component service properties. * @return this builder */ - ServiceDependencyBuilder<T> propagate(); + ServiceDependencyBuilder<S> propagate(); /** * Configures whether the dependency properties must be propagated or not to the component service properties. * @return this builder */ - ServiceDependencyBuilder<T> propagate(boolean propagate); + ServiceDependencyBuilder<S> propagate(boolean propagate); /** * Configures a method that can is called in order to get propagated service properties. @@ -62,12 +62,12 @@ public interface ServiceDependencyBuilde * @param method the method name to call on the object instance. This method returns the propagated service properties. * @return this builder */ - ServiceDependencyBuilder<T> propagate(Object instance, String method); + ServiceDependencyBuilder<S> propagate(Object instance, String method); /** * Sets the default implementation if the service is not available. * @param defaultImpl the implementation used by default when the service is not available. * @return this builder */ - ServiceDependencyBuilder<T> defImpl(Object defaultImpl); + ServiceDependencyBuilder<S> defImpl(Object defaultImpl); } \ No newline at end of file Added: felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/impl/AdapterBase.java URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/impl/AdapterBase.java?rev=1724333&view=auto ============================================================================== --- felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/impl/AdapterBase.java (added) +++ felix/sandbox/pderop/dependencymanager-lambda/org.apache.felix.dependencymanager.lambda/src/org/apache/felix/dm/builder/lambda/impl/AdapterBase.java Tue Jan 12 22:45:36 2016 @@ -0,0 +1,213 @@ +package org.apache.felix.dm.builder.lambda.impl; + +import java.util.Dictionary; +import java.util.concurrent.CompletableFuture; +import java.util.function.BiConsumer; +import java.util.function.Consumer; + +import org.apache.felix.dm.Component; +import org.apache.felix.dm.builder.lambda.BundleDependencyBuilder; +import org.apache.felix.dm.builder.lambda.ComponentBuilder; +import org.apache.felix.dm.builder.lambda.ComponentBuilderBase; +import org.apache.felix.dm.builder.lambda.ConfigurationDependencyBuilder; +import org.apache.felix.dm.builder.lambda.Functions.CbComponent; +import org.apache.felix.dm.builder.lambda.Functions.FluentProperties; +import org.apache.felix.dm.builder.lambda.FutureDependencyBuilder; +import org.apache.felix.dm.builder.lambda.ServiceDependencyBuilder; + +/** + * Methods common to extended components like adapters or aspects. + * + * TODO javadoc + */ +@SuppressWarnings({"unchecked"}) +public interface AdapterBase<T, B extends ComponentBuilderBase<T, B>> extends ComponentBuilderBase<T, B> { + + void andThenBuild(Consumer<ComponentBuilder<T>> builder); + + default B provides(Class<?> ... ifaces) { + andThenBuild(compBuilder -> compBuilder.provides(ifaces)); + return (B) this; + } + + default B provides(String ... ifaces) { + andThenBuild(compBuilder -> compBuilder.provides(ifaces)); + return (B) this; + } + + default B properties(Dictionary<?, ?> properties) { + andThenBuild(compBuilder -> compBuilder.properties(properties)); + return (B) this; + } + + default B properties(String name, Object value, Object ... rest) { + andThenBuild(compBuilder -> compBuilder.properties(name, value, rest)); + return (B) this; + } + + default B properties(FluentProperties ...properties) { + andThenBuild(compBuilder -> compBuilder.properties(properties)); + return (B) this; + } + + default B withService(Class<?> service, Class<?> ... services) { + andThenBuild(compBuilder -> compBuilder.withService(service, services)); + return (B) this; + } + + default <U> B withService(Class<U> service, Consumer<ServiceDependencyBuilder<U>> consumer) { + andThenBuild(compBuilder -> compBuilder.withService(service, consumer)); + return (B) this; + } + + default B withConfiguration(Consumer<ConfigurationDependencyBuilder<T>> consumer) { + andThenBuild(compBuilder -> compBuilder.withConfiguration(consumer)); + return (B) this; + } + + default B withBundle(Consumer<BundleDependencyBuilder<T>> consumer) { + andThenBuild(compBuilder -> compBuilder.withBundle(consumer)); + return (B) this; + } + + default <U> B withFuture(CompletableFuture<U> future, Consumer<FutureDependencyBuilder<T, U>> consumer) { + andThenBuild(compBuilder -> compBuilder.withFuture(future, consumer)); + return (B) this; + } + + default B init(Consumer<T> callback) { + andThenBuild(compBuilder -> compBuilder.init(callback)); + return (B) this; + } + + default B init(BiConsumer<T, Component> callback) { + andThenBuild(compBuilder -> compBuilder.init(callback)); + return (B) this; + } + + default B init(Runnable callback) { + andThenBuild(compBuilder -> compBuilder.init(callback)); + return (B) this; + } + + default <U> B init(Class<U> type, Consumer<U> callback) { + andThenBuild(compBuilder -> compBuilder.init(type, callback)); + return (B) this; + } + + default <U> B init(Class<U> type, BiConsumer<U, Component> callback) { + andThenBuild(compBuilder -> compBuilder.init(type, callback)); + return (B) this; + } + + default B init(CbComponent callback) { + andThenBuild(compBuilder -> compBuilder.init(callback)); + return (B) this; + } + + default B start(Consumer<T> callback) { + andThenBuild(compBuilder -> compBuilder.start(callback)); + return (B) this; + } + + default B start(BiConsumer<T, Component> callback) { + andThenBuild(compBuilder -> compBuilder.start(callback)); + return (B) this; + } + + default <U> B start(Class<U> type, Consumer<U> callback) { + andThenBuild(compBuilder -> compBuilder.start(type, callback)); + return (B) this; + } + + default <U> B start(Class<U> type, BiConsumer<U, Component> callback) { + andThenBuild(compBuilder -> compBuilder.start(type, callback)); + return (B) this; + } + + default B start(Runnable callback) { + andThenBuild(compBuilder -> compBuilder.start(callback)); + return (B) this; + } + + default B start(CbComponent callback) { + andThenBuild(compBuilder -> compBuilder.init(callback)); + return (B) this; + } + + default B stop(Consumer<T> callback) { + andThenBuild(compBuilder -> compBuilder.stop(callback)); + return (B) this; + } + + default B stop(BiConsumer<T, Component> callback) { + andThenBuild(compBuilder -> compBuilder.stop(callback)); + return (B) this; + } + + default <U> B stop(Class<U> type, Consumer<U> callback) { + andThenBuild(compBuilder -> compBuilder.stop(type, callback)); + return (B) this; + } + + default <U> B stop(Class<U> type, BiConsumer<U, Component> callback) { + andThenBuild(compBuilder -> compBuilder.stop(type, callback)); + return (B) this; + } + + default B stop(Runnable callback) { + andThenBuild(compBuilder -> compBuilder.stop(callback)); + return (B) this; + } + + default B stop(CbComponent callback) { + andThenBuild(compBuilder -> compBuilder.init(callback)); + return (B) this; + } + + default B destroy(Consumer<T> callback) { + andThenBuild(compBuilder -> compBuilder.destroy(callback)); + return (B) this; + } + + default B destroy(BiConsumer<T, Component> callback) { + andThenBuild(compBuilder -> compBuilder.destroy(callback)); + return (B) this; + } + + default <U> B destroy(Class<U> type, Consumer<U> callback) { + andThenBuild(compBuilder -> compBuilder.destroy(type, callback)); + return (B) this; + } + + default <U> B destroy(Class<U> type, BiConsumer<U, Component> callback) { + andThenBuild(compBuilder -> compBuilder.destroy(type, callback)); + return (B) this; + } + + default B destroy(Runnable callback) { + andThenBuild(compBuilder -> compBuilder.destroy(callback)); + return (B) this; + } + + default B destroy(CbComponent callback) { + andThenBuild(compBuilder -> compBuilder.init(callback)); + return (B) this; + } + + default <U> B autoInject(Class<U> clazz, boolean autoConfig) { + andThenBuild(compBuilder -> compBuilder.autoInject(clazz, autoConfig)); + return (B) this; + } + + default <U> B autoInject(Class<U> clazz, String field) { + andThenBuild(compBuilder -> compBuilder.autoInject(clazz, field)); + return (B) this; + } + + default B debug(String label) { + andThenBuild(compBuilder -> compBuilder.debug(label)); + return (B) this; + } + +}
