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/05/24 09:16:26 UTC

A few questions about current MailRepository


Hi!

1. Why MailRepository gets configured on startup?

It is configured with the values from config.xml and initialize is 
called. How can I determine that I shouldn't auto create Mailbox right now?
On demand it gets configured by James every time needed:

  DefaultConfiguration mboxConf
                 = new DefaultConfiguration("repository", 
"generated:AvalonFileRepository.compose()");
             mboxConf.setAttribute("destinationURL", destination);
             mboxConf.setAttribute("type", "MAIL");


2. What is the life cycle of a MailRepository?

I noticed that it was only initialized once it was first called. But 
maybe i interpreted the logs wrong. Does the server keep an 
MailRepository object for each user in memory until it stops?

3. How long are the message keys (names) valid?

Does it fulfill the contract completely to cache keys for the lifetime 
of the MailRepository object?

Joachim

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


Re: A few questions about current MailRepository

Posted by Stefano Bagnara <ap...@bago.org>.
Joachim Draeger wrote:
> Stefano Bagnara wrote:
> 
>>>>> 1. Why MailRepository gets configured on startup?
> 
>>>> Every MAIL repository used by ToRepository and FromRepository 
>>>> mailets, the SPOOL repository used by RemoteDelivery and the main 
>>>> SPOOL repository used by the JamesSpoolManager 
>>>> (localspoolrepository) are created/configured when the components 
>>>> are initialized.
> 
>>> On startup a MailRepository object gets configured with 
>>> destinationURL="whatever://var/mail/inboxes/" and initialized. That 
>>> MailRepository object won't ever be used. So I shouldn't do anything 
>>> in initialize method at that time, but how can I determine that?
> 
>> Can you tell me where does this happens?
>> I cannot find this in the code.
> 
> I don't know where and why it happens exactly. But I found something in 
> the mailstore.log: (at startup)

Ok, James.init. This is probably only to check that the folder exists.
Maybe this is a bug because the repositoryUrl for the inboxes 
configuration is only a prefix for the real repository....

----
         Configuration inboxConf = conf.getChild("inboxRepository");
         Configuration inboxRepConf = inboxConf.getChild("repository");
         // we could delete this block. I didn't remove this because I'm 
not sure
         // wether we need the "check" of the inbox repository here, or not.
         try {
             store.select(inboxRepConf);
         } catch (Exception e) {
             getLogger().error("Cannot open private MailRepository");
             throw e;
         }
----
>> What is "open()" ?
>> MailRepository does not have an open method.
> 
> Sorry, just pseudo code. open() creates the the mailbox structure on 
> disk. It's like "lazy loading". This can't happen in initialize method 
> because that gets called on James start up
> 
> Joachim

Imho you can do this in the initialize. The call made by James.init at 
startup can be considered a bug and you can add a workaround for the 
moment to avoid it.

Stefano


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


Re: A few questions about current MailRepository

Posted by Joachim Draeger <jd...@joachim-draeger.de>.
Stefano Bagnara wrote:

>>>> 1. Why MailRepository gets configured on startup?

>>> Every MAIL repository used by ToRepository and FromRepository 
>>> mailets, the SPOOL repository used by RemoteDelivery and the main 
>>> SPOOL repository used by the JamesSpoolManager (localspoolrepository) 
>>> are created/configured when the components are initialized.

>> On startup a MailRepository object gets configured with 
>> destinationURL="whatever://var/mail/inboxes/" and initialized. That 
>> MailRepository object won't ever be used. So I shouldn't do anything 
>> in initialize method at that time, but how can I determine that?

> Can you tell me where does this happens?
> I cannot find this in the code.

I don't know where and why it happens exactly. But I found something in 
the mailstore.log: (at startup)

