Page 1 of 1

[patch_done] ZPgEventAlerter modification

Posted: 13.04.2012, 21:15
by markus
Hi,
i've started playing with ZPgEventAlerter component.
It works great - one thing is missing through:
in psql notify command has two parameters: channel and payload (string literal).
OnNotify event don't introduce this second parameter - only notification channel. And this additional data can be sometimes very useful.

I've modified ZPgEventAlerter.pas and ZPlainPostgreSqlDriver.pas to add Payload to OnNotify event of component.

Only issue would be compatibility with earlier versions of postgres.
payload data was introduced in postgreSQL 7.4, but earlier versions are not available for download.

Best regards,
Marek

Posted: 14.04.2012, 09:22
by mrLion
markus, Friend, this component has another implicit, to a critical error! If we take a rather frequent situation where the same message is processed in different windows, we find the problem. When you close a window in the "garbage collection" we must remove all the service's server, we are registered in the constructor.
So, if we use two windows event handling A, after scavenging the event will no longer be handled by the server and, correspondingly, another window will not receive messages.
The error lies in the processing algorithm. How do I correct? I have long been made​​, simply adjust the code in Pascal - laziness, because using the C + +
If you want to - I can provide code in C + +, and explanations. Correct, and will enter the annals of history! :)

Posted: 14.04.2012, 13:54
by EgonHugeist
mrLion,

that's interesting. Can you attach a patch?

markus,

i've looked to the PlainDriver and it seems we supportd only version 7.4UP. Otherwise we've to change your patch by using ICon.GetServerMajorVersion >= 7, ICon.GetServerMiniorVersion >= 3 .....
But if we need a version check we'll see on on forum threads.

patch done Rev. 1149 /testing-egonhugeist
I'll merge all the changes to the testing branch later on.

Btw. can you use TortoiseSVN to generate Patches? (use *.diff for the Forum) So we can see the Revision you've used and only the changed lines. That would be great!

King regards,
Michael

Posted: 14.04.2012, 17:17
by mrLion
EgonHugeist, no problem.
Catch. This is a module in C + + that I use. Unfortunately, almost all the comments in Russian. If you will not understand the code, can be translated into English, by Google. But this is not so fast.
Module, standalone, I did I connect the plug-in, so that the sample itself is not very easy to tear.
But the general principle is this: you create a class-catcher handler event, which controls all to the ground (1 exempl for 1 connection with DB!!!). And if necessary, recorded the event. Each list of events (in each box) is also a class (the last in the source). When you remove the window class is removed, and also removes the recording of events.
But there is a subtle point - the class-list of events should be assigned to a pointer to a function - the "processor", which will directly handle the incoming events.
Yes, and more. Error handling is not provided. There was no need yet. :)

Best Regards
Ivan Rog.

Posted: 16.04.2012, 18:56
by markus
mrLion,
You're right about flaws in design of notifications, but Your example (two windows with listeners) is error prone itself.
According to libpq documentation:
The function PQnotifies returns the next notification from a list of unhandled notification messages received from the server. It returns a null pointer if there are no pending notifications. Once a notification is returned from PQnotifies, it is considered handled and will be removed from the list of notifications.
So having more than one listener for one connection listening for the same event will simply not work. Only one of them will handle notification.

Your solution with NotificationManager is nice...
It should even go further and in ZPgEventAlerter we should be able to assign Manager. If Manager is assigned - let it take care of receiving notifications. If not - ZPgEventAlerter do it on it's own. Callback functions like in Your code will handle events on their own.

btw:
in PGInterface.cpp line 330:

Code: Select all

PGnotify *notify=NULL;
 drv->GetPlainFunc()->PQFreemem(notify); - this is not needed i think;)
Same goes to line 340.

EgonHugeist - I'll start using diff files from now on. Sorry for earlier trouble.

Posted: 16.04.2012, 20:23
by EgonHugeist
mrLion,

I must admit i was out of time to study your lines more detailed. So i'll check your design on weekend. But i must admit the idea 'em selves i like.

markus,

no apologies needed. Your patches and purpose was always understandable. It's only a better way to comunicate with code lines.

Michael

Posted: 16.04.2012, 22:49
by ism
Zeosdbo - International project :)

Long ago watching with interest

Posted: 17.04.2012, 16:14
by mrLion
markus, Yes, I know! After reading the documentation, I just "gave birth" this class, so that the handler has always been one, but used in many places. Glad that helped, although the idea is on the surface. :)

EgonHugeist, but I have nowhere to rush.

ism, да не стесьняйся, присоединяйся!

Posted: 22.04.2012, 17:59
by markus
Hi all:)

I've been playing with ZPgEventAlerter to incorporate mrLion idea.

With my changes we will be able to create a tree of EventAlerters with only one processor handling notifications from DB.

But it would be nice if some Pascal specialist look at it and check potential bugs/errors etc.

Marek

Posted: 22.04.2012, 19:44
by EgonHugeist
markus, mrLion,

:? work overload -> Rev 1182. 8)

I'll check thes proposals later on.

Michael

Posted: 26.04.2012, 23:24
by EgonHugeist
mrLion,

thank you for your proposal. I wasn't able to understand everything. I think the Patch of Markus includes your idea too. I hope you're also happy with his solution..

markus,

patch done Rev1203\testing and Rev.1204\testing-egonhugeist. Thank you. Nice code, no problems found.

Michael