0

I have an event observer class. It is a generic mailer. It takes event and creates an email of it. I want to create multiple instances of this observer class like so:

<m:Mailer
resource="WEB-INF/email/adminConfirmation.ftl" 
emailNotificationAddress="admin@xxxx.com">
    <order:onOrderChange>
        <s:parameters>
        <order:StateChange>
           <s:Observes />
        </order:StateChange>
        </s:parameters>
    </order:onOrderChange>
</m:Mailer>
<m:Mailer
resource="WEB-INF/email/userConfirmation.ftl" 
emailNotificationAddress="${order.user.email}">
    <order:onOrderChange>
        <s:parameters>
        <order:StateChange>
           <s:Observes />
        </order:StateChange>
        </s:parameters>
    </order:onOrderChange>
</m:Mailer>

And furthermore I would like it to inherit it's annotation based informations, so I don't have to declare this order:onOrderChange method each time. I tried to declare two instances with s:modifies. But in no matter what I do there is just one listener instance attached.

I desperately want to attach multiple, differently configured instances of the same class as event observers. And haven't found any solution yet...

Mike M.
  • 11
  • 1
  • 2

1 Answers1

0

Might be easier for everyone if you post the class, not the Seam 3 xml-configuration... :-)

What you are searching for a is a generic mailer that listens to different events and sends different emails according to the event, right? I'm not sure if I see the generic part of the requirement, you might want to add some more information to your question to make that clear.

What I would recommend instead is having a single MailSender, that listens to a single event (e.g. RegistrationMailEvent) annotated with different qualifiers (@Admin, @User). I would start with the complete email-logic in one place - should that get too complicated, you can still refactor that into some more beans.

Does this suit your needs?

Oh, and BTW: Events are synchronous - so you have to be aware that you are stopping the thread of execution until event processing has finished. That might not be desired in case of a slow mail server.

Jan Groth
  • 14,039
  • 5
  • 40
  • 55
  • To clarify - implementation is not important. I asked about creating multiple observer bean instances of the same class (read the subject). Implementation and purpose is not important. Just assume these beans have exactly the same implementation, but are parametrized differently. – Mike M. Jun 20 '12 at 07:42
  • This is supposed to be a nice place, so you can safely assume that I read the subject of your post. – Jan Groth Jun 20 '12 at 07:54