24/05/06 13:42:15 INFO  mailstore: JamesMailStore init...
24/05/06 13:42:15 INFO  mailstore: Registering Repository instance of 
class org.apache.james.mailrepository.AvalonMailRepository to handle 
file protocol requests for repositories of type MAIL
24/05/06 13:42:15 INFO  mailstore: Registering Repository instance of 
class org.apache.james.mailrepository.AvalonSpoolRepository to handle 
file protocol requests for repositories of type SPOOL
...
24/05/06 13:42:15 INFO  mailstore: Registering Repository instance of 
class org.apache.james.mailrepository.UIDPlusFolderMailRepository to 
handle maildir protocol requests for repositories of type MAIL
...
24/05/06 13:42:17 DEBUG mailstore: obtained repository: 
org.apache.james.mailrepository.UIDPlusFolderMailRepository to handle: 
maildir,MAIL
24/05/06 13:42:17 DEBUG mailstore: maildir service
24/05/06 13:42:17 DEBUG mailstore: maildir configure
24/05/06 13:42:17 DEBUG mailstore: MaildirMailRepository.destinationURL: 
maildir://var/mail/inboxes/
24/05/06 13:42:17 DEBUG mailstore: destination: 
maildir:///apps/james/var/mail/inboxes/Maildir/
24/05/06 13:42:17 DEBUG mailstore: maildir configured
24/05/06 13:42:17 DEBUG mailstore: maildir initialized

And when it's demanded for a specific user:

24/05/06 13:44:51 DEBUG mailstore: obtained repository: 
org.apache.james.mailrepository.UIDPlusFolderMailRepository to handle: 
maildir,MAIL
24/05/06 13:44:51 DEBUG mailstore: maildir service
24/05/06 13:44:51 DEBUG mailstore: maildir configure
24/05/06 13:44:51 DEBUG mailstore: MaildirMailRepository.destinationURL: 
maildir://var/mail/inboxes/joachim2/
24/05/06 13:44:51 DEBUG mailstore: destination: 
maildir:///apps/james/var/mail/inboxes/joachim2/Maildir/
24/05/06 13:44:51 DEBUG mailstore: maildir configured
24/05/06 13:44:51 DEBUG mailstore: maildir initialized
24/05/06 13:44:51 INFO  mailstore: added repository: 
maildir://var/mail/inboxes/joachim2/MAIL->org.apache.james.mailrepository.UIDPlusFolderMailRepository

I think that happens to every MailRepository that is configured in 
config.xml.

<config>
    <James>
       <inboxRepository>
          <repository destinationURL="maildir://var/mail/inboxes/" 
            type="MAIL"/>
       </inboxRepository>
    </James>
    <mailstore>
       <repositories>
          <repository 
class="org.apache.james.mailrepository.UIDPlusFolderMailRepository ">
             <protocols>
                <protocol>maildir</protocol>
             </protocols>
             <types>
                <type>MAIL</type>
             </types>
          </repository>
       </repositories>
    </mailstore>
</config>

> 
>> When a MailRepository is demanded for a specific user it get's 
>> configured with destinationURL="whatever://var/mail/inboxes/username".
>>
>> Of course I can add "if (!open) open();" to every store, list, remove 
>> method, but I just wonder if there is a better way.
> 
> What is "open()" ?
> MailRepository does not have an open method.

Sorry, just pseudo code. open() creates the the mailbox structure on 
disk. It's like "lazy loading". This can't happen in initialize method 
because that gets called on James start up

Joachim

Re: A few questions about current MailRepository

Posted by Stefano Bagnara <ap...@bago.org>.
Joachim Draeger wrote:
> 
> Stefano Bagnara wrote:
>>> 1. Why MailRepository gets configured on startup?
>> Every MAIL repository used by ToRepository and FromRepository mailets, 
>> the SPOOL repository used by RemoteDelivery and the main SPOOL 
>> repository used by the JamesSpoolManager (localspoolrepository) are 
>> created/configured when the components are initialized.
> 
> On startup a MailRepository object gets configured with 
> destinationURL="whatever://var/mail/inboxes/" and initialized. That 
> MailRepository object won't ever be used. So I shouldn't do anything in 
> initialize method at that time, but how can I determine that?

Can you tell me where does this happens?
I cannot find this in the code.

