You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Thilo Tanner <th...@reprisk.com> on 2014/02/11 14:42:28 UTC
Tapestry IOC / Autobuild / Advise Question
Hi all,
I have a quick question concerning Tapestry IOC. I'm currently integrating Akka into one of my applications. In order to use it with a DI container, I created a IndirectActorProducer which uses the autobuild() method of ObjectLocator, in order to create a new actor object whenever produce is triggered (a requirement by Akka). Service injections are also fulfilled by autobuild(). So far so good. Then I tried to use the @CommitAfter annotation from JPA module. Because the of the fact, that the objects created with autobuild() aren't services, the commit isn't triggered. @Match("*Actor") advisor doesn't work as well.
How can advise a method in an object created with autobuild() ? Do I need to create a new IOC scope or can I use Plastic somehow?
Docs to use Akka with DI:
http://doc.akka.io/docs/akka/2.2.3/java/untyped-actors.html#Dependency_Injection
​Thanks a lot in advance for all your inputs!
Best,
Thilo
Re: Tapestry IOC / Autobuild / Advise Question
Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 11 Feb 2014 18:16:01 -0200, Lance Java <la...@googlemail.com>
wrote:
>> you must bind every actor and make sure it uses the correct scope
> You could do something like this:
>
> public void bind(ServiceBinder binder) {
> Class[] actorClasses = ...;
>
> for (Class actorClass : actorClasses) {
> binder.bind(actorClass).scope("prototype");
> }
> }
>
> If you put all of your classes in the same package you could use
> ClassNameLocator to look them up.
That's a really nice, elegant solution! :)
--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Tapestry IOC / Autobuild / Advise Question
Posted by Lance Java <la...@googlemail.com>.
> you must bind every actor and make sure it uses the correct scope
You could do something like this:
public void bind(ServiceBinder binder) {
Class[] actorClasses = ...;
for (Class actorClass : actorClasses) {
binder.bind(actorClass).scope("prototype");
}
}
If you put all of your classes in the same package you could use
ClassNameLocator to look them up.
On 11 February 2014 17:50, Thiago H de Paula Figueiredo
<th...@gmail.com>wrote:
> On Tue, 11 Feb 2014 15:03:21 -0200, Thilo Tanner <th...@reprisk.com>
> wrote:
>
> Hi Thiago,
>>
>
> Hi!
>
>
> unfortunately, it isn't that simple. I made a quick test and introduced a
>> bean service lifecycle. Technically it works, but the solution isn't very
>> elegant: you must bind every actor and make sure it uses the correct scope
>> plus the correct marker (to trigger the method advise). Due to the
>> architecture of Akka, you then have to create the actual actors using
>> actorSystem.actorOf() using either an indirect actor producer or an
>> instance of the actor service defined before.
>>
>
> You can declare services based on objects you instantiate yourself. Just
> create a buildXXX() method. Of course, you'll need to create one for each
> actor.
>
>
> The solution with autobuild() is much more elegant,
>>
>
> Have you tried using the proxy() method instead of autobuild? I'm not sure
> it'll work, but that's something I'd try. After all, the whole Tapestry-IoC
> implementation of decoration and aspects are based on proxies.
>
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
Re: Tapestry IOC / Autobuild / Advise Question
Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 11 Feb 2014 15:03:21 -0200, Thilo Tanner
<th...@reprisk.com> wrote:
> Hi Thiago,
Hi!
> unfortunately, it isn't that simple. I made a quick test and introduced
> a bean service lifecycle. Technically it works, but the solution isn't
> very elegant: you must bind every actor and make sure it uses the
> correct scope plus the correct marker (to trigger the method advise).
> Due to the architecture of Akka, you then have to create the actual
> actors using actorSystem.actorOf() using either an indirect actor
> producer or an instance of the actor service defined before.
You can declare services based on objects you instantiate yourself. Just
create a buildXXX() method. Of course, you'll need to create one for each
actor.
> The solution with autobuild() is much more elegant,
Have you tried using the proxy() method instead of autobuild? I'm not sure
it'll work, but that's something I'd try. After all, the whole
Tapestry-IoC implementation of decoration and aspects are based on proxies.
--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
RE: Tapestry IOC / Autobuild / Advise Question
Posted by Thilo Tanner <th...@reprisk.com>.
Hi Thiago,
unfortunately, it isn't that simple. I made a quick test and introduced a bean service lifecycle. Technically it works, but the solution isn't very elegant: you must bind every actor and make sure it uses the correct scope plus the correct marker (to trigger the method advise). Due to the architecture of Akka, you then have to create the actual actors using actorSystem.actorOf() using either an indirect actor producer or an instance of the actor service defined before. The solution with autobuild() is much more elegant, with the exception that you need to handle the transactions manually. For me it feels, that actors are more similar to pages than to real services. They act (sic) as glue code (integration layer) for high level business code.
I think I will go back to the autobuild() solution and manage the transactions manually (or outside Akka).
Thanks for the input!
Thilo
________________________________________
From: Thiago H de Paula Figueiredo <th...@gmail.com>
Sent: Tuesday, February 11, 2014 17:30
To: Tapestry users
Subject: Re: Tapestry IOC / Autobuild / Advise Question
On Tue, 11 Feb 2014 13:51:13 -0200, Thilo Tanner
<th...@reprisk.com> wrote:
> Hi Lance, hi Thiago,
Hi!
> thanks a lot for your feedback. To be honest, I'm still a bit confused:
>
> Creating a bean or prototype scope seem to be controversial, according
> to older discussions:
>
> e.g. http://web.archiveorange.com/archive/v/NzHgIqXAifXhNB7jPRIc
I don't think that's controversial at all. The thread had a scenario which
is very different from yours. You need decoration and advice, so you need
to make it a service. The scenario in the thread wanted that an object
that isn't a proxy to be returned, so my answer wass based on this
requirement.
--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Tapestry IOC / Autobuild / Advise Question
Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 11 Feb 2014 13:51:13 -0200, Thilo Tanner
<th...@reprisk.com> wrote:
> Hi Lance, hi Thiago,
Hi!
> thanks a lot for your feedback. To be honest, I'm still a bit confused:
>
> Creating a bean or prototype scope seem to be controversial, according
> to older discussions:
>
> e.g. http://web.archiveorange.com/archive/v/NzHgIqXAifXhNB7jPRIc
I don't think that's controversial at all. The thread had a scenario which
is very different from yours. You need decoration and advice, so you need
to make it a service. The scenario in the thread wanted that an object
that isn't a proxy to be returned, so my answer wass based on this
requirement.
--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
RE: Tapestry IOC / Autobuild / Advise Question
Posted by Thilo Tanner <th...@reprisk.com>.
Hi Lance, hi Thiago,
thanks a lot for your feedback. To be honest, I'm still a bit confused:
Creating a bean or prototype scope seem to be controversial, according to older discussions:
e.g. http://web.archiveorange.com/archive/v/NzHgIqXAifXhNB7jPRIc
It is recommended to either use autobuild() or a factory.
Using Plastic doesn't seem to work either, because I end up with a ClassInstantiator which let me create a transformed object (without any dependencies injected). Is there a way to get the transformed class out of Plastic and use it within autobuild? Or is it possible to transform an object created by autobuild()?
http://tapestry.apache.org/5.3/apidocs/org/apache/tapestry5/plastic/PlasticClass.html
Thanks again and best,
Thilo
________________________________________
From: Lance Java <la...@googlemail.com>
Sent: Tuesday, February 11, 2014 16:21
To: Tapestry users
Subject: Re: Tapestry IOC / Autobuild / Advise Question
Thiago, perhaps my wording was a little ambiguous. I consider perthread
scoped services are still singletons. The proxy is a singleton (the
underlying target may not be a singleton). Using autobuild creates a new
instance.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Tapestry IOC / Autobuild / Advise Question
Posted by Lance Java <la...@googlemail.com>.
Thiago, every time you call ObjectLocator.getService() you get a singleton.
Every time you call ObjectLocator.autobuild() you get a new object.
Re: Tapestry IOC / Autobuild / Advise Question
Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 11 Feb 2014 13:21:20 -0200, Lance Java <la...@googlemail.com>
wrote:
> Thiago, perhaps my wording was a little ambiguous. I consider perthread
> scoped services are still singletons. The proxy is a singleton (the
> underlying target may not be a singleton).
I would never say that. The proxy itself may be a singleton, but that's
just a implementation detail. A perthread service will use a different
instance for each thread.
--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Tapestry IOC / Autobuild / Advise Question
Posted by Lance Java <la...@googlemail.com>.
Thiago, perhaps my wording was a little ambiguous. I consider perthread
scoped services are still singletons. The proxy is a singleton (the
underlying target may not be a singleton). Using autobuild creates a new
instance.
Re: Tapestry IOC / Autobuild / Advise Question
Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 11 Feb 2014 12:22:52 -0200, Lance Java <la...@googlemail.com>
wrote:
> Decoration is really for singleton services whereas you are using a scope
> which can be compared to spring's prototype scope.
I'm sorry, Lance, but that's not correct. Decoration and advice does work
with any service defined with an interface. I've been using it on
perthread services a lot without any issues. I think the solution is to
create a new Tapestry-IoC scope, similar to Spring's prototype one
(basically, create a new object everytime injection is done) and turn the
actor objects into services.
--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Tapestry IOC / Autobuild / Advise Question
Posted by Lance Java <la...@googlemail.com>.
You might also want to consider implementing a custom scope (eg
"prototype") by contributing a ServiceLifecycle to ServiceLifecycleSource.
You could then mark your services with @Scope("prototype").
Take a look at PerThreadServiceLifecycle for inspiration.
Re: Tapestry IOC / Autobuild / Advise Question
Posted by Lance Java <la...@googlemail.com>.
Decoration is really for singleton services whereas you are using a scope
which can be compared to spring's prototype scope.
I think you could transform the class (via PlasticManager /
PlasticClassTransformer) prior to calling
ObjectLocator.autobuild(transformedClass)