[patch_done] ZPgEventAlerter modification

The alpha/beta tester's forum for ZeosLib 7.0.x series

Report problems concerning our Delphi 2009+ version and new Zeoslib 7.0 features here.

This is a forum that will be removed once the 7.X version goes into stable!!

Moderators: gto, EgonHugeist, olehs

Locked
markus
Senior Boarder
Senior Boarder
Posts: 58
Joined: 17.10.2011, 12:43
Location: Piotrków Trybunalski, Poland

[patch_done] ZPgEventAlerter modification

Post 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
You do not have the required permissions to view the files attached to this post.
mrLion
Senior Boarder
Senior Boarder
Posts: 71
Joined: 20.03.2010, 10:17

Post 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! :)
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post 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
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
mrLion
Senior Boarder
Senior Boarder
Posts: 71
Joined: 20.03.2010, 10:17

Post 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.
You do not have the required permissions to view the files attached to this post.
markus
Senior Boarder
Senior Boarder
Posts: 58
Joined: 17.10.2011, 12:43
Location: Piotrków Trybunalski, Poland

Post 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.
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post 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
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
ism
Zeos Test Team
Zeos Test Team
Posts: 202
Joined: 02.10.2010, 20:48

Post by ism »

Zeosdbo - International project :)

Long ago watching with interest
Lazarus 1.0.8 fpc 2.6.0
mrLion
Senior Boarder
Senior Boarder
Posts: 71
Joined: 20.03.2010, 10:17

Post 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, да не стесьняйся, присоединяйся!
markus
Senior Boarder
Senior Boarder
Posts: 58
Joined: 17.10.2011, 12:43
Location: Piotrków Trybunalski, Poland

Post 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
You do not have the required permissions to view the files attached to this post.
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post by EgonHugeist »

markus, mrLion,

:? work overload -> Rev 1182. 8)

I'll check thes proposals later on.

Michael
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post 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
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
Locked