commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Howard M. Lewis Ship" <hls...@comcast.net>
Subject RE: [HiveMind] Extension to adder example
Date Wed, 17 Sep 2003 11:20:51 GMT
Right on the money ... except that I probably would not both defining the service model for
Adder
and Subtractor; the default ("deferred") is less efficient, but less trouble as well. Making
those
services singletons (rather than deferred singletons) is a premature optimization.

--
Howard M. Lewis Ship
Creator, Tapestry: Java Web Components
http://jakarta.apache.org/tapestry
http://jakarta.apache.org/commons/sandbox/hivemind/
http://javatapestry.blogspot.com

> -----Original Message-----
> From: Harish Krishnaswamy [mailto:hkrishnaswamy@comcast.net] 
> Sent: Tuesday, September 16, 2003 7:31 PM
> To: Jakarta Commons Developers List
> Subject: Re: [HiveMind] Extension to adder example
> 
> 
> You wouldn't believe, I had done the very same thing except 
> called it a 
> Calculator!
> 
> Here are my modules...
> 
> Service point module:
> 
> <?xml version="1.0"?>
> 
> <module id="hivemind.examples" version="1.0.0">
> 
>   <service id="Adder" interface="hivemind.examples.Adder" 
> model="singleton"/>
> 
>   <service id="Subtracter" interface="hivemind.examples.Subtracter" 
> model="singleton"/>
>  
>   <service id="Calculator" interface="hivemind.examples.Calculator" 
> model="singleton">
>     <invoke-factory service-id="hivemind.BuilderFactory">
>         <construct
>             class="hivemind.examples.impl.CalculatorImpl">
>            
>             <set-service property="adder" service-id="Adder"/>
>             <set-service property="subtracter" 
> service-id="Subtracter"/>
>         </construct>
>     </invoke-factory>
>   </service>
> 
> </module>
> 
> Service module:
> <?xml version="1.0"?>
> 
> <module id="hivemind.examples.impl" version="1.0.0">
> 
>   <extend-service service-id="hivemind.examples.Adder">
>       <create-instance class="hivemind.examples.impl.AdderImpl"/>
>   </extend-service>
> 
>   <extend-service service-id="hivemind.examples.Subtracter">
>       <create-instance class="hivemind.examples.impl.SubtracterImpl"/>
>   </extend-service>
> 
> </module>
> 
> Client module:
> <?xml version="1.0"?>
> 
> <module id="hivemind.examples.log" version="1.0.0">
> 
>   <extend-service service-id="hivemind.examples.Adder">
>     <interceptor service-id="hivemind.LoggingInterceptor" order="10"/>
>   </extend-service>
> 
> </module>
> 
> And the rest is Hivemind! I am really liking it a lot. I 
> can't wait for 
> Tapestry 3.1!
> 
> -Harish
> 
> Bill Lear wrote:
> 
> >What I'd like to do is to define a service analogous to the Adder, 
> >Subtracter.
> >
> >Then, I'd like to define a service, Math that uses the Adder and 
> >Subtracter modules to provide the following interface:
> >
> >public interface Math {
> >    int add(int arg0, int arg1);
> >    int subtract(int arg0, int arg1);
> >}
> >
> >with implementation:
> >
> >package hivemind.examples.impl;
> >
> >import hivemind.examples.Math;
> >import hivemind.examples.Adder;
> >import hivemind.examples.Subtracter;
> >
> >public class MathImpl implements Math {
> >    private Adder adder;
> >
> >    public void setAdder(Adder adder) {
> >        this.adder = adder;
> >    }
> >
> >    private Subtracter subtracter;
> >
> >    public void setSubtracter(Subtracter subtracter) {
> >        this.subtracter = subtracter;
> >    }
> >
> >    public int add(int arg0, int arg1) {
> >        return adder.add(arg0, arg1);
> >    }
> >
> >    public int subtract(int arg0, int arg1) {
> >        return subtracter.add(arg0, arg1);
> >    }
> >}
> >
> >and call it from code thus (after appropriate registry construction,
> >etc.):
> >
> >        Math math = (Math) 
> registry.getService("hivemind.examples.Math",
> >                                               Math.class);
> >
> >        System.out.println("Result of add: " + math.add(arg0, arg1));
> >        System.out.println("Result of subtract: " + 
> math.subtract(arg0, 
> > arg1));
> >
> >I'm a bit confused as to how to tie all of this together.  Could 
> >someone provide some pointers?
> >
> >Thanks.
> >
> >
> >Bill
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> >
> >
> >  
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 


Mime
View raw message