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 "Noel J. Bergman" <no...@devtech.com> on 2002/08/25 07:00:28 UTC

[PATCH] Outgoing Server Name Fix

I moved the point of initialization from the wrong place (SMTPHandler) to
the right place, SMTPServer.  At the same time, I discovered a problem that
I have effectively fixed around, but we'll all want a more elegant solution.

Attached is the patch.  The affected files are:

----

BaseConnectionHandler

This is just a refactoring of code so that a server can ask the connection
handler to parse the configuration and return the hello name.  It kept that
code in one place, rather than replicate it.

----

SMTPHandler

This rolls back my earlier change for setting the hello name into the
MailetContext.  We don't want to actually rollback the CVS because Peter
made a lot of commenting changes, too.

----

SMTPServer

The code for setting the hello name into the MailetContext came here, and it
is cleaner.

I also added a comment regarding inherited lifecycle methods to save anyone
else the same grief I had for a bit.

----

RemoteDelivery

This is the one change that I don't like, but I didn't like the alternatives
that came immediately to mind much better.

Here's the deal: the SpoolManager service is starting before the SMTP Server
service.  The SpoolManager loads and initializes mailet chain.
RemoteDelivery is initializing before the SMTP Server even gets a chance to
start, much less set the hello name into the mailet context.

The problem is that we must wait for the SMTP Service to configure before we
try to get the hello name, from the mailet context.  The thoughts that came
to mind were:

(a) Wait a few seconds at the start of the delivery thread to give the SMTP
server time to initialize.  This works fine, but isn't guaranteed.

(b) Wait for the hello name to be set.  Can't.  There is no contract to
ensure that there will be one.

(c) Query the hello name for each delivery operation.  Doesn't sit well with
me, either.

(d) Add a method to MailetContext such that multi-threaded Mailets can ask
the MailetContext if it has finished initializing.  The notion of "finished"
is not well-defined.

(e) Change the initialization order ... but then the SMTP server would have
to wait for the SpoolManager before the SMTP hander's could be permitted to
start.

----

RE: [PATCH] Outgoing Server Name Fix

Posted by "Noel J. Bergman" <no...@devtech.com>.
Harmeet,

The problem is that there is no guarantee that it will EVER be published.  I
considered your solution, which basically amounts to a loop that waits and
sleeps, as well as just blocking waiting for notification, but there is no
documented requirement that the MailetContext provide a hello name.  I
mentioned this in my message as item (b).

I'd also considered a variation where an upper time limit is placed on the
publication period.  In the end, it boils down to the same thing.  We wait
some reasonable period of time for the value to be available, and then
continue on with whatever we do or do not get.  The only difference is
whether or not the waiting period is abbreviated by the publication event.
Since this occurs only during startup of each RemoteDelivery thread, I used
an upper limit directly.

The alternatives appear to be: (a) wait for some time to see if the value
will be published; (b) document a requirement, and wait for it to be
fulfilled; (c) poll for the value each time you need it; or (d) poll for the
value, and if you ever get one, stop polling.

	--- Noel

-----Original Message-----
From: Harmeet Bedi [mailto:harmeet@kodemuse.com]
Sent: Sunday, August 25, 2002 14:33
To: James Developers List
Subject: Re: [PATCH] Outgoing Server Name Fix


From: "Noel J. Bergman" <no...@devtech.com>
> the right place, SMTPServer.  At the same time, I discovered a problem
that
> I have effectively fixed around, but we'll all want a more elegant
solution.

A publish subscribe mechanism may be more elegant. Here is a simple one..

public class WaitForAvailability {
    // primitive type is used to provide the barrier.
    // it is changed after an object is published.
    private static boolean available = false;

    private static Object obj = null;

    public static Object get() throws InterruptedException {
        while ( !available )
            Thread.currentThread().sleep(1000);
        return obj;
    }
    public static void makeAvailable(Object publish) {
        obj = publish;
        available = true;
    }
}

Harmeet
----- Original Message -----
From: "Noel J. Bergman" <no...@devtech.com>
To: "James-Dev Mailing List" <ja...@jakarta.apache.org>
Sent: Saturday, August 24, 2002 10:00 PM
Subject: [PATCH] Outgoing Server Name Fix


