You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by Joachim Draeger <jd...@gmx.de> on 2006/09/23 10:25:57 UTC

Avalon: providing a service to a MailRepository

Hi!

At the moment I'm working on a MailRepository wrapper for the MailboxManager API
  that provides managing and fetching Mailboxes. I try to integrate it with james
the nice way. :)
For the implementation (TorqueMailboxManagerProvider) I have the following:

<blockinfo>
   <block>
     <version>1.0</version>
   </block>
   <services>
       <service name="org.apache.james.mailboxmanager.MailboxManagerProvider"
version="1.0" />
   </services>
</blockinfo>


In assambly.xml I put:

<block name="mailboxmanager"
class="org.apache.james.mailboxmanager.torque.TorqueMailboxManagerProvider" />

Great! It starts up at James start!
Now the MailboxManagerMailRepository should lookup the mailboxmanager service...
Well I noticed that a component can only lookup services that are defined twice,
in assembly.xml and blockinfo (*.xinfo).
But how does for example JDBCMailRepository lookup the data-source?
MailRepositories are instantiated in AvalonMailStore which is proxy-ing the
services bound to it. Good idea.
But how do I offer the MailboxManagerProvider to the MailboxManagerMailRepository?
I bound it to the AvalonMailStore... It worked! I can now look it up.
I had to modify the AvalonMailStore.xinfo to add the MailboxManagerProvider and 
that is not an option because it requires to rebuild James.
It should be pluggable!

Well I think I will workaround it and make TorqueMailboxManagerProvider some 
kind of singleton. Am I missing something?

Joachim




---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Re: Avalon: providing a service to a MailRepository

Posted by Joachim Draeger <jd...@gmx.de>.
Hi Bernd,

Bernd Fondermann schrieb:

> The singleton is one solution. But not preferable.

Right.

> The other is to have a service which is returning (an interface of)
> the object you want to pass around. You'd of course still have to bind
> your components to that service. But you could make the service return
> any implementation of the interface.
> Does it help in your scenario or is it complicating things?

The problem is I can't (or don't know how to) bind any additional service x to a 
MailRepository implementation because it is instantiated by AvalonMailStore.
Binding the service to AvalonMailStore which would be possible and indeed makes 
it available to the created MailRepository is not an option because it requires 
to rebuild James.

Joachim

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Re: Avalon: providing a service to a MailRepository

Posted by Bernd Fondermann <be...@googlemail.com>.
:-)  the verbosity and bureaucracy demanded by phoenix is much higher
and in large parts inappropriate (to say the least :-) ) compared to
today's IoCs or even directly linking components. I doubt I'd really
like to call it "inversion of control".

The singleton is one solution. But not preferable.
The other is to have a service which is returning (an interface of)
the object you want to pass around. You'd of course still have to bind
your components to that service. But you could make the service return
any implementation of the interface.
Does it help in your scenario or is it complicating things?

  Bernd

On 9/23/06, Joachim Draeger <jd...@gmx.de> wrote:
>
> Hi!
>
> At the moment I'm working on a MailRepository wrapper for the MailboxManager API
>   that provides managing and fetching Mailboxes. I try to integrate it with james
> the nice way. :)
> For the implementation (TorqueMailboxManagerProvider) I have the following:
>
> <blockinfo>
>    <block>
>      <version>1.0</version>
>    </block>
>    <services>
>        <service name="org.apache.james.mailboxmanager.MailboxManagerProvider"
> version="1.0" />
>    </services>
> </blockinfo>
>
>
> In assambly.xml I put:
>
> <block name="mailboxmanager"
> class="org.apache.james.mailboxmanager.torque.TorqueMailboxManagerProvider" />
>
> Great! It starts up at James start!
> Now the MailboxManagerMailRepository should lookup the mailboxmanager service...
> Well I noticed that a component can only lookup services that are defined twice,
> in assembly.xml and blockinfo (*.xinfo).
> But how does for example JDBCMailRepository lookup the data-source?
> MailRepositories are instantiated in AvalonMailStore which is proxy-ing the
> services bound to it. Good idea.
> But how do I offer the MailboxManagerProvider to the MailboxManagerMailRepository?
> I bound it to the AvalonMailStore... It worked! I can now look it up.
> I had to modify the AvalonMailStore.xinfo to add the MailboxManagerProvider and
> that is not an option because it requires to rebuild James.
> It should be pluggable!
>
> Well I think I will workaround it and make TorqueMailboxManagerProvider some
> kind of singleton. Am I missing something?
>
> Joachim
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Re: Avalon: providing a service to a MailRepository

