Home > Archive > PHP Pear > January 2005 > Event Dispatcher and Failed Posted Notifications
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Event Dispatcher and Failed Posted Notifications
|
|
| Michael Caplan 2005-01-26, 3:57 pm |
| Bertrand et al,
I have been paying close attention to the proposed / approved Event
Dispatcher, as it seems to provide a very elegant solution to the problem of
inter-module coupling. I have spent some time in the code and working
through the unit tests to figure out how Event Dispatcher works. I think I
have my head around most of it, but there is one issue I can't seem to
figure out and I am hoping you or anyone else can help me solve it.
The scenario is this: I am coding in an environment which has several
defined modules. Each module provides unique functionality (eg: article
module, calendar module, tracker module, etc....). Under certain scenarios,
these modules will need to interface with each other (eg: an article is
posted into the article module which requires the tracker module to be
updated so that it can track access to the article - or something like
that). So, module A posts an event (which is to be handled immediately)
which the dispatcher then forwards to an observer in module B. All good.
But let's say the event posted to module B fails. For whatever reason,
module A has a strong dependency on module B doing it's work, and upon
failure of module B's handled event it would be most desirable that module A
rolls back. Is there a way that the event poster can become aware of an
event failure (presuming it is an immediately posted event)?
I've spent some time in the COCOA docs that you referenced and modeled your
work on, and don't see how such a scenario would be handled there either.
Perhaps the scenario that I am outlining is not viable real world example?
Thanks for your time and excellent work,
Michael Caplan
CONFIDENTIALITY NOTICE
This message contains confidential information intended only for the use of
the individual or entity named as recipient. Any dissemination, distribution
or copying of this communication by anyone other than the intended recipient
is strictly prohibited. If you have received this message in error, please
immediately notify us and delete your copy. Thank you.
AVIS DE CONFIDENTIALITÉ
Les informations contenues aux présentes sont de nature privilégiée et
confidentielle. Elles ne peuvent être utilisées que par la personne ou
l'entité dont le nom paraît comme destinataire. Si le lecteur du présent
message n'est pas le destinataire prévu, il est par les présentes prié de
noter qu'il est strictement interdit de divulguer, de distribuer ou de
copier ce message. Si ce message vous a été transmis par mégarde, veuillez
nous en aviser immédiatement et supprimer votre copie. Merci.
| |
| Bertrand Mansion 2005-01-26, 3:57 pm |
| Michael Caplan wrote:
>Bertrand et al,
>
>=20
>
>I have been paying close attention to the proposed / approved Event
>Dispatcher, as it seems to provide a very elegant solution to the problem =
of
>inter-module coupling. I have spent some time in the code and working
>through the unit tests to figure out how Event Dispatcher works. I think =
I
>have my head around most of it, but there is one issue I can't seem to
>figure out and I am hoping you or anyone else can help me solve it.
>
>=20
>
>The scenario is this: I am coding in an environment which has several
>defined modules. Each module provides unique functionality (eg: article
>module, calendar module, tracker module, etc....). Under certain scenario=
s,
>these modules will need to interface with each other (eg: an article is
>posted into the article module which requires the tracker module to be
>updated so that it can track access to the article - or something like
>that). So, module A posts an event (which is to be handled immediately)
>which the dispatcher then forwards to an observer in module B. All good.
>But let's say the event posted to module B fails. For whatever reason,
>module A has a strong dependency on module B doing it's work, and upon
>failure of module B's handled event it would be most desirable that module=
A
>rolls back. Is there a way that the event poster can become aware of an
>event failure (presuming it is an immediately posted event)?
I think this might be better handled by exceptions if PHP5 is an option for=
you.
You can also have object A (the poster) be the contained notification objec=
t
(this is the usual way to go anyway) and have B (the receiver) use the cont=
ained
object like suck:
// In B, this is your callback
function receiverMethod(&$notification)
{
// Do some work...
=20
if ($failed) {
$A =3D& $notification->getNotificationObject();
$A->rollback();
$notification->cancelNotification();
}
}
Good luck,
Bertrand Mansion
Mamasam
| |
| Michael Caplan 2005-01-26, 3:57 pm |
| Bertrand,
Thanks for the speedy reply. What you described would solve the problem,
but it supposes that the event recipient knows about the passed object from
the event poster. This solution seems to imply a tighter coupling between
modules than I would like. Anyway, something to chew on.
Thanks again,
Michael
-----Original Message-----
CONFIDENTIALITY NOTICE
This message contains confidential information intended only for the use of
the individual or entity named as recipient. Any dissemination, distribution
or copying of this communication by anyone other than the intended recipient
is strictly prohibited. If you have received this message in error, please
immediately notify us and delete your copy. Thank you.
AVIS DE CONFIDENTIALITÉ
Les informations contenues aux présentes sont de nature privilégiée et
confidentielle. Elles ne peuvent être utilisées que par la personne ou
l'entité dont le nom paraît comme destinataire. Si le lecteur du présent
message n'est pas le destinataire prévu, il est par les présentes prié de
noter qu'il est strictement interdit de divulguer, de distribuer ou de
copier ce message. Si ce message vous a été transmis par mégarde, veuillez
nous en aviser immédiatement et supprimer votre copie. Merci.
From: Bertrand Mansion [mailto:bmansion@mamasam.com]
Sent: Wednesday, January 26, 2005 8:23 AM
To: Michael Caplan
Cc: 'pear-general@lists.php.net'
Subject: Re: Event Dispatcher and Failed Posted Notifications
Michael Caplan wrote:
>Bertrand et al,
>
>
>
>I have been paying close attention to the proposed / approved Event
>Dispatcher, as it seems to provide a very elegant solution to the problem
of
>inter-module coupling. I have spent some time in the code and working
>through the unit tests to figure out how Event Dispatcher works. I think I
>have my head around most of it, but there is one issue I can't seem to
>figure out and I am hoping you or anyone else can help me solve it.
>
>
>
>The scenario is this: I am coding in an environment which has several
>defined modules. Each module provides unique functionality (eg: article
>module, calendar module, tracker module, etc....). Under certain
scenarios,
>these modules will need to interface with each other (eg: an article is
>posted into the article module which requires the tracker module to be
>updated so that it can track access to the article - or something like
>that). So, module A posts an event (which is to be handled immediately)
>which the dispatcher then forwards to an observer in module B. All good.
>But let's say the event posted to module B fails. For whatever reason,
>module A has a strong dependency on module B doing it's work, and upon
>failure of module B's handled event it would be most desirable that module
A
>rolls back. Is there a way that the event poster can become aware of an
>event failure (presuming it is an immediately posted event)?
I think this might be better handled by exceptions if PHP5 is an option for
you.
You can also have object A (the poster) be the contained notification object
(this is the usual way to go anyway) and have B (the receiver) use the
contained
object like suck:
// In B, this is your callback
function receiverMethod(&$notification)
{
// Do some work...
if ($failed) {
$A =& $notification->getNotificationObject();
$A->rollback();
$notification->cancelNotification();
}
}
Good luck,
Bertrand Mansion
Mamasam
|
|
|
|
|