> When a MailRepository is demanded for a specific user it get's 
> configured with destinationURL="whatever://var/mail/inboxes/username".
> 
> Of course I can add "if (!open) open();" to every store, list, remove 
> method, but I just wonder if there is a better way.

What is "open()" ?
MailRepository does not have an open method.

>> There is a weak cache: James tries to keep the mbox references in 
>> memory, but if no one has reference it may gc them.
> 
>>> 3. How long are the message keys (names) valid?
>>> Does it fulfill the contract completely to cache keys for the 
>>> lifetime of the MailRepository object?
> 
>> James expect to store mails under a given key and to be able to 
>> retrieve the same mail using the same key. There is no "persistence" 
>> of key as references so it's safe to change keys between restarts.
> 
> Okay, but MailRepository maybe gc away. Is it sufficient to keep keys 
> valid for the lifetime of the MailRepository?

For the current contract the answer is no. Btw I think we only reuse 
keys for repositories "hard referenced" and never for weak referenced 
ones, so it should be safe.
I think that if this helps we can "abuse" the current contract and 
document this aspect of the key validity for the "new" contract.

Stefano


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


Re: A few questions about current MailRepository

Posted by Joachim Draeger <jd...@joachim-draeger.de>.
Stefano Bagnara wrote:
>> 1. Why MailRepository gets configured on startup?
> Every MAIL repository used by ToRepository and FromRepository mailets, 
> the SPOOL repository used by RemoteDelivery and the main SPOOL 
> repository used by the JamesSpoolManager (localspoolrepository) are 
> created/configured when the components are initialized.

On startup a MailRepository object gets configured with 
destinationURL="whatever://var/mail/inboxes/" and initialized. That 
MailRepository object won't ever be used. So I shouldn't do anything in 
initialize method at that time, but how can I determine that?

When a MailRepository is demanded for a specific user it get's 
configured with destinationURL="whatever://var/mail/inboxes/username".

Of course I can add "if (!open) open();" to every store, list, remove 
method, but I just wonder if there is a better way.

> There is a weak cache: James tries to keep the mbox references in 
> memory, but if no one has reference it may gc them.

>> 3. How long are the message keys (names) valid?
>> Does it fulfill the contract completely to cache keys for the lifetime 
>> of the MailRepository object?

> James expect to store mails under a given key and to be able to retrieve 
> the same mail using the same key. There is no "persistence" of key as 
> references so it's safe to change keys between restarts.

Okay, but MailRepository maybe gc away. Is it sufficient to keep keys 
valid for the lifetime of the MailRepository?

Joachim

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


Re: A few questions about current MailRepository

Posted by Stefano Bagnara <ap...@bago.org>.
Joachim Draeger wrote:
> Hi!
> 
> 1. Why MailRepository gets configured on startup?

Every MAIL repository used by ToRepository and FromRepository mailets, 
the SPOOL repository used by RemoteDelivery and the main SPOOL 
repository used by the JamesSpoolManager (localspoolrepository) are 
created/configured when the components are initialized.

> It is configured with the values from config.xml and initialize is 
> called. How can I determine that I shouldn't auto create Mailbox right now?
> On demand it gets configured by James every time needed:
> 
>  DefaultConfiguration mboxConf
>                 = new DefaultConfiguration("repository", 
> "generated:AvalonFileRepository.compose()");
>             mboxConf.setAttribute("destinationURL", destination);
>             mboxConf.setAttribute("type", "MAIL");

Mailboxes are created on demand and cached.

> 2. What is the life cycle of a MailRepository?
> 
> I noticed that it was only initialized once it was first called. But 
> maybe i interpreted the logs wrong. Does the server keep an 
> MailRepository object for each user in memory until it stops?

There is a weak cache: James tries to keep the mbox references in 
memory, but if no one has reference it may gc them.

> 3. How long are the message keys (names) valid?
> 
> Does it fulfill the contract completely to cache keys for the lifetime 
> of the MailRepository object?
> 
> Joachim

James expect to store mails under a given key and to be able to retrieve 
the same mail using the same key. There is no "persistence" of key as 
references so it's safe to change keys between restarts.

Stefano


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