Posted by Joachim Draeger <jd...@gmx.de>.
Hi Stefano,

Stefano Bagnara schrieb:

> My only solution is to create a specialization of AvalonMailStore that 
> uses it's own xinfo and lookup the MailboxManagerProvider service: does 
> this make sense?

That came to my mind too, and I think I it is better than keeping a static 
instance somewhere.
But obviously that solution isn't 100% clean too, because you can do that only 
once. The next one who wants to use MailboxManager and an own custom 
implementation of AvalonMailStore has to hack again.
But that's really too far away to consider. :-)
So specializing AvalonMailStore is bit workarounding, too but the best solution 
for now. Thanks!

Joachim


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Re: Avalon: providing a service to a MailRepository

Posted by Stefano Bagnara <ap...@bago.org>.
Hi Joachim,

the problem is that Avalon IoC does not support the concept of 
"Factories" creating managed components, so our factories have to 
manually call the container lifecycle methods on the created objects and 
the factory have to statically declare every dependency that will be 
needed by the created objects.

My only solution is to create a specialization of AvalonMailStore that 
uses it's own xinfo and lookup the MailboxManagerProvider service: does 
this make sense?

MyAvalonMailStore extends AvalonMailStore (nothing more)
MyAvalonMailStore.xinfo => equals AvalonMailStore adding the 
MailboxManagerProvider dependency declaration.

Then you change the assembly:
<block name="mailstore" class="....imap.MyAvalonMailStore" >
   <provide name="database-connections" role="...DataSourceSelector" />
   <provide name="mailboxmanager" role="...MailboxManagerProvider" />
</block>

I would prefer this solution to the singleton one.

Stefano

Joachim Draeger wrote:
> 
> Hi!
> 
> At the moment I'm working on a MailRepository wrapper for the 
> MailboxManager API
>  that provides managing and fetching Mailboxes. I try to integrate it 
> with james
> the nice way. :)
> For the implementation (TorqueMailboxManagerProvider) I have the following:
> 
> <blockinfo>
>   <block>
>     <version>1.0</version>
>   </block>
>   <services>
>       <service 
> name="org.apache.james.mailboxmanager.MailboxManagerProvider"
> version="1.0" />
>   </services>
> </blockinfo>
> 
> 
> In assambly.xml I put:
> 
> <block name="mailboxmanager"
> class="org.apache.james.mailboxmanager.torque.TorqueMailboxManagerProvider" 
> />
> 
> Great! It starts up at James start!
> Now the MailboxManagerMailRepository should lookup the mailboxmanager 
> service...
> Well I noticed that a component can only lookup services that are 
> defined twice,
> in assembly.xml and blockinfo (*.xinfo).
> But how does for example JDBCMailRepository lookup the data-source?
> MailRepositories are instantiated in AvalonMailStore which is proxy-ing the
> services bound to it. Good idea.
> But how do I offer the MailboxManagerProvider to the 
> MailboxManagerMailRepository?
> I bound it to the AvalonMailStore... It worked! I can now look it up.
> I had to modify the AvalonMailStore.xinfo to add the 
> MailboxManagerProvider and that is not an option because it requires to 
> rebuild James.
> It should be pluggable!
> 
> Well I think I will workaround it and make TorqueMailboxManagerProvider 
> some kind of singleton. Am I missing something?
> 
> Joachim



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org