You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hivemind.apache.org by Andrei Chiritescu <an...@netrom.ro> on 2005/10/05 10:38:04 UTC

injecting sevices

Do you know whether hivemind contains a method to get an instance from a 
specific class (given the classname), which then does all the 
autowiring? I would just like to get a class instance based on 
classname, so that an entry in hivemodule is not necessary.

I there a method to get an instance of a specific class (given the fully 
qualified classname) that is managed by Hivemind(has the services 
injected) without having to add an entry in the hivemodule descriptor?
Basically what I have is a "Controller" service (declared in the xml 
module) and a lot of Device classes which require the Controller. What I 
want is to get a instance of Device class that has the Controller class 
wired (injected by hivemind) without adding the Device service in the 
xml descriptor.

Is this possible?

Regards,
Andrei Chiritescu


---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-user-help@jakarta.apache.org


Re: injecting sevices

Posted by adasal <ad...@gmail.com>.
Andrei
"When you say "In *any* class" I think mean any Tapestry class (one
which extends BasePage or BaseComponent ) which has a IPostcodeTO
property. In this case I'm afraid that the IPostcodeTO is not injected
by Hivemind in that class (I think Tapestry handles that)."
I don't think that it is handled by Tapestry. Although this is used in a
Tapestry component that is in a tapestry page the unit test tests it outside
of the Tapestry context. None of the objects inherit from BasePage or
BaseComponent in these unit tests. So I think this shows that what you want
to do should be possible.
If I get time I will look at this further.
Adam

On 10/7/05, Andrei Chiritescu <an...@netrom.ro> wrote:
>
> Hi Adam, thanks for your the answers, but none of the solution will work
> for me.
> In the first case you present something that resembles with inheritance
> between elements which is not good since I don t what to modify the xml
> for each new class.
> At the second case you said :
>
> >In *any* class I may write:-
> >public abstract IPostcodeTO getIPostcodeTO();
>
> When you say "In *any* class" I think mean any Tapestry class (one
> which extends BasePage or BaseComponent ) which has a IPostcodeTO
> property. In this case I'm afraid that the IPostcodeTO is not injected
> by Hivemind in that class (I think Tapestry handles that).
> However the problem is that my code does not work over a tapestry
> framework, so....
>
> The problem that I have is very simple (I think) and I would look for a
> simple solution.
> I have one service A declared in the xml module. Now I would like to
> know how to get an instance of any class(at runtime, so the class is not
> known at compile thus no way to set it in the xml module) which has a
> setter like "void setA(A a)" to have the service A injected.
>
> Here is a more complete code:
> - as I have said before I have a module declared like(AAA is any given
> class) :
> /<module id="app" version="1.0.0" package="app">
> <service-point id="AAA" interface="app.AAA">
> <invoke-factory model="singleton">
> <construct class="app.AAA"/>
> </invoke-factory>
> </service-point>
> </module>/
>
> - and an interface like:
>
> interface BBB {
> void setAAA(AAA aaa);
> }
>
> - and in another class something like
>
> AAA aaa = ... an instance of the AAA class
> String className= ... provided at run time - the name of a class that
> implements the BBB interface
> Class bbbClass;
> BBB bbbInstance;
> try{
> bbbClass= Thread.currentThread().getContextClassLoader().loadClass(
> className );
> bbbInstance= (BBB ) bbbClass.newInstance();
> bbbInstance.setAAA( this );
> }catch ( Exception e )
> {/*error*/}
>
> - What I would like is to replace the code between the try/catch with
> some hivemind one. So the end result will look like :
>
> AAA aaa = ... an instance of the AAA class
> String className= ... provided at run time - the name of a class that
> implements the BBB interface
> Class bbbClass;
> BBB bbbInstance;
> try{
> bbbClass= Thread.currentThread().getContextClassLoader().loadClass(
> className );
> bbbInstance= hivemindRegistry.getManagedInstance (bbbClass);
> }catch ( Exception e )
> {/*error*/}
>
> So, basically, I what hivemind to create the instance and inject an AAA
> instance into my bbbClass, instead of doing it manually.
>
> Does anyone have a practical solution for this?
> I would appreciate if the solution would be exemplified on the given
> example :)
>
> Thanks for your help,
> Andrei
>
>
> adasal wrote:
>
> > In the application written by Shing Hing Man and myself we have:-
> > case 1:-
> > <VCompletedBooleanIfInList
> >
> > ognlPathValidate="ognlPath.toCondition.toCheck1.ifPreCon1.aValue"
> > ognlPathCondition="ognlPath.toPreCondition.toCheck1 "
> > errorMessage="${uniqueMessageID1}"
> > enumType="@OGNLpath@ENUM"/>
> >
> >
> > <VCompletedDoubleIfBoolean
> >
> > ognlPathValidate=" ognlPath.toCondition.toCheck2.ifPreCon2.aValue"
> > ognlPathCondition="ognlPath.toPreCondition.toCheck2"
> > errorMessage="${uniqueMessageID2}"/>
> > but note we are reussing VCompletedDoubleIfBoolean defined in the
> > schema like this:-
> > <element name="VCompletedDateIfBoolean"> If ognlPathCondition is true,
> > ognlpathValidate must not be null. Otherwise, there is no
> > validation on
> > ognlpathValidate.
> > <attribute name="ognlPathValidate" required="true"> An
> > ErroredDate.
> > </attribute>
> > <attribute name="ognlPathCondition" required="true"> An
> > ErroredBoolean.
> > </attribute>
> > <attribute name="errorMessage" required="true"/>
> > <conversion
> >
> > class="com.pathto.baseclass.usedin.validation.VCompletedDateIfBoolean"/>
> > </element>
> > which retrieve the object we are interested in from the object tree,
> > and retrieves the values we need.
> > This entails necessary repetition in hivemodule. The issue would be
> > whether each case defined in hivemodule is really a seperate case.
> > It does become tedious, and perhaps confussing, to have a large
> > hivemodule, where many contributions are only subtly different.
> >
> > Case 2:-
> > Where a postcode lookup method in our Tapestry application interfaces
> > to a third party service we have found that some inputs cause the
> > service to hang (and, what is worse, would provoke the user to
> > multiple submits).
> > This is overcome (in part) by wrappling the calls in a timed window
> > that snaps shut before lengthy searches are made.
> > Hivemodule is useful here in setting global timeout properties,
> > although they shouldn't have to be changed since I have made a series
> > of emperical tests to determine a minimum window.
> > This seems to me to be a simple "controller".
> >
> > <!-- Threaded service to timeout when large searches are made with
> > incomplete data. model="threaded" -->
> > <service-point id="IPostcodeSearchTO"
> > interface="com.pathTo.search.service.wrapper.api.IPostcodeTO">
> > <invoke-factory model="threaded">
> > <construct
> > class="com.pathTo.search.service.wrapper.PostcodeSearchTOImpl ">
> > <set property="globalTimeout" value="4"/>
> > </construct>
> > </invoke-factory>
> > </service-point>
> >
> > with impl:-
> > public class PostcodeSearchTOImpl implements IPostcodeTO {
> > ..............
> > }
> > and interface :-
> > public interface IPostcodeTO {
> > public int getIPostcodeSearchTO();
> > public void setIPostcodeSearchTO(int globalTimeout);
> > public boolean isTimedOut();
> >
> > }
> >
> > In *any* class I may write:-
> > public abstract IPostcodeTO getIPostcodeTO();
> > .............
> > //in this case the calling client method is in our impl of Tapestry
> > public void updateAddressResults(IRequestCycle cycle) {
> > ................
> > //the value set in hivemodule
> > IPostcodeTO globalTimeout = getIPostcodeTO();
> >
> > //the value used in this instance can be reset, because it is a time
> > derived from the system in milliseconds, I start it now
> > globalTimeout.setIPostcodeSearchTO(globalTimeout.getIPostcodeSearchTO
> ());
> >
> > make calls to object(s).method(s) that use the properties set
> > ......................
> > }
> > }
> > The service client is in any class, as usual with private class
> > instance of the interface type.
> >
> > I think that covers what you are refering to?
> > Adam
> >
> > On 10/5/05, *Andrei Chiritescu* <andreic@netrom.ro
> > <ma...@netrom.ro>> wrote:
> >
> > > Contoller will be IController and ControllerImpl. Device will
> > > implement IController. All that is configured in HiveModule is the
> > > service defining Controller, it's methods and instantiated
> > values will
> > > be available to Device. Is this what you mean?
> >
> > Not quite. Let me try to explain my situation better.
> > I have a module like :
> > /<module id="app" version="1.0.0" package="app">
> > <service-point id="Controller" interface="app.Controller ">
> > <invoke-factory model="singleton">
> > <construct class="app.Controller"/>
> > </invoke-factory>
> > <interceptor service-id="hivemind.LoggingInterceptor"/>
> > </service-point>
> > </module>/
> >
> > and the Controller.class:
> > /package app;
> > class Controller
> > {
> > /* implementaion is not important */
> > }
> >
> > and I also have a Device class:
> > //package app;
> > class //Device /
> > / {
> > private Controller controller;
> > public void setController( Controller controller )
> > {
> > this.controller = controller;
> > }
> > }
> > /
> > Now , what I would like is to get a Device instance that will have the
> > controller injected into it. This without having to add a
> > /<service-point/> /for the Device into the xml descriptor module.
> > So, something like this should work(or anything similar) :
> > Registry registry = ....
> > Device device = (Device) registry.getService( /Device/.class );
> >
> > Basically I would like that for any given class to get its managed
> > instance (like the Device class in the example) without needing the
> > <service-point> declared.
> >
> > Thanks,
> > Andrei Chiritescu
> >
> >
> > adasal wrote:
> >
> > > Contoller will be IController and ControllerImpl. Device will
> > > implement IController. All that is configured in HiveModule is the
> > > service defining Controller, it's methods and instantiated
> > values will
> > > be available to Device. Is this what you mean?
> > > Or you can get an instance of the service :-
> > > Contoller registry.getService("app.IController",
> > > ControllerImpl..class)
> > > or do something like this:-
> > >
> > > public class XXXEngine extends BaseEngine {
> > > ....................
> > > protected Object createGlobal(RequestContext context) {
> > > HttpServletRequest request = context.getRequest();
> > >
> > > return HiveMindFilter.getRegistry(request);
> > > }
> > > used like e.g. this:-
> > >
> > > protected void cleanupAfterRequest(IRequestCycle cycle) {
> > > super.cleanupAfterRequest(cycle);
> > >
> > > Registry registry = (Registry) getGlobal();
> > > //which allows:-
> > > ISessionManager sessionManager = (ISessionManager)
> > > registry.getService(ISessionManager.class);
> > >
> > > .........
> > > What is being controlled here is access to a single session object,
> > > but your problems may be similar.
> > > Tapestry-3.0.3 hivemind-1.0.0
> > > Adam
> > >
> > > On 10/5/05, *Andrei Chiritescu* < andreic@netrom.ro
> > <ma...@netrom.ro>
> > > <mailto: andreic@netrom.ro <mailto: andreic@netrom.ro>>> wrote:
> > >
> > > Do you know whether hivemind contains a method to get an
> > instance
> > > from a
> > > specific class (given the classname), which then does all the
> > > autowiring? I would just like to get a class instance based on
> > > classname, so that an entry in hivemodule is not necessary.
> > >
> > > I there a method to get an instance of a specific class
> > (given the
> > > fully
> > > qualified classname) that is managed by Hivemind(has the
> > services
> > > injected) without having to add an entry in the hivemodule
> > > descriptor?
> > > Basically what I have is a "Controller" service (declared in
> > the xml
> > > module) and a lot of Device classes which require the
> > Controller.
> > > What I
> > > want is to get a instance of Device class that has the
> > Controller
> > > class
> > > wired (injected by hivemind) without adding the Device
> > service in the
> > > xml descriptor.
> > >
> > > Is this possible?
> > >
> > > Regards,
> > > Andrei Chiritescu
> > >
> > >
> > >
> > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > > hivemind-user-unsubscribe@jakarta.apache.org
> > <ma...@jakarta.apache.org>
> > > <mailto: hivemind-user-unsubscribe@jakarta.apache.org
> > <ma...@jakarta.apache.org>>
> > > For additional commands, e-mail:
> > > hivemind-user-help@jakarta.apache.org
> > <mailto:hivemind-user-help@jakarta.apache.org >
> > > <mailto: hivemind-user-help@jakarta.apache.org
> > <mailto:hivemind-user-help@jakarta.apache.org >>
> > >
> > >
> >
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: hivemind-user-help@jakarta.apache.org
>
>

Re: DAO

Posted by Juliano Junio Viana <ju...@logicstyle.com>.
Hi,
I am not using tapestry, but my application uses daos in the way you
describe.
If you don't need or don't care for declarative transaction control,
there is no need to use HiveTranse.
Just implement your DAOs as hivemind service points, and have them
injected (with auto wiring) on the classes that need them.
I prefer defining one interface for each DAO , but I don't think it's
required by hivemind 1.1 any longer.

Regards,
  - Juliano.

John Coleman wrote:

>We have a tapestry project where POJOs are directly using DAOs.
>
>Obviously we would like to implement these DAOs as services through
>hivemind, and ideally inject the service into the POJOs, rather than look
>them up.
>
>Has anyone a simple example of this, should we use hivetranse?
>
>TIA
>John
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: hivemind-user-help@jakarta.apache.org
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-user-help@jakarta.apache.org


Re: DAO

Posted by John Coleman <jo...@ntlworld.com>.
Thanks guys, I was really hoping for a nice simple but complete working
example, as I want to just hand this over to a junior programmer team. I'm
surprised if one is not available as this was one of the original drivers
behind Hivemind.

Maybe this question would be better on tapestry discussion?

John



---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-user-help@jakarta.apache.org


RE: DAO

Posted by James Carman <ja...@carmanconsulting.com>.
John,

You might want to check out my article
(http://www.theserverside.com/articles/article.tss?l=HivemindBuzz) for an
example of doing DAOs (I called them repositories) using HiveMind 1.1 and
Hibernate3.  Of course, the transactional control provided by HiveTranse is
a bit more sophisticated (you can demarcate transactional boundaries using
different transaction policies), but the framework that I used works just
fine for simpler projects.  If you want the current version of the source
code, let me know and I'll forward it to you individually.  It uses HSQLDB
so you don't have to set up a MySQL database.  Hope it helps!

James

-----Original Message-----
From: John Coleman [mailto:john.s.coleman@ntlworld.com] 
Sent: Tuesday, November 08, 2005 6:53 AM
To: hivemind-user@jakarta.apache.org
Subject: DAO

We have a tapestry project where POJOs are directly using DAOs.

Obviously we would like to implement these DAOs as services through
hivemind, and ideally inject the service into the POJOs, rather than look
them up.

Has anyone a simple example of this, should we use hivetranse?

TIA
John



---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-user-help@jakarta.apache.org


DAO

Posted by John Coleman <jo...@ntlworld.com>.
We have a tapestry project where POJOs are directly using DAOs.

Obviously we would like to implement these DAOs as services through
hivemind, and ideally inject the service into the POJOs, rather than look
them up.

Has anyone a simple example of this, should we use hivetranse?

TIA
John



---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-user-help@jakarta.apache.org


Re: injecting sevices

Posted by Andrei Chiritescu <an...@netrom.ro>.
Hi Adam, thanks for your the answers, but none of the solution will work 
for me.
In the first case you present something that resembles with inheritance 
between elements which is not good since I don t what to modify the xml 
for each new class.
At the second case you said :

 >In *any* class I may write:-
 >public abstract IPostcodeTO getIPostcodeTO();

When you say "In *any* class"  I think mean any Tapestry class (one 
which extends BasePage or BaseComponent ) which has a IPostcodeTO  
property. In this case I'm afraid that the IPostcodeTO is not injected 
by Hivemind in that class (I think Tapestry handles that).
However the problem is that my code does not work over a tapestry 
framework, so....

The problem that I have is very simple (I think) and I would look for a 
simple solution.
I have one service A declared in the xml module. Now I would like to 
know how to get an instance of any class(at runtime, so the class is not 
known at compile thus no way to set it in the xml module) which has a 
setter like "void setA(A a)" to have the service A injected.

Here is a more complete code:
- as I have said before I have a module declared like(AAA is any given 
class) :
/<module id="app" version="1.0.0" package="app">
    <service-point id="AAA" interface="app.AAA">
        <invoke-factory model="singleton">
            <construct class="app.AAA"/>
        </invoke-factory>
    </service-point>
</module>/

- and an interface like:

interface BBB {
 void setAAA(AAA aaa);
}

- and in another class something like

AAA aaa = ... an instance of the AAA class
String className= ... provided at run time - the name of a class that 
implements the BBB interface
Class bbbClass;
BBB bbbInstance;
try{
    bbbClass= Thread.currentThread().getContextClassLoader().loadClass( 
className );
    bbbInstance= (BBB ) bbbClass.newInstance();
    bbbInstance.setAAA( this );
}catch ( Exception e )
{/*error*/}
     
- What I would like is to replace the code between the try/catch with 
some hivemind one. So the end result will look like :

AAA aaa = ... an instance of the AAA class
String className= ... provided at run time - the name of a class that 
implements the BBB interface
Class bbbClass;
BBB bbbInstance;
try{
    bbbClass= Thread.currentThread().getContextClassLoader().loadClass( 
className );
    bbbInstance= hivemindRegistry.getManagedInstance(bbbClass);        
}catch ( Exception e )
{/*error*/}    

So, basically, I what hivemind to create the instance and inject an AAA 
instance into my bbbClass, instead of doing it manually.

Does anyone have a practical solution for this?
I would appreciate if the solution would be exemplified on the given 
example :)

Thanks for your help,
Andrei


adasal wrote:

> In the application written by Shing Hing Man and myself we have:-
> case 1:-
>         <VCompletedBooleanIfInList
>             
> ognlPathValidate="ognlPath.toCondition.toCheck1.ifPreCon1.aValue"
>             ognlPathCondition="ognlPath.toPreCondition.toCheck1"
>             errorMessage="${uniqueMessageID1}"
>             enumType="@OGNLpath@ENUM"/>
>        
>
>         <VCompletedDoubleIfBoolean
>             
> ognlPathValidate="ognlPath.toCondition.toCheck2.ifPreCon2.aValue"
>             ognlPathCondition="ognlPath.toPreCondition.toCheck2"
>             errorMessage="${uniqueMessageID2}"/>
> but note we are reussing VCompletedDoubleIfBoolean defined in the 
> schema like this:-
> <element name="VCompletedDateIfBoolean"> If ognlPathCondition is true,
>             ognlpathValidate must not be null. Otherwise, there is no 
> validation on
>             ognlpathValidate.
>             <attribute name="ognlPathValidate" required="true"> An 
> ErroredDate.
>                 </attribute>
>             <attribute name="ognlPathCondition" required="true"> An 
> ErroredBoolean.
>                 </attribute>
>             <attribute name="errorMessage" required="true"/>
>             <conversion
>                 
> class="com.pathto.baseclass.usedin.validation.VCompletedDateIfBoolean"/>
>             </element>
> which retrieve the object we are interested in from the object tree, 
> and retrieves the values we need.
> This entails necessary repetition in hivemodule. The issue would be 
> whether each case defined in hivemodule is really a seperate case.
> It does become tedious, and perhaps confussing, to have a large 
> hivemodule, where many contributions are only subtly different.
>
> Case 2:-
> Where a postcode lookup method in our Tapestry application interfaces 
> to a third party service we have found that some inputs cause the 
> service to hang (and, what is worse, would provoke the user to 
> multiple submits).
> This is overcome (in part) by wrappling the calls in a timed window 
> that snaps shut before lengthy searches are made.
> Hivemodule is useful here in setting global timeout properties, 
> although they shouldn't have to be changed since I have made a series 
> of emperical tests to determine a minimum window.
> This seems to me to be a simple "controller".
>
> <!-- Threaded service to timeout when large searches are made with 
> incomplete data.  model="threaded" -->
>     <service-point id="IPostcodeSearchTO"
>         interface="com.pathTo.search.service.wrapper.api.IPostcodeTO">
>         <invoke-factory model="threaded">
>             <construct 
> class="com.pathTo.search.service.wrapper.PostcodeSearchTOImpl">
>                 <set property="globalTimeout" value="4"/>
>             </construct>
>         </invoke-factory>
>     </service-point>
>
> with impl:-
> public class PostcodeSearchTOImpl implements IPostcodeTO {
> ..............
> }
> and interface :-
> public interface IPostcodeTO {
>     public int getIPostcodeSearchTO();
>     public void setIPostcodeSearchTO(int globalTimeout);
>     public boolean isTimedOut();
>
> }
>
> In *any* class I may write:-
> public abstract IPostcodeTO getIPostcodeTO();
> .............
> //in this case the calling client method is in our impl of Tapestry
> public void updateAddressResults(IRequestCycle cycle) {
> ................
> //the value set in hivemodule
> IPostcodeTO globalTimeout = getIPostcodeTO();
>
> //the value used in this instance can be reset, because it is a time 
> derived from the system in milliseconds, I start it now
> globalTimeout.setIPostcodeSearchTO(globalTimeout.getIPostcodeSearchTO());
>
> make calls to object(s).method(s) that use the properties set
> ......................
> }
> }
> The service client is in any class, as usual with private class 
> instance of the interface type.
>
> I think that covers what you are refering to?
> Adam
>
> On 10/5/05, *Andrei Chiritescu* <andreic@netrom.ro 
> <ma...@netrom.ro>> wrote:
>
>     > Contoller will be IController and ControllerImpl. Device will
>     > implement IController. All that is configured in HiveModule is the
>     > service defining Controller, it's methods and instantiated
>     values will
>     > be available to Device. Is this what you mean?
>
>     Not quite. Let me try to explain my situation better.
>     I have a module like :
>     /<module id="app" version="1.0.0" package="app">
>         <service-point id="Controller" interface="app.Controller">
>             <invoke-factory model="singleton">
>                 <construct class="app.Controller"/>
>             </invoke-factory>
>             <interceptor service-id="hivemind.LoggingInterceptor"/>
>         </service-point>
>     </module>/
>
>     and the Controller.class:
>     /package app;
>     class Controller
>     {
>         /* implementaion is not important */
>     }
>
>     and I also have a Device class:
>     //package app;
>     class //Device /
>     / {
>         private Controller controller;
>         public void setController( Controller controller )
>         {
>             this.controller = controller;
>         }
>     }
>     /
>     Now , what I would like is to get a Device instance that will have the
>     controller injected into it. This without having to add a
>     /<service-point/> /for the Device into the xml descriptor module.
>     So, something like this should work(or anything similar) :
>     Registry registry = ....
>     Device device = (Device) registry.getService( /Device/.class );
>
>     Basically I would like that for any given class to get its managed
>     instance (like the Device class in the example) without needing the
>     <service-point> declared.
>
>     Thanks,
>     Andrei Chiritescu
>
>
>     adasal wrote:
>
>     > Contoller will be IController and ControllerImpl. Device will
>     > implement IController. All that is configured in HiveModule is the
>     > service defining Controller, it's methods and instantiated
>     values will
>     > be available to Device. Is this what you mean?
>     > Or you can get an instance of the service :-
>     > Contoller registry.getService("app.IController",
>     >                 ControllerImpl..class)
>     > or do something like this:-
>     >
>     > public class XXXEngine extends BaseEngine {
>     > ....................
>     > protected Object createGlobal(RequestContext context) {
>     >         HttpServletRequest request = context.getRequest();
>     >
>     >         return HiveMindFilter.getRegistry(request);
>     >     }
>     > used like e.g. this:-
>     >
>     > protected void cleanupAfterRequest(IRequestCycle cycle) {
>     >         super.cleanupAfterRequest(cycle);
>     >
>     >         Registry registry = (Registry) getGlobal();
>     > //which allows:-
>     >         ISessionManager sessionManager = (ISessionManager)
>     > registry.getService(ISessionManager.class);
>     >
>     > .........
>     > What is being controlled here is access to a single session object,
>     > but your problems may be similar.
>     > Tapestry-3.0.3 hivemind-1.0.0
>     > Adam
>     >
>     > On 10/5/05, *Andrei Chiritescu* <andreic@netrom.ro
>     <ma...@netrom.ro>
>     > <mailto: andreic@netrom.ro <ma...@netrom.ro>>> wrote:
>     >
>     >     Do you know whether hivemind contains a method to get an
>     instance
>     >     from a
>     >     specific class (given the classname), which then does all the
>     >     autowiring? I would just like to get a class instance based on
>     >     classname, so that an entry in hivemodule is not necessary.
>     >
>     >     I there a method to get an instance of a specific class
>     (given the
>     >     fully
>     >     qualified classname) that is managed by Hivemind(has the
>     services
>     >     injected) without having to add an entry in the hivemodule
>     >     descriptor?
>     >     Basically what I have is a "Controller" service (declared in
>     the xml
>     >     module) and a lot of Device classes which require the
>     Controller.
>     >     What I
>     >     want is to get a instance of Device class that has the
>     Controller
>     >     class
>     >     wired (injected by hivemind) without adding the Device
>     service in the
>     >     xml descriptor.
>     >
>     >     Is this possible?
>     >
>     >     Regards,
>     >     Andrei Chiritescu
>     >
>     >
>     >    
>     ---------------------------------------------------------------------
>     >     To unsubscribe, e-mail:
>     >     hivemind-user-unsubscribe@jakarta.apache.org
>     <ma...@jakarta.apache.org>
>     >     <mailto: hivemind-user-unsubscribe@jakarta.apache.org
>     <ma...@jakarta.apache.org>>
>     >     For additional commands, e-mail:
>     >     hivemind-user-help@jakarta.apache.org
>     <ma...@jakarta.apache.org>
>     >     <mailto: hivemind-user-help@jakarta.apache.org
>     <ma...@jakarta.apache.org>>
>     >
>     >
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-user-help@jakarta.apache.org


Re: injecting sevices

Posted by adasal <ad...@gmail.com>.
In the application written by Shing Hing Man and myself we have:-
case 1:-
<VCompletedBooleanIfInList
ognlPathValidate="ognlPath.toCondition.toCheck1.ifPreCon1.aValue"
ognlPathCondition="ognlPath.toPreCondition.toCheck1"
errorMessage="${uniqueMessageID1}"
enumType="@OGNLpath@ENUM"/>


<VCompletedDoubleIfBoolean
ognlPathValidate="ognlPath.toCondition.toCheck2.ifPreCon2.aValue"
ognlPathCondition="ognlPath.toPreCondition.toCheck2"
errorMessage="${uniqueMessageID2}"/>
but note we are reussing VCompletedDoubleIfBoolean defined in the schema
like this:-
<element name="VCompletedDateIfBoolean"> If ognlPathCondition is true,
ognlpathValidate must not be null. Otherwise, there is no validation on
ognlpathValidate.
<attribute name="ognlPathValidate" required="true"> An ErroredDate.
</attribute>
<attribute name="ognlPathCondition" required="true"> An ErroredBoolean.
</attribute>
<attribute name="errorMessage" required="true"/>
<conversion
class="com.pathto.baseclass.usedin.validation.VCompletedDateIfBoolean"/>
</element>
which retrieve the object we are interested in from the object tree, and
retrieves the values we need.
This entails necessary repetition in hivemodule. The issue would be whether
each case defined in hivemodule is really a seperate case.
It does become tedious, and perhaps confussing, to have a large hivemodule,
where many contributions are only subtly different.

Case 2:-
Where a postcode lookup method in our Tapestry application interfaces to a
third party service we have found that some inputs cause the service to hang
(and, what is worse, would provoke the user to multiple submits).
This is overcome (in part) by wrappling the calls in a timed window that
snaps shut before lengthy searches are made.
Hivemodule is useful here in setting global timeout properties, although
they shouldn't have to be changed since I have made a series of emperical
tests to determine a minimum window.
This seems to me to be a simple "controller".

<!-- Threaded service to timeout when large searches are made with
incomplete data. model="threaded" -->
<service-point id="IPostcodeSearchTO"
interface="com.pathTo.search.service.wrapper.api.IPostcodeTO">
<invoke-factory model="threaded">
<construct class="com.pathTo.search.service.wrapper.PostcodeSearchTOImpl">
<set property="globalTimeout" value="4"/>
</construct>
</invoke-factory>
</service-point>

with impl:-
public class PostcodeSearchTOImpl implements IPostcodeTO {
..............
}
and interface :-
public interface IPostcodeTO {
public int getIPostcodeSearchTO();
public void setIPostcodeSearchTO(int globalTimeout);
public boolean isTimedOut();

}

In *any* class I may write:-
public abstract IPostcodeTO getIPostcodeTO();
.............
//in this case the calling client method is in our impl of Tapestry
public void updateAddressResults(IRequestCycle cycle) {
................
//the value set in hivemodule
IPostcodeTO globalTimeout = getIPostcodeTO();

//the value used in this instance can be reset, because it is a time derived
from the system in milliseconds, I start it now
globalTimeout.setIPostcodeSearchTO(globalTimeout.getIPostcodeSearchTO());

make calls to object(s).method(s) that use the properties set
......................
}
}
The service client is in any class, as usual with private class instance of
the interface type.

I think that covers what you are refering to?
Adam

On 10/5/05, Andrei Chiritescu <an...@netrom.ro> wrote:
>
> > Contoller will be IController and ControllerImpl. Device will
> > implement IController. All that is configured in HiveModule is the
> > service defining Controller, it's methods and instantiated values will
> > be available to Device. Is this what you mean?
>
> Not quite. Let me try to explain my situation better.
> I have a module like :
> /<module id="app" version="1.0.0" package="app">
> <service-point id="Controller" interface="app.Controller">
> <invoke-factory model="singleton">
> <construct class="app.Controller"/>
> </invoke-factory>
> <interceptor service-id="hivemind.LoggingInterceptor"/>
> </service-point>
> </module>/
>
> and the Controller.class:
> /package app;
> class Controller
> {
> /* implementaion is not important */
> }
>
> and I also have a Device class:
> //package app;
> class //Device /
> / {
> private Controller controller;
> public void setController( Controller controller )
> {
> this.controller = controller;
> }
> }
> /
> Now , what I would like is to get a Device instance that will have the
> controller injected into it. This without having to add a
> /<service-point/> /for the Device into the xml descriptor module.
> So, something like this should work(or anything similar) :
> Registry registry = ....
> Device device = (Device) registry.getService( /Device/.class );
>
> Basically I would like that for any given class to get its managed
> instance (like the Device class in the example) without needing the
> <service-point> declared.
>
> Thanks,
> Andrei Chiritescu
>
>
> adasal wrote:
>
> > Contoller will be IController and ControllerImpl. Device will
> > implement IController. All that is configured in HiveModule is the
> > service defining Controller, it's methods and instantiated values will
> > be available to Device. Is this what you mean?
> > Or you can get an instance of the service :-
> > Contoller registry.getService("app.IController",
> > ControllerImpl..class)
> > or do something like this:-
> >
> > public class XXXEngine extends BaseEngine {
> > ....................
> > protected Object createGlobal(RequestContext context) {
> > HttpServletRequest request = context.getRequest();
> >
> > return HiveMindFilter.getRegistry(request);
> > }
> > used like e.g. this:-
> >
> > protected void cleanupAfterRequest(IRequestCycle cycle) {
> > super.cleanupAfterRequest(cycle);
> >
> > Registry registry = (Registry) getGlobal();
> > //which allows:-
> > ISessionManager sessionManager = (ISessionManager)
> > registry.getService(ISessionManager.class);
> >
> > .........
> > What is being controlled here is access to a single session object,
> > but your problems may be similar.
> > Tapestry-3.0.3 hivemind-1.0.0
> > Adam
> >
> > On 10/5/05, *Andrei Chiritescu* <andreic@netrom.ro
> > <ma...@netrom.ro>> wrote:
> >
> > Do you know whether hivemind contains a method to get an instance
> > from a
> > specific class (given the classname), which then does all the
> > autowiring? I would just like to get a class instance based on
> > classname, so that an entry in hivemodule is not necessary.
> >
> > I there a method to get an instance of a specific class (given the
> > fully
> > qualified classname) that is managed by Hivemind(has the services
> > injected) without having to add an entry in the hivemodule
> > descriptor?
> > Basically what I have is a "Controller" service (declared in the xml
> > module) and a lot of Device classes which require the Controller.
> > What I
> > want is to get a instance of Device class that has the Controller
> > class
> > wired (injected by hivemind) without adding the Device service in the
> > xml descriptor.
> >
> > Is this possible?
> >
> > Regards,
> > Andrei Chiritescu
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > hivemind-user-unsubscribe@jakarta.apache.org
> > <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> > hivemind-user-help@jakarta.apache.org
> > <ma...@jakarta.apache.org>
> >
> >
>
>
>

Re: injecting sevices

Posted by Andrei Chiritescu <an...@netrom.ro>.
> Contoller will be IController and ControllerImpl. Device will 
> implement IController. All that is configured in HiveModule is the 
> service defining Controller, it's methods and instantiated values will 
> be available to Device. Is this what you mean?

Not quite. Let me try to explain my situation better.
I have a module like :
/<module id="app" version="1.0.0" package="app">
    <service-point id="Controller" interface="app.Controller">
        <invoke-factory model="singleton">
            <construct class="app.Controller"/>
        </invoke-factory>
        <interceptor service-id="hivemind.LoggingInterceptor"/>
    </service-point>
</module>/

and the Controller.class:
/package app;
class Controller
{
    /* implementaion is not important */
}

and I also have a Device class:
//package app;
class //Device /
/ {
    private Controller controller;
    public void setController( Controller controller )
    {
        this.controller = controller;
    }
}
/
Now , what I would like is to get a Device instance that will have the 
controller injected into it. This without having to add a 
/<service-point/> /for the Device into the xml descriptor module.
So, something like this should work(or anything similar) :
Registry registry = ....
Device device = (Device) registry.getService( /Device/.class );

Basically I would like that for any given class to get its managed 
instance (like the Device class in the example) without needing the 
<service-point> declared.

Thanks,
Andrei Chiritescu


adasal wrote:

> Contoller will be IController and ControllerImpl. Device will 
> implement IController. All that is configured in HiveModule is the 
> service defining Controller, it's methods and instantiated values will 
> be available to Device. Is this what you mean?
> Or you can get an instance of the service :-
> Contoller registry.getService("app.IController",
>                 ControllerImpl..class)
> or do something like this:-
>
> public class XXXEngine extends BaseEngine {
> ....................
> protected Object createGlobal(RequestContext context) {
>         HttpServletRequest request = context.getRequest();
>
>         return HiveMindFilter.getRegistry(request);
>     }
> used like e.g. this:-
>
> protected void cleanupAfterRequest(IRequestCycle cycle) {
>         super.cleanupAfterRequest(cycle);
>
>         Registry registry = (Registry) getGlobal();
> //which allows:-
>         ISessionManager sessionManager = (ISessionManager) 
> registry.getService(ISessionManager.class);
>
> .........
> What is being controlled here is access to a single session object, 
> but your problems may be similar.
> Tapestry-3.0.3 hivemind-1.0.0
> Adam
>
> On 10/5/05, *Andrei Chiritescu* <andreic@netrom.ro 
> <ma...@netrom.ro>> wrote:
>
>     Do you know whether hivemind contains a method to get an instance
>     from a
>     specific class (given the classname), which then does all the
>     autowiring? I would just like to get a class instance based on
>     classname, so that an entry in hivemodule is not necessary.
>
>     I there a method to get an instance of a specific class (given the
>     fully
>     qualified classname) that is managed by Hivemind(has the services
>     injected) without having to add an entry in the hivemodule
>     descriptor?
>     Basically what I have is a "Controller" service (declared in the xml
>     module) and a lot of Device classes which require the Controller.
>     What I
>     want is to get a instance of Device class that has the Controller
>     class
>     wired (injected by hivemind) without adding the Device service in the
>     xml descriptor.
>
>     Is this possible?
>
>     Regards,
>     Andrei Chiritescu
>
>
>     ---------------------------------------------------------------------
>     To unsubscribe, e-mail:
>     hivemind-user-unsubscribe@jakarta.apache.org
>     <ma...@jakarta.apache.org>
>     For additional commands, e-mail:
>     hivemind-user-help@jakarta.apache.org
>     <ma...@jakarta.apache.org>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-user-help@jakarta.apache.org


Re: injecting sevices

Posted by adasal <ad...@gmail.com>.
Contoller will be IController and ControllerImpl. Device will implement
IController. All that is configured in HiveModule is the service defining
Controller, it's methods and instantiated values will be available to
Device. Is this what you mean?
Or you can get an instance of the service :-
Contoller registry.getService("app.IController",
ControllerImpl..class)
or do something like this:-

public class XXXEngine extends BaseEngine {
....................
protected Object createGlobal(RequestContext context) {
HttpServletRequest request = context.getRequest();

return HiveMindFilter.getRegistry(request);
}
used like e.g. this:-

protected void cleanupAfterRequest(IRequestCycle cycle) {
super.cleanupAfterRequest(cycle);

Registry registry = (Registry) getGlobal();
//which allows:-
ISessionManager sessionManager = (ISessionManager) registry.getService(
ISessionManager.class);

.........
What is being controlled here is access to a single session object, but your
problems may be similar.
Tapestry-3.0.3 hivemind-1.0.0
Adam

On 10/5/05, Andrei Chiritescu <an...@netrom.ro> wrote:
>
> Do you know whether hivemind contains a method to get an instance from a
> specific class (given the classname), which then does all the
> autowiring? I would just like to get a class instance based on
> classname, so that an entry in hivemodule is not necessary.
>
> I there a method to get an instance of a specific class (given the fully
> qualified classname) that is managed by Hivemind(has the services
> injected) without having to add an entry in the hivemodule descriptor?
> Basically what I have is a "Controller" service (declared in the xml
> module) and a lot of Device classes which require the Controller. What I
> want is to get a instance of Device class that has the Controller class
> wired (injected by hivemind) without adding the Device service in the
> xml descriptor.
>
> Is this possible?
>
> Regards,
> Andrei Chiritescu
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: hivemind-user-help@jakarta.apache.org
>
>