Return-Path: X-Original-To: apmail-incubator-any23-dev-archive@minotaur.apache.org Delivered-To: apmail-incubator-any23-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 81BDCDF41 for ; Fri, 10 Aug 2012 22:09:15 +0000 (UTC) Received: (qmail 46101 invoked by uid 500); 10 Aug 2012 22:09:15 -0000 Delivered-To: apmail-incubator-any23-dev-archive@incubator.apache.org Received: (qmail 46052 invoked by uid 500); 10 Aug 2012 22:09:15 -0000 Mailing-List: contact any23-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: any23-dev@incubator.apache.org Delivered-To: mailing list any23-dev@incubator.apache.org Received: (qmail 46042 invoked by uid 99); 10 Aug 2012 22:09:15 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Aug 2012 22:09:15 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of ansell.peter@gmail.com designates 74.125.82.43 as permitted sender) Received: from [74.125.82.43] (HELO mail-wg0-f43.google.com) (74.125.82.43) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Aug 2012 22:09:07 +0000 Received: by wgbdr1 with SMTP id dr1so1566849wgb.0 for ; Fri, 10 Aug 2012 15:08:47 -0700 (PDT) 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=QYbyjzk9C7y0Tu2U7sWfX+rh6OYtvRq8B7DRZgf+jlI=; b=RRZ7UIeZ7esBZQ92Y4uSjbDt4jnm9+2sjETYx/G+3yRNdxPdE2MwIK74bslIHNSR06 1VMBstSKHSMDCUujiNpBtgTaKordil8M05Vt0iaQ+ny6r5gptc7ccgtu+X2UdQ9PTC1i kVHbLXUWHVLV95svoYJJuTET+2kJSrX1c8SAeN89Ou5U7qGVGl6PiybyFQVG/yA3dHYM c85YL819iZT5EtQAzd0Znf2f6G7vEwvgde5uXBRELGNSteTlzbB1JUPJ/aKTJUr56HS7 X0uKTk9GKjTgQXSrNJRiPw5PuuIaI0JAmxqmQJs4JEWhvJBOe7iREia9CvkwSLI78eDb HLow== MIME-Version: 1.0 Received: by 10.180.79.69 with SMTP id h5mr9111969wix.6.1344636527032; Fri, 10 Aug 2012 15:08:47 -0700 (PDT) Received: by 10.216.198.167 with HTTP; Fri, 10 Aug 2012 15:08:46 -0700 (PDT) In-Reply-To: References: Date: Sat, 11 Aug 2012 08:08:46 +1000 Message-ID: Subject: Re: Any23 Modularization From: Peter Ansell To: any23-dev@incubator.apache.org Content-Type: text/plain; charset=UTF-8 On 10 August 2012 19:16, Simone Tripodi wrote: >> There is at least one statement in that code that I don't think is >> true in my experience. The author of that JSR says that "Service >> locators decouple even further but reduce compile time type safety". I >> am not sure what service locators they have been using, but >> java.util.ServiceLoader is definitely typesafe, especially if you use >> it with a Factory interface instead of using reflection to instantiate >> the object manually. In my experience using java.util.ServiceLoader on >> my own projects and in my work with OWLAPI, I have found that you can >> have a typesafe plugin system quite easily without relying on a >> dependency injection system to do it for you. >> > > they are not indeed the same kind of service locators, and the one you > are referring is definitely NOT typesafe because in > META-INF/services/com.acme.Interface definition you are free to > specify a class which doesn't implement com.acme.Interface - and you > can find that misconfiguration at *runtime* only. > > Modern DI framework allows specify typesafe services in a pure java > config which is checked at *compile* time. The purpose of service locators in my experience is to decouple services so that they are explicitly not required at compile time. It depends whether you want arbitrary sets of services, or just a single place to define specific singleton/global services as to whether you would find it useful to specify services in a compiled java file or in a configuration file. ServiceLoader is not designed to be a configuration framework to define specific services, but it is great if you want to use any and all services that are available. >From what I can tell, in Any23 we want to load up any and all services that are available at runtime and the user will specify which one they want to use with an identifier or MIME-Type, so ServiceLoader fits that purpose in my view. > FYI, ServiceLoader is already in use in Any23 to load plugins and > META-INF/services files are generated at compile time via the metainf > library developed by Kohsuke (the Jenkin's guy). Anyway, we've had a > broken test anyway, due to misconfigurations in META-INF/services :) > >> However I don't mind if you want to put in JSR-330 annotations in the >> apprpriate places. I am just wary of cases when a library forces you >> to use dynamic dependency injection and either makes it very hard or >> impossible to do it using a plain-old-java way. As long as the code >> doesn't lock things down by doing things like creating private fields >> with no accessors or mutators except for DI magic, I am fine with it. >> Personally, I don't mind maintaining Factories as I am going to be >> using them myself, since I don't generally use DI, and using Open >> Source code I am free to create the factories if they don't exist. >> > > I never mentioned adopting a specific framework that forces us on > writing stuff according to its rule, just referenced to the JRS. > > Factories are still fine, but not how they are used in the current > codebase - they often get me feel lost while reviewing before the > release. In the api patch I tried to reduce the confusion, particularly removing the use of Class.getConstructor in WriterRegistry and replacing it with a factory. There are two FIXME notes in the patch where I would like to remove hardcoded factories and format identifiers. Cheers, Peter