> I moved the point of initialization from the wrong place (SMTPHandler) to
> the right place, SMTPServer.  At the same time, I discovered a problem
that
> I have effectively fixed around, but we'll all want a more elegant
solution.
>
> Attached is the patch.  The affected files are:
>
> ----
>
> BaseConnectionHandler
>
> This is just a refactoring of code so that a server can ask the connection
> handler to parse the configuration and return the hello name.  It kept
that
> code in one place, rather than replicate it.
>
> ----
>
> SMTPHandler
>
> This rolls back my earlier change for setting the hello name into the
> MailetContext.  We don't want to actually rollback the CVS because Peter
> made a lot of commenting changes, too.
>
> ----
>
> SMTPServer
>
> The code for setting the hello name into the MailetContext came here, and
it
> is cleaner.
>
> I also added a comment regarding inherited lifecycle methods to save
anyone
> else the same grief I had for a bit.
>
> ----
>
> RemoteDelivery
>
> This is the one change that I don't like, but I didn't like the
alternatives
> that came immediately to mind much better.
>
> Here's the deal: the SpoolManager service is starting before the SMTP
Server
> service.  The SpoolManager loads and initializes mailet chain.
> RemoteDelivery is initializing before the SMTP Server even gets a chance
to
> start, much less set the hello name into the mailet context.
>
> The problem is that we must wait for the SMTP Service to configure before
we
> try to get the hello name, from the mailet context.  The thoughts that
came
> to mind were:
>
> (a) Wait a few seconds at the start of the delivery thread to give the
SMTP
> server time to initialize.  This works fine, but isn't guaranteed.
>
> (b) Wait for the hello name to be set.  Can't.  There is no contract to
> ensure that there will be one.
>
> (c) Query the hello name for each delivery operation.  Doesn't sit well
with
> me, either.
>
> (d) Add a method to MailetContext such that multi-threaded Mailets can ask
> the MailetContext if it has finished initializing.  The notion of
"finished"
> is not well-defined.
>
> (e) Change the initialization order ... but then the SMTP server would
have
> to wait for the SpoolManager before the SMTP hander's could be permitted
to
> start.
>
> ----
>


----------------------------------------------------------------------------
----


> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [PATCH] Outgoing Server Name Fix

Posted by Harmeet Bedi <ha...@kodemuse.com>.
From: "Noel J. Bergman" <no...@devtech.com>
> the right place, SMTPServer.  At the same time, I discovered a problem
that
> I have effectively fixed around, but we'll all want a more elegant
solution.

A publish subscribe mechanism may be more elegant. Here is a simple one..

public class WaitForAvailability {
    // primitive type is used to provide the barrier.
    // it is changed after an object is published.
    private static boolean available = false;

    private static Object obj = null;

    public static Object get() throws InterruptedException {
        while ( !available )
            Thread.currentThread().sleep(1000);
        return obj;
    }
    public static void makeAvailable(Object publish) {
        obj = publish;
        available = true;
    }
}

Harmeet
----- Original Message -----
From: "Noel J. Bergman" <no...@devtech.com>
To: "James-Dev Mailing List" <ja...@jakarta.apache.org>
Sent: Saturday, August 24, 2002 10:00 PM
Subject: [PATCH] Outgoing Server Name Fix


> I moved the point of initialization from the wrong place (SMTPHandler) to
> the right place, SMTPServer.  At the same time, I discovered a problem
that
> I have effectively fixed around, but we'll all want a more elegant
solution.
>
> Attached is the patch.  The affected files are:
>
> ----
>
> BaseConnectionHandler
>
> This is just a refactoring of code so that a server can ask the connection
> handler to parse the configuration and return the hello name.  It kept
that
> code in one place, rather than replicate it.
>
> ----
>
> SMTPHandler
>
> This rolls back my earlier change for setting the hello name into the
> MailetContext.  We don't want to actually rollback the CVS because Peter
> made a lot of commenting changes, too.
>
> ----
>
> SMTPServer
>
> The code for setting the hello name into the MailetContext came here, and
it
> is cleaner.
>
> I also added a comment regarding inherited lifecycle methods to save
anyone
> else the same grief I had for a bit.
>
> ----
>
> RemoteDelivery
>
> This is the one change that I don't like, but I didn't like the
alternatives
> that came immediately to mind much better.
>
> Here's the deal: the SpoolManager service is starting before the SMTP
Server
> service.  The SpoolManager loads and initializes mailet chain.
> RemoteDelivery is initializing before the SMTP Server even gets a chance
to
> start, much less set the hello name into the mailet context.
>
> The problem is that we must wait for the SMTP Service to configure before
we
> try to get the hello name, from the mailet context.  The thoughts that
came
> to mind were:
>
> (a) Wait a few seconds at the start of the delivery thread to give the
SMTP
> server time to initialize.  This works fine, but isn't guaranteed.
>
> (b) Wait for the hello name to be set.  Can't.  There is no contract to
> ensure that there will be one.
>
> (c) Query the hello name for each delivery operation.  Doesn't sit well
with
> me, either.
>
> (d) Add a method to MailetContext such that multi-threaded Mailets can ask
> the MailetContext if it has finished initializing.  The notion of
"finished"
> is not well-defined.
>
> (e) Change the initialization order ... but then the SMTP server would
have
> to wait for the SpoolManager before the SMTP hander's could be permitted
to
> start.
>
> ----
>


----------------------------------------------------------------------------
----


> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>