Return-Path: X-Original-To: apmail-felix-dev-archive@www.apache.org Delivered-To: apmail-felix-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CB75A10BD2 for ; Mon, 10 Nov 2014 23:41:40 +0000 (UTC) Received: (qmail 93393 invoked by uid 500); 10 Nov 2014 23:41:40 -0000 Delivered-To: apmail-felix-dev-archive@felix.apache.org Received: (qmail 93321 invoked by uid 500); 10 Nov 2014 23:41:40 -0000 Mailing-List: contact dev-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list dev@felix.apache.org Received: (qmail 93309 invoked by uid 99); 10 Nov 2014 23:41:40 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Nov 2014 23:41:40 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of pierre.derop@gmail.com designates 209.85.217.172 as permitted sender) Received: from [209.85.217.172] (HELO mail-lb0-f172.google.com) (209.85.217.172) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Nov 2014 23:41:14 +0000 Received: by mail-lb0-f172.google.com with SMTP id w7so6830000lbi.3 for ; Mon, 10 Nov 2014 15:39:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=Ac7rZTohUTN8Clu7QGPJL8HTLDk8pC1y49yw2hlLpfo=; b=JmxX9xO2mPOsnKQr+lBFgTCtgHdujlur45jrFDl+i+GDV42rhQxEduz1VujgPg2h9e 06JzASqGfEA6R3xq4LMlLzKOa34QVOs65xLz+R9D3VKXGj7SAOrPO32WxRJCnvwuqb96 hYSdlee6P6ehui/Bi1ImK04CouLvhenUzdXned+aDMOOAk3RaVlGcqmCpByhp4ywvBA+ wTRwDrwQhrURUm3pGlGcNjmZnFFY4MVg+II4Cc+kRN4KxwtRxKchniJTByG7DrksbHAX N1vJvThVnnLiiN3hOH+vF0GKesI4LDQ0jGvgMfVcbNdambt0G024fuQnJA9KE3OJR7to dMDQ== MIME-Version: 1.0 X-Received: by 10.152.179.67 with SMTP id de3mr32637123lac.73.1415662783586; Mon, 10 Nov 2014 15:39:43 -0800 (PST) Received: by 10.114.98.10 with HTTP; Mon, 10 Nov 2014 15:39:43 -0800 (PST) In-Reply-To: <54609622.6070206@die-schneider.net> References: <54609622.6070206@die-schneider.net> Date: Tue, 11 Nov 2014 00:39:43 +0100 Message-ID: Subject: Re: Make DependencyManager API more fluent? From: Pierre De Rop To: "dev@felix.apache.org" Content-Type: multipart/alternative; boundary=001a11342aea5669bb050789ada8 X-Virus-Checked: Checked by ClamAV on apache.org --001a11342aea5669bb050789ada8 Content-Type: text/plain; charset=UTF-8 Hello Christian; The improvements you are proposing would require a major version bump since it's an incompatible API change. But I personally like what you are suggesting, and I could quickly do it in the upcoming Dependency Manager 4.0.0, which is a new major version. But before, I need to know if Marcel is agree to go ahead with all this; so for the moment, may be you can just create a Jira issue, and let's wait for Marcel to see if he's OK. Just one remark: the setters can be easily removed, however I think we can't manage to make the "component()" method automatically add the Component to the DependencyManager, because technically; when you add a Component to a DependencyManager, the Component is actually *activated*, and at this point, all the necessary dependencies have to be already in place. So, the only possible improvement I'm thinking about for now could have the form of this: public void init(BundleContext context, DependencyManager manager) throws Exception { component() .implementation(DataGenerator.class) .add(serviceDependency(Store.class).required()) .add(serviceDependency(LogService.class)) .addTo(manager); } (notice the addTo method at the end of the sample above, which could just add the fully built component to the DependencyManager "manager" object). but I propose you first create the Jira issue and see what Marcel thinks. I will possible add more suggestions in your Jira issue once you will have created it (like also using a builder pattern for the aspects/adapters: this would allow to reduce the number of method signatures for the createAdapter/createAspect methods). kind regards (and thanks for proposing to improve Dependency Manager :-)) /Pierre On Mon, Nov 10, 2014 at 11:40 AM, Christian Schneider < chris@die-schneider.net> wrote: > 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. > > Christian > > ---- > > 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")) > } > > -- > Christian Schneider > http://www.liquid-reality.de > > Open Source Architect > http://www.talend.com > > --001a11342aea5669bb050789ada8--