Re: [Platemail-developer] Re: whatzzup
Status: Pre-Alpha
Brought to you by:
batneil
|
From: Neil C. <ba...@th...> - 2005-03-31 00:06:27
|
On Wednesday 30 March 2005 13:32, Neil Campbell wrote:
> > It seems odd, since the client should be reactive I think. Having a
> > present number of connections is half-baked; too few and you're going to
> > be unresponsive because you'll be redoing SELECTs, too many and you're
> > going to hit the same problem and thus need to dynamically accept this.
>
> Well, Javamail has a pool of connections, but no actual limit as far as I
> can tell. You can change the size of the pool, but this only controls how
> many unused connections it keeps around, not the maximum number it will
> open concurrently.
>
> > Actually, what you could do is this:
> >
> > conn = openNewConnection(host, port)
> > if(!conn) {
> > // connection refused, take heroic measures
> > reuseConn = pickExistingConnection(connections, FEWEST_MESSAGES)
> > response = send(reuseConn, NOOP)
> > if(response == "OK" || "NO" || "BAD") {
> > // host is still there, not real failure
> > conn = reuseConn;
> > }
> > }
I've put in some code that's not unlike your suggestion. If the first attempt
to open a connection fails, I tell the IMAPMailSource to free me one up (the
IMAPMailSource has a collection of IMAPFolderConnections, which are
responsible for keeping a remote folder and the local data in sync). The
mail source iterates over its connections asking each to release its
connection until it finds one that does, at which point it lets the original
failed connection have another go.
If the second attempt to open the connection fails, that FolderConnection
gives up for the time being (a later attempt to sync everything will cause it
to try again). This second failure could be because the first failure was of
a more serious nature, or it could be because the connections are being dealt
with non-sequentially (they aren't at the moment though) so another thread
has stolen the connection in the meantime.
This is all really less than ideal, but it does work even if there are many
folders and only a single connection available. I think what's more annoying
though is that some set of folders will end up with the connections, which
means that I'll probably no longer be in a position for the server to tell me
when a new message arrives in the INBOX, and I'll have to explicitly open it
again later.
I suppose this is acceptable for the time being though, and I can sort out the
finer points later on in the process. At least now if you have fewer folders
than your server's connection limit everything should be hunky dorey.
Neil
|