[ 
https://issues.apache.org/jira/browse/FELIX-4689?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15062443#comment-15062443
 ] 

Pierre De Rop edited comment on FELIX-4689 at 12/18/15 7:35 AM:
----------------------------------------------------------------

Added a new "properties(FluentProperty ... properties)" method in 
ComponentBuilder. This method allows to define component service properties 
using a lambda expression and each property name is deduced from the lambda 
parameter name.
Using this new method requires the usage of the "-parameters" javac option, and 
under eclipse, the "Store information of about method parameters" compiler 
option must be enabled.

Sample code when using fluent properties:

{code}
        component(comp -> comp
            .properties(foo -> "bar", gabu -> "zo") // property names are 
deduced from lambda parameter name
            .provides(ServiceProvider.class)
            .impl(ServiceProviderImpl.class)
            .withService(LogService.class, srv -> 
srv.onAdd(ServiceProviderImpl::bind)));
{code}

Here the "ServiceProvider" service component is provided using the "foo=bar" 
and "gabu=zo" properties ("foo" is deduced from the lambda parameter name : foo 
-> "bar", etc ...)



was (Author: pderop):
Added a new "properties(FluentProperty ... properties)" method in 
ComponentBuilder. This method allows to define component service properties 
using a lambda expression and each property name is deduced from the lambda 
parameter name.
Using this new method requires the usage of the "-parameters" javac option, and 
under eclipse, the "Store information of about method parameters" compiler 
option must be enabled.

Sample code when using fluent properties:

{code}
        component(comp -> comp
            .provides(ServiceProvider.class)
            .onStart(ServiceProviderImpl::activate)
            .properties(foo -> "bar", gabu -> "zo") // property names are 
deduced from lambda parameter name
            .impl(ServiceProviderImpl.class)
            .withService(LogService.class, srv -> 
srv.onAdd(ServiceProviderImpl::bind)));
{code}

Here the "ServiceProvider" service component is provided using the "foo=bar" 
and "gabu=zo" properties ("foo" is deduced from the lambda parameter name : foo 
-> "bar", etc ...)


> Create a more fluent syntax for the dependency manager builder
> --------------------------------------------------------------
>
>                 Key: FELIX-4689
>                 URL: https://issues.apache.org/jira/browse/FELIX-4689
>             Project: Felix
>          Issue Type: Improvement
>          Components: Dependency Manager
>            Reporter: Christian Schneider
>         Attachments: FELIX-4689-1.patch
>
>
> I wonder if the DependencyManager API could be made a bit more fluent.
> Technically it already uses the fluent builder pattern
> but all the builder verbs still look a lot like traditional setters.
> I know what I propose is mostly syntactic sugar but I think the result
> looks more readable and crisp. See below for some ideas.
> There is the concern about auto adding the component() to manager as it would 
> acrivate the not fully configured component. We could perhaps overcome this 
> by adding the component to a list of pending components first and then moving 
> them to the active components after the init method.
> The camel DSL solves this similarly.
> This is from samples.dependonservice:
>     public void init(BundleContext context, DependencyManager manager)
> throws Exception {
>         manager.add(createComponent()
>             .setImplementation(DataGenerator.class)
>             .add(createServiceDependency()
>                 .setService(Store.class)
>                 .setRequired(true)
>             )
>             .add(createServiceDependency()
>                 .setService(LogService.class)
>                 .setRequired(false)
>             )
>         );
>     }
> Why not make it look like this:
>     public void init(BundleContext context, DependencyManager manager)
> throws Exception {
>         component()
>             .implementation(DataGenerator.class)
>             .add(serviceDependency(Store.class).required())
>             .add(serviceDependency(LogService.class))
>             );
>         );
>     }
> component() could create and add the component.
> Or for configuration:
>     public void init(BundleContext context, DependencyManager manager)
> throws Exception {
>         manager.add(createComponent()
>             .setImplementation(Task.class)
>             .add(createConfigurationDependency()
>                 .setPid("config.pid")
>                 // The following is optional and allows to display our
> configuration from webconsole
>                 .setHeading("Task Configuration")
>                 .setDescription("Configuration for the Task Service")
>                 .add(createPropertyMetaData()
>                      .setCardinality(0)
>                      .setType(String.class)
>                      .setHeading("Task Interval")
>                      .setDescription("Declare here the interval used to
> trigger the Task")
>                      .setDefaults(new String[] {"10"})
>                      .setId("interval"))));
>     }
> could be:
>     public void init(BundleContext context, DependencyManager manager)
> throws Exception {
>         component().implementation(Task.class)
>             .configuration("config.pid")
>                 .add(meta("Task Configuration)
>                     .description("Configuration for the Task Service")
>                     .add(property("interval")
>                             .cardinality(0)
>                             .type(String.class)
>                             .heading("Task Interval")
>                             .description("Declare here the interval used
> to trigger the Task")
>                             .default("10"))
>     }



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to