pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedA method to asynchronously LISTEN ?
16+ messages / 3 participants
[nested] [flat]
* A method to asynchronously LISTEN ?
@ 2019-02-15 16:55 Philippe Ebersohl <philippe.ebersohl@dalim.com>
0 siblings, 1 reply; 16+ messages in thread
From: Philippe Ebersohl @ 2019-02-15 16:55 UTC (permalink / raw)
To: pgsql-jdbc
Hello,
I checked the documentation and FAQ at jdbc.postgresql.org
Is there a roadmap of feature implementation for the jdbc driver ?
Are there plans to include something similar to the PGNotificationListener found in pgjdbc-ng?
Which does not require to send SELECT to the postgres.
We would if possible only use one postgresql jdbc driver.
I hope I hit the right list for my questions.
Thank you.
Best regards,
Philippe Ebersohl
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: A method to asynchronously LISTEN ?
@ 2019-02-22 19:03 Dave Cramer <pg@fastcrypt.com>
parent: Philippe Ebersohl <philippe.ebersohl@dalim.com>
0 siblings, 1 reply; 16+ messages in thread
From: Dave Cramer @ 2019-02-22 19:03 UTC (permalink / raw)
To: Philippe Ebersohl <philippe.ebersohl@dalim.com>; +Cc: pgsql-jdbc
Hi Philippe,
So this is old, but I didn't get much response
https://github.com/pgjdbc/pgjdbc/pull/579
have a look and see if it works for you. If so we can look at putting it in.
Dave Cramer
davec@postgresintl.com
www.postgresintl.com
On Sat, 16 Feb 2019 at 03:36, Philippe Ebersohl <philippe.ebersohl@dalim.com>
wrote:
> Hello,
> I checked the documentation and FAQ at jdbc.postgresql.org
> Is there a roadmap of feature implementation for the jdbc driver ?
>
> Are there plans to include something similar to the PGNotificationListener
> found in pgjdbc-ng?
> Which does not require to send SELECT to the postgres.
>
> We would if possible only use one postgresql jdbc driver.
>
> I hope I hit the right list for my questions.
> Thank you.
>
> Best regards,
> Philippe Ebersohl
>
>
>
> (null)
>
>
>
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: A method to asynchronously LISTEN ?
@ 2019-02-25 09:15 Philippe Ebersohl <philippe.ebersohl@dalim.com>
parent: Dave Cramer <pg@fastcrypt.com>
0 siblings, 1 reply; 16+ messages in thread
From: Philippe Ebersohl @ 2019-02-25 09:15 UTC (permalink / raw)
To: Dave Cramer <pg@fastcrypt.com>; +Cc: pgsql-jdbc
Hello Dave,
This is, sir, what we would like !
However looking at line 47-50 of
pgjdbc/src/test/java/org/postgresql/test/jdbc2/NotifyTest.java
How do we guaranty that the listener is called before the assertTrue() is fired ?
stmt . executeUpdate( " NOTIFY mynotification " );
assertTrue(flag . get());
Best regards,
Philippe
From: "Dave Cramer" <pg@fastcrypt.com>
To: "Philippe Ebersohl" <philippe.ebersohl@dalim.com>
Cc: "List" <pgsql-jdbc@postgresql.org>
Sent: Friday, 22 February, 2019 20:03:46
Subject: Re: A method to asynchronously LISTEN ?
Hi Philippe,
So this is old, but I didn't get much response https://github.com/pgjdbc/pgjdbc/pull/579
have a look and see if it works for you. If so we can look at putting it in.
Dave Cramer
davec@postgresintl.com
www.postgresintl.com
On Sat, 16 Feb 2019 at 03:36, Philippe Ebersohl < philippe.ebersohl@dalim.com > wrote:
Hello,
I checked the documentation and FAQ at jdbc.postgresql.org
Is there a roadmap of feature implementation for the jdbc driver ?
Are there plans to include something similar to the PGNotificationListener found in pgjdbc-ng?
Which does not require to send SELECT to the postgres.
We would if possible only use one postgresql jdbc driver.
I hope I hit the right list for my questions.
Thank you.
Best regards,
Philippe Ebersohl
(null)
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: A method to asynchronously LISTEN ?
@ 2019-02-25 15:13 Dave Cramer <pg@fastcrypt.com>
parent: Philippe Ebersohl <philippe.ebersohl@dalim.com>
0 siblings, 2 replies; 16+ messages in thread
From: Dave Cramer @ 2019-02-25 15:13 UTC (permalink / raw)
To: Philippe Ebersohl <philippe.ebersohl@dalim.com>; +Cc: pgsql-jdbc
Philippe
On Mon, 25 Feb 2019 at 04:15, Philippe Ebersohl <philippe.ebersohl@dalim.com>
wrote:
> Hello Dave,
>
> This is, sir, what we would like !
>
> However looking at line 47-50 of
> pgjdbc/src/test/java/org/postgresql/test/jdbc2/NotifyTest.java
> <https://github.com/pgjdbc/pgjdbc/pull/579/commits/229d10adf6686805004491a0d94de076d8e1a3ea#diff-d8d2...;
>
> How do we guaranty that the listener is called before the assertTrue() is
> fired ?
>
> stmt.executeUpdate("NOTIFY mynotification");
>
>
>
> assertTrue(flag.get());
>
I'm not sure exactly what you mean
Dave Cramer
davec@postgresintl.com
www.postgresintl.com
*From: *"Dave Cramer" <pg@fastcrypt.com>
> *To: *"Philippe Ebersohl" <philippe.ebersohl@dalim.com>
> *Cc: *"List" <pgsql-jdbc@postgresql.org>
> *Sent: *Friday, 22 February, 2019 20:03:46
> *Subject: *Re: A method to asynchronously LISTEN ?
>
> Hi Philippe,
> So this is old, but I didn't get much response
> https://github.com/pgjdbc/pgjdbc/pull/579
>
> have a look and see if it works for you. If so we can look at putting it
> in.
>
> Dave Cramer
>
> davec@postgresintl.com
> www.postgresintl.com
>
>
> On Sat, 16 Feb 2019 at 03:36, Philippe Ebersohl <
> philippe.ebersohl@dalim.com> wrote:
>
>> Hello,
>> I checked the documentation and FAQ at jdbc.postgresql.org
>> Is there a roadmap of feature implementation for the jdbc driver ?
>>
>> Are there plans to include something similar to
>> the PGNotificationListener found in pgjdbc-ng?
>> Which does not require to send SELECT to the postgres.
>>
>> We would if possible only use one postgresql jdbc driver.
>>
>> I hope I hit the right list for my questions.
>> Thank you.
>>
>> Best regards,
>> Philippe Ebersohl
>>
>>
>>
>> (null)
>>
>>
>>
>
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: A method to asynchronously LISTEN ?
@ 2019-02-26 10:58 Philippe Ebersohl <philippe.ebersohl@dalim.com>
parent: Dave Cramer <pg@fastcrypt.com>
1 sibling, 0 replies; 16+ messages in thread
From: Philippe Ebersohl @ 2019-02-26 10:58 UTC (permalink / raw)
To: Dave Cramer <pg@fastcrypt.com>; +Cc: pgsql-jdbc
Hello,
This feature is indeed what we would need.
In fact I do not understand how the test case works.
I am more a sql/database guy.
Best regards,
Philippe Ebersohl
From: "Dave Cramer" <pg@fastcrypt.com>
To: "Philippe Ebersohl" <philippe.ebersohl@dalim.com>
Cc: "List" <pgsql-jdbc@postgresql.org>
Sent: Monday, 25 February, 2019 16:13:49
Subject: Re: A method to asynchronously LISTEN ?
Philippe
On Mon, 25 Feb 2019 at 04:15, Philippe Ebersohl < philippe.ebersohl@dalim.com > wrote:
Hello Dave,
This is, sir, what we would like !
However looking at line 47-50 of
pgjdbc/src/test/java/org/postgresql/test/jdbc2/NotifyTest.java
How do we guaranty that the listener is called before the assertTrue() is fired ?
stmt . executeUpdate( " NOTIFY mynotification " );
assertTrue(flag . get());
I'm not sure exactly what you mean
Dave Cramer
davec@postgresintl.com
www.postgresintl.com
BQ_BEGIN
From: "Dave Cramer" < pg@fastcrypt.com >
To: "Philippe Ebersohl" < philippe.ebersohl@dalim.com >
Cc: "List" < pgsql-jdbc@postgresql.org >
Sent: Friday, 22 February, 2019 20:03:46
Subject: Re: A method to asynchronously LISTEN ?
Hi Philippe,
So this is old, but I didn't get much response https://github.com/pgjdbc/pgjdbc/pull/579
have a look and see if it works for you. If so we can look at putting it in.
Dave Cramer
davec@postgresintl.com
www.postgresintl.com
On Sat, 16 Feb 2019 at 03:36, Philippe Ebersohl < philippe.ebersohl@dalim.com > wrote:
BQ_BEGIN
Hello,
I checked the documentation and FAQ at jdbc.postgresql.org
Is there a roadmap of feature implementation for the jdbc driver ?
Are there plans to include something similar to the PGNotificationListener found in pgjdbc-ng?
Which does not require to send SELECT to the postgres.
We would if possible only use one postgresql jdbc driver.
I hope I hit the right list for my questions.
Thank you.
Best regards,
Philippe Ebersohl
(null)
BQ_END
BQ_END
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: A method to asynchronously LISTEN ?
@ 2019-02-26 17:29 David G. Johnston <david.g.johnston@gmail.com>
parent: Dave Cramer <pg@fastcrypt.com>
1 sibling, 1 reply; 16+ messages in thread
From: David G. Johnston @ 2019-02-26 17:29 UTC (permalink / raw)
To: Dave Cramer <pg@fastcrypt.com>; +Cc: Philippe Ebersohl <philippe.ebersohl@dalim.com>; pgsql-jdbc
The question being asked is whether executeUpdate method performs
synchronous execution of the listener function queue during its execution.
This after sending the command to the server and the server completing
execution of the NOTIFY. This assumes that the server places the
notification on the channel for pick-up immediately (which will not be the
case within a transaction).
While the client is, IIRC, synchronous, thus the local order of operations
can be controlled, the server is asynchronous and thus this test is exposed
to timing issues. Maybe we need something like conn.listenSync() that
blocks until a notification payload is received on the connection...?
David J.
On Mon, Feb 25, 2019 at 8:14 AM Dave Cramer <pg@fastcrypt.com> wrote:
> Philippe
>
>
>
>
> On Mon, 25 Feb 2019 at 04:15, Philippe Ebersohl <
> philippe.ebersohl@dalim.com> wrote:
>
>> Hello Dave,
>>
>> This is, sir, what we would like !
>>
>> However looking at line 47-50 of
>> pgjdbc/src/test/java/org/postgresql/test/jdbc2/NotifyTest.java
>> <https://github.com/pgjdbc/pgjdbc/pull/579/commits/229d10adf6686805004491a0d94de076d8e1a3ea#diff-d8d2...;
>>
>> How do we guaranty that the listener is called before the assertTrue() is
>> fired ?
>>
>> stmt.executeUpdate("NOTIFY mynotification");
>>
>>
>>
>> assertTrue(flag.get());
>>
>
> I'm not sure exactly what you mean
>
> Dave Cramer
>
> davec@postgresintl.com
> www.postgresintl.com
>
>
> *From: *"Dave Cramer" <pg@fastcrypt.com>
>> *To: *"Philippe Ebersohl" <philippe.ebersohl@dalim.com>
>> *Cc: *"List" <pgsql-jdbc@postgresql.org>
>> *Sent: *Friday, 22 February, 2019 20:03:46
>> *Subject: *Re: A method to asynchronously LISTEN ?
>>
>> Hi Philippe,
>> So this is old, but I didn't get much response
>> https://github.com/pgjdbc/pgjdbc/pull/579
>>
>> have a look and see if it works for you. If so we can look at putting it
>> in.
>>
>> Dave Cramer
>>
>> davec@postgresintl.com
>> www.postgresintl.com
>>
>>
>> On Sat, 16 Feb 2019 at 03:36, Philippe Ebersohl <
>> philippe.ebersohl@dalim.com> wrote:
>>
>>> Hello,
>>> I checked the documentation and FAQ at jdbc.postgresql.org
>>> Is there a roadmap of feature implementation for the jdbc driver ?
>>>
>>> Are there plans to include something similar to
>>> the PGNotificationListener found in pgjdbc-ng?
>>> Which does not require to send SELECT to the postgres.
>>>
>>> We would if possible only use one postgresql jdbc driver.
>>>
>>> I hope I hit the right list for my questions.
>>> Thank you.
>>>
>>> Best regards,
>>> Philippe Ebersohl
>>>
>>>
>>>
>>> (null)
>>>
>>>
>>>
>>
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: A method to asynchronously LISTEN ?
@ 2019-02-26 19:04 Dave Cramer <pg@fastcrypt.com>
parent: David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 1 reply; 16+ messages in thread
From: Dave Cramer @ 2019-02-26 19:04 UTC (permalink / raw)
To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: Philippe Ebersohl <philippe.ebersohl@dalim.com>; pgsql-jdbc
On Tue, 26 Feb 2019 at 12:29, David G. Johnston <david.g.johnston@gmail.com>
wrote:
> The question being asked is whether executeUpdate method performs
> synchronous execution of the listener function queue during its execution.
>
> This after sending the command to the server and the server completing
> execution of the NOTIFY. This assumes that the server places the
> notification on the channel for pick-up immediately (which will not be the
> case within a transaction).
>
> While the client is, IIRC, synchronous, thus the local order of operations
> can be controlled, the server is asynchronous and thus this test is exposed
> to timing issues. Maybe we need something like conn.listenSync() that
> blocks until a notification payload is received on the connection...?
>
kind of defeats the asynchronous aspect, no ?
Dave Cramer
davec@postgresintl.com
www.postgresintl.com
> David J.
>
> On Mon, Feb 25, 2019 at 8:14 AM Dave Cramer <pg@fastcrypt.com> wrote:
>
>> Philippe
>>
>>
>>
>>
>> On Mon, 25 Feb 2019 at 04:15, Philippe Ebersohl <
>> philippe.ebersohl@dalim.com> wrote:
>>
>>> Hello Dave,
>>>
>>> This is, sir, what we would like !
>>>
>>> However looking at line 47-50 of
>>> pgjdbc/src/test/java/org/postgresql/test/jdbc2/NotifyTest.java
>>> <https://github.com/pgjdbc/pgjdbc/pull/579/commits/229d10adf6686805004491a0d94de076d8e1a3ea#diff-d8d2...;
>>>
>>> How do we guaranty that the listener is called before the assertTrue()
>>> is fired ?
>>>
>>> stmt.executeUpdate("NOTIFY mynotification");
>>>
>>>
>>>
>>> assertTrue(flag.get());
>>>
>>
>> I'm not sure exactly what you mean
>>
>> Dave Cramer
>>
>> davec@postgresintl.com
>> www.postgresintl.com
>>
>>
>> *From: *"Dave Cramer" <pg@fastcrypt.com>
>>> *To: *"Philippe Ebersohl" <philippe.ebersohl@dalim.com>
>>> *Cc: *"List" <pgsql-jdbc@postgresql.org>
>>> *Sent: *Friday, 22 February, 2019 20:03:46
>>> *Subject: *Re: A method to asynchronously LISTEN ?
>>>
>>> Hi Philippe,
>>> So this is old, but I didn't get much response
>>> https://github.com/pgjdbc/pgjdbc/pull/579
>>>
>>> have a look and see if it works for you. If so we can look at putting it
>>> in.
>>>
>>> Dave Cramer
>>>
>>> davec@postgresintl.com
>>> www.postgresintl.com
>>>
>>>
>>> On Sat, 16 Feb 2019 at 03:36, Philippe Ebersohl <
>>> philippe.ebersohl@dalim.com> wrote:
>>>
>>>> Hello,
>>>> I checked the documentation and FAQ at jdbc.postgresql.org
>>>> Is there a roadmap of feature implementation for the jdbc driver ?
>>>>
>>>> Are there plans to include something similar to
>>>> the PGNotificationListener found in pgjdbc-ng?
>>>> Which does not require to send SELECT to the postgres.
>>>>
>>>> We would if possible only use one postgresql jdbc driver.
>>>>
>>>> I hope I hit the right list for my questions.
>>>> Thank you.
>>>>
>>>> Best regards,
>>>> Philippe Ebersohl
>>>>
>>>>
>>>>
>>>> (null)
>>>>
>>>>
>>>>
>>>
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: A method to asynchronously LISTEN ?
@ 2019-02-26 21:17 David G. Johnston <david.g.johnston@gmail.com>
parent: Dave Cramer <pg@fastcrypt.com>
0 siblings, 1 reply; 16+ messages in thread
From: David G. Johnston @ 2019-02-26 21:17 UTC (permalink / raw)
To: Dave Cramer <pg@fastcrypt.com>; +Cc: Philippe Ebersohl <philippe.ebersohl@dalim.com>; pgsql-jdbc
On Tue, Feb 26, 2019 at 12:04 PM Dave Cramer <pg@fastcrypt.com> wrote:
>
>
> On Tue, 26 Feb 2019 at 12:29, David G. Johnston <
> david.g.johnston@gmail.com> wrote:
>
>> The question being asked is whether executeUpdate method performs
>> synchronous execution of the listener function queue during its execution.
>>
>> This after sending the command to the server and the server completing
>> execution of the NOTIFY. This assumes that the server places the
>> notification on the channel for pick-up immediately (which will not be the
>> case within a transaction).
>>
>> While the client is, IIRC, synchronous, thus the local order of
>> operations can be controlled, the server is asynchronous and thus this test
>> is exposed to timing issues. Maybe we need something like
>> conn.listenSync() that blocks until a notification payload is received on
>> the connection...?
>>
>
> kind of defeats the asynchronous aspect, no ?
>
>>
>>>>
You'd still want an asynchronous API for people but JavaScript introduced
the "async/await" feature for a reason. In this case making it "sync"
instead of coding up wait loop seems desirable. That said its quite
possible I'm missing some existing feature as I haven't used this API at
all.
David J.
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: A method to asynchronously LISTEN ?
@ 2019-02-27 10:47 Philippe Ebersohl <philippe.ebersohl@dalim.com>
parent: David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 1 reply; 16+ messages in thread
From: Philippe Ebersohl @ 2019-02-27 10:47 UTC (permalink / raw)
To: David G. Johnston <david.g.johnston@gmail.com>; Dave Cramer <pg@fastcrypt.com>; +Cc: pgsql-jdbc
Hello,
I do not think there is a need for something like conn.listenSync().
We were just intrigued about the test.
In fact the current proposition should just work fine and we would like to test it.
How could we have access to a postgresql-*.jdbc.jar that includes this feature ?
Regards,
Philippe
From: "David G. Johnston" <david.g.johnston@gmail.com>
To: "Dave Cramer" <pg@fastcrypt.com>
Cc: "Philippe Ebersohl" <philippe.ebersohl@dalim.com>, "List" <pgsql-jdbc@postgresql.org>
Sent: Tuesday, 26 February, 2019 22:17:12
Subject: Re: A method to asynchronously LISTEN ?
On Tue, Feb 26, 2019 at 12:04 PM Dave Cramer < pg@fastcrypt.com > wrote:
On Tue, 26 Feb 2019 at 12:29, David G. Johnston < david.g.johnston@gmail.com > wrote:
BQ_BEGIN
The question being asked is whether executeUpdate method performs synchronous execution of the listener function queue during its execution.
This after sending the command to the server and the server completing execution of the NOTIFY. This assumes that the server places the notification on the channel for pick-up immediately (which will not be the case within a transaction).
While the client is, IIRC, synchronous, thus the local order of operations can be controlled, the server is asynchronous and thus this test is exposed to timing issues. Maybe we need something like conn.listenSync() that blocks until a notification payload is received on the connection...?
kind of defeats the asynchronous aspect, no ?
BQ_BEGIN
BQ_BEGIN
BQ_BEGIN
BQ_END
BQ_END
BQ_END
BQ_END
You'd still want an asynchronous API for people but JavaScript introduced the "async/await" feature for a reason. In this case making it "sync" instead of coding up wait loop seems desirable. That said its quite possible I'm missing some existing feature as I haven't used this API at all.
David J.
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: A method to asynchronously LISTEN ?
@ 2019-02-27 10:53 Dave Cramer <pg@fastcrypt.com>
parent: Philippe Ebersohl <philippe.ebersohl@dalim.com>
0 siblings, 1 reply; 16+ messages in thread
From: Dave Cramer @ 2019-02-27 10:53 UTC (permalink / raw)
To: Philippe Ebersohl <philippe.ebersohl@dalim.com>; +Cc: David G. Johnston <david.g.johnston@gmail.com>; pgsql-jdbc
On Wed, 27 Feb 2019 at 05:47, Philippe Ebersohl <philippe.ebersohl@dalim.com>
wrote:
> Hello,
> I do not think there is a need for something like conn.listenSync().
> We were just intrigued about the test.
>
> In fact the current proposition should just work fine and we would like to
> test it.
> How could we have access to a postgresql-*.jdbc.jar that includes this
> feature ?
>
> Regards,
> Philippe
>
I just rebased it over the current code
https://github.com/pgjdbc/pgjdbc/pull/579
You should be able to build it manually using the commandline instructions
to get the pull
git checkout -b davecramer-notify master
git pull https://github.com/davecramer/pgjdbc.git notify
then use maven to build it
Dave Cramer
davec@postgresintl.com
www.postgresintl.com
>
> ------------------------------
> *From: *"David G. Johnston" <david.g.johnston@gmail.com>
> *To: *"Dave Cramer" <pg@fastcrypt.com>
> *Cc: *"Philippe Ebersohl" <philippe.ebersohl@dalim.com>, "List" <
> pgsql-jdbc@postgresql.org>
> *Sent: *Tuesday, 26 February, 2019 22:17:12
> *Subject: *Re: A method to asynchronously LISTEN ?
>
> On Tue, Feb 26, 2019 at 12:04 PM Dave Cramer <pg@fastcrypt.com> wrote:
>
>>
>>
>> On Tue, 26 Feb 2019 at 12:29, David G. Johnston <
>> david.g.johnston@gmail.com> wrote:
>>
>>> The question being asked is whether executeUpdate method performs
>>> synchronous execution of the listener function queue during its execution.
>>>
>>> This after sending the command to the server and the server completing
>>> execution of the NOTIFY. This assumes that the server places the
>>> notification on the channel for pick-up immediately (which will not be the
>>> case within a transaction).
>>>
>>> While the client is, IIRC, synchronous, thus the local order of
>>> operations can be controlled, the server is asynchronous and thus this test
>>> is exposed to timing issues. Maybe we need something like
>>> conn.listenSync() that blocks until a notification payload is received on
>>> the connection...?
>>>
>>
>> kind of defeats the asynchronous aspect, no ?
>>
>>>
>>>>>
> You'd still want an asynchronous API for people but JavaScript introduced
> the "async/await" feature for a reason. In this case making it "sync"
> instead of coding up wait loop seems desirable. That said its quite
> possible I'm missing some existing feature as I haven't used this API at
> all.
>
> David J.
>
>
> [image: Visit us on EuroDUO 2019 in Lisbon] <https://euroduo.dalim.com/;
>
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: A method to asynchronously LISTEN ?
@ 2019-02-28 09:52 Philippe Ebersohl <philippe.ebersohl@dalim.com>
parent: Dave Cramer <pg@fastcrypt.com>
0 siblings, 1 reply; 16+ messages in thread
From: Philippe Ebersohl @ 2019-02-28 09:52 UTC (permalink / raw)
To: Dave Cramer <pg@fastcrypt.com>; +Cc: David G. Johnston <david.g.johnston@gmail.com>; pgsql-jdbc
Hello,
we retrieved the sources.
After starting the testNotify() below, we execute from pgadmin : notify mynotification
But the listener is not notified.
Did we miss something ?
public void testNotify() throws SQLException, InterruptedException {
final AtomicBoolean flag = new AtomicBoolean(false);
Statement stmt = conn.createStatement();
((org.postgresql.PGConnection)conn).addNotificationListener(new org.postgresql.PGNotificationListener() {
@Override
public void notification(org.postgresql.PGNotification notification) {
flag.set(true);
System.out.println("Notification received");
}
});
stmt.executeUpdate("LISTEN mynotification");
// stmt.executeUpdate("NOTIFY mynotification");
Thread.sleep(30000);
org.postgresql.PGNotification[] notifications = conn.unwrap(org.postgresql.PGConnection.class).getNotifications();
//assertTrue(flag.get());
//assertNotNull(notifications);
//assertEquals(1, notifications.length);
//assertEquals("mynotification", notifications[0].getName());
//long endMillis = System.currentTimeMillis();
//long runtime = endMillis - startMillis;
//assertNull("There have been notifications, although none have been expected.",notifications);
//assertTrue("We didn't wait long enough! runtime=" + runtime, runtime > 450);
stmt.close();
}
Regards.
Philippe Ebersohl
From: "Dave Cramer" <pg@fastcrypt.com>
To: "Philippe Ebersohl" <philippe.ebersohl@dalim.com>
Cc: "David G. Johnston" <david.g.johnston@gmail.com>, "List" <pgsql-jdbc@postgresql.org>
Sent: Wednesday, 27 February, 2019 11:53:59
Subject: Re: A method to asynchronously LISTEN ?
On Wed, 27 Feb 2019 at 05:47, Philippe Ebersohl < philippe.ebersohl@dalim.com > wrote:
Hello,
I do not think there is a need for something like conn.listenSync().
We were just intrigued about the test.
In fact the current proposition should just work fine and we would like to test it.
How could we have access to a postgresql-*.jdbc.jar that includes this feature ?
Regards,
Philippe
I just rebased it over the current code https://github.com/pgjdbc/pgjdbc/pull/579
You should be able to build it manually using the commandline instructions to get the pull
git checkout -b davecramer-notify master
git pull https://github.com/davecramer/pgjdbc.git notify
then use maven to build it
Dave Cramer
davec@postgresintl.com
www.postgresintl.com
BQ_BEGIN
From: "David G. Johnston" < david.g.johnston@gmail.com >
To: "Dave Cramer" < pg@fastcrypt.com >
Cc: "Philippe Ebersohl" < philippe.ebersohl@dalim.com >, "List" < pgsql-jdbc@postgresql.org >
Sent: Tuesday, 26 February, 2019 22:17:12
Subject: Re: A method to asynchronously LISTEN ?
On Tue, Feb 26, 2019 at 12:04 PM Dave Cramer < pg@fastcrypt.com > wrote:
BQ_BEGIN
On Tue, 26 Feb 2019 at 12:29, David G. Johnston < david.g.johnston@gmail.com > wrote:
BQ_BEGIN
The question being asked is whether executeUpdate method performs synchronous execution of the listener function queue during its execution.
This after sending the command to the server and the server completing execution of the NOTIFY. This assumes that the server places the notification on the channel for pick-up immediately (which will not be the case within a transaction).
While the client is, IIRC, synchronous, thus the local order of operations can be controlled, the server is asynchronous and thus this test is exposed to timing issues. Maybe we need something like conn.listenSync() that blocks until a notification payload is received on the connection...?
BQ_END
kind of defeats the asynchronous aspect, no ?
BQ_BEGIN
BQ_BEGIN
BQ_BEGIN
BQ_END
BQ_END
BQ_END
BQ_END
You'd still want an asynchronous API for people but JavaScript introduced the "async/await" feature for a reason. In this case making it "sync" instead of coding up wait loop seems desirable. That said its quite possible I'm missing some existing feature as I haven't used this API at all.
David J.
BQ_END
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: A method to asynchronously LISTEN ?
@ 2019-03-11 09:41 Philippe Ebersohl <philippe.ebersohl@dalim.com>
parent: Philippe Ebersohl <philippe.ebersohl@dalim.com>
0 siblings, 1 reply; 16+ messages in thread
From: Philippe Ebersohl @ 2019-03-11 09:41 UTC (permalink / raw)
To: Dave Cramer <pg@fastcrypt.com>; +Cc: pgsql-jdbc
Hello,
could you pleas advise what is wrong in our testing ?
We retrieved the git sources, build them.
Modified the testNotify() as shown below.
When performing "NOTIFY mynotification" from an SQL client, we do not see the " Notification received" message as expected.
Thank you.
Regards,
Philippe Ebersohl
From: "Philippe Ebersohl" <philippe.ebersohl@dalim.com>
To: "Dave Cramer" <pg@fastcrypt.com>
Cc: "David G. Johnston" <david.g.johnston@gmail.com>, "List" <pgsql-jdbc@postgresql.org>
Sent: Thursday, 28 February, 2019 10:52:44
Subject: Re: A method to asynchronously LISTEN ?
Hello,
we retrieved the sources.
After starting the testNotify() below, we execute from pgadmin : notify mynotification
But the listener is not notified.
Did we miss something ?
public void testNotify() throws SQLException, InterruptedException {
final AtomicBoolean flag = new AtomicBoolean(false);
Statement stmt = conn.createStatement();
((org.postgresql.PGConnection)conn).addNotificationListener(new org.postgresql.PGNotificationListener() {
@Override
public void notification(org.postgresql.PGNotification notification) {
flag.set(true);
System.out.println("Notification received");
}
});
stmt.executeUpdate("LISTEN mynotification");
// stmt.executeUpdate("NOTIFY mynotification");
Thread.sleep(30000);
org.postgresql.PGNotification[] notifications = conn.unwrap(org.postgresql.PGConnection.class).getNotifications();
//assertTrue(flag.get());
//assertNotNull(notifications);
//assertEquals(1, notifications.length);
//assertEquals("mynotification", notifications[0].getName());
//long endMillis = System.currentTimeMillis();
//long runtime = endMillis - startMillis;
//assertNull("There have been notifications, although none have been expected.",notifications);
//assertTrue("We didn't wait long enough! runtime=" + runtime, runtime > 450);
stmt.close();
}
Regards.
Philippe Ebersohl
From: "Dave Cramer" <pg@fastcrypt.com>
To: "Philippe Ebersohl" <philippe.ebersohl@dalim.com>
Cc: "David G. Johnston" <david.g.johnston@gmail.com>, "List" <pgsql-jdbc@postgresql.org>
Sent: Wednesday, 27 February, 2019 11:53:59
Subject: Re: A method to asynchronously LISTEN ?
On Wed, 27 Feb 2019 at 05:47, Philippe Ebersohl < [ mailto:philippe.ebersohl@dalim.com | philippe.ebersohl@dalim.com ] > wrote:
Hello,
I do not think there is a need for something like conn.listenSync().
We were just intrigued about the test.
In fact the current proposition should just work fine and we would like to test it.
How could we have access to a postgresql-*.jdbc.jar that includes this feature ?
Regards,
Philippe
I just rebased it over the current code [ https://github.com/pgjdbc/pgjdbc/pull/579 | https://github.com/pgjdbc/pgjdbc/pull/579 ]
You should be able to build it manually using the commandline instructions to get the pull
git checkout -b davecramer-notify master
git pull [ https://github.com/davecramer/pgjdbc.git | https://github.com/davecramer/pgjdbc.git ] notify
then use maven to build it
Dave Cramer
[ mailto:davec@postgresintl.com | davec@postgresintl.com ]
[ http://www.postgresintl.com/ | www.postgresintl.com ]
BQ_BEGIN
From: "David G. Johnston" < [ mailto:david.g.johnston@gmail.com | david.g.johnston@gmail.com ] >
To: "Dave Cramer" < [ mailto:pg@fastcrypt.com | pg@fastcrypt.com ] >
Cc: "Philippe Ebersohl" < [ mailto:philippe.ebersohl@dalim.com | philippe.ebersohl@dalim.com ] >, "List" < [ mailto:pgsql-jdbc@postgresql.org | pgsql-jdbc@postgresql.org ] >
Sent: Tuesday, 26 February, 2019 22:17:12
Subject: Re: A method to asynchronously LISTEN ?
On Tue, Feb 26, 2019 at 12:04 PM Dave Cramer < [ mailto:pg@fastcrypt.com | pg@fastcrypt.com ] > wrote:
BQ_BEGIN
On Tue, 26 Feb 2019 at 12:29, David G. Johnston < [ mailto:david.g.johnston@gmail.com | david.g.johnston@gmail.com ] > wrote:
BQ_BEGIN
The question being asked is whether executeUpdate method performs synchronous execution of the listener function queue during its execution.
This after sending the command to the server and the server completing execution of the NOTIFY. This assumes that the server places the notification on the channel for pick-up immediately (which will not be the case within a transaction).
While the client is, IIRC, synchronous, thus the local order of operations can be controlled, the server is asynchronous and thus this test is exposed to timing issues. Maybe we need something like conn.listenSync() that blocks until a notification payload is received on the connection...?
BQ_END
kind of defeats the asynchronous aspect, no ?
BQ_BEGIN
BQ_BEGIN
BQ_BEGIN
BQ_END
BQ_END
BQ_END
BQ_END
You'd still want an asynchronous API for people but JavaScript introduced the "async/await" feature for a reason. In this case making it "sync" instead of coding up wait loop seems desirable. That said its quite possible I'm missing some existing feature as I haven't used this API at all.
David J.
[ https://euroduo.dalim.com/ ]
BQ_END
[ https://euroduo.dalim.com/ ]
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: A method to asynchronously LISTEN ?
@ 2019-03-13 14:37 Dave Cramer <pg@fastcrypt.com>
parent: Philippe Ebersohl <philippe.ebersohl@dalim.com>
0 siblings, 1 reply; 16+ messages in thread
From: Dave Cramer @ 2019-03-13 14:37 UTC (permalink / raw)
To: Philippe Ebersohl <philippe.ebersohl@dalim.com>; +Cc: pgsql-jdbc
On Mon, 11 Mar 2019 at 05:41, Philippe Ebersohl <philippe.ebersohl@dalim.com>
wrote:
>
> Hello,
> could you pleas advise what is wrong in our testing ?
>
> We retrieved the git sources, build them.
> Modified the testNotify() as shown below.
> When performing "NOTIFY mynotification" from an SQL client, we do not
> see the "Notification received" message as expected.
>
> Thank you.
>
> Regards,
>
> Philippe Ebersohl
>
>
Hello Phillipe,
I will look at this as soon as possible. I am currently busy with other
things.
Dave Cramer
davec@postgresintl.com
www.postgresintl.com
>
>
> ------------------------------
> *From: *"Philippe Ebersohl" <philippe.ebersohl@dalim.com>
> *To: *"Dave Cramer" <pg@fastcrypt.com>
> *Cc: *"David G. Johnston" <david.g.johnston@gmail.com>, "List" <
> pgsql-jdbc@postgresql.org>
> *Sent: *Thursday, 28 February, 2019 10:52:44
> *Subject: *Re: A method to asynchronously LISTEN ?
>
> Hello,
> we retrieved the sources.
>
>
> After starting the testNotify() below, we execute from pgadmin : notify
> mynotification
>
> But the listener is not notified.
>
> Did we miss something ?
>
>
>
> public void testNotify() throws SQLException, InterruptedException {
> final AtomicBoolean flag = new AtomicBoolean(false);
> Statement stmt = conn.createStatement();
>
> ((org.postgresql.PGConnection)conn).addNotificationListener(new
> org.postgresql.PGNotificationListener() {
> @Override
> public void notification(org.postgresql.PGNotification
> notification) {
> flag.set(true);
>
> System.out.println("Notification received");
>
> }
> });
> stmt.executeUpdate("LISTEN mynotification");
> // stmt.executeUpdate("NOTIFY mynotification");
>
> Thread.sleep(30000);
>
> org.postgresql.PGNotification[] notifications =
> conn.unwrap(org.postgresql.PGConnection.class).getNotifications();
> //assertTrue(flag.get());
> //assertNotNull(notifications);
> //assertEquals(1, notifications.length);
> //assertEquals("mynotification", notifications[0].getName());
> //long endMillis = System.currentTimeMillis();
> //long runtime = endMillis - startMillis;
> //assertNull("There have been notifications, although none
> have been expected.",notifications);
> //assertTrue("We didn't wait long enough! runtime=" + runtime,
> runtime > 450);
>
> stmt.close();
> }
>
>
> Regards.
>
> Philippe Ebersohl
>
>
> ------------------------------
> *From: *"Dave Cramer" <pg@fastcrypt.com>
> *To: *"Philippe Ebersohl" <philippe.ebersohl@dalim.com>
> *Cc: *"David G. Johnston" <david.g.johnston@gmail.com>, "List" <
> pgsql-jdbc@postgresql.org>
> *Sent: *Wednesday, 27 February, 2019 11:53:59
> *Subject: *Re: A method to asynchronously LISTEN ?
>
>
>
> On Wed, 27 Feb 2019 at 05:47, Philippe Ebersohl <
> philippe.ebersohl@dalim.com> wrote:
>
>> Hello,
>> I do not think there is a need for something like conn.listenSync().
>> We were just intrigued about the test.
>>
>> In fact the current proposition should just work fine and we would like
>> to test it.
>> How could we have access to a postgresql-*.jdbc.jar that includes this
>> feature ?
>>
>> Regards,
>> Philippe
>>
>
> I just rebased it over the current code
> https://github.com/pgjdbc/pgjdbc/pull/579
> You should be able to build it manually using the commandline instructions
> to get the pull
>
> git checkout -b davecramer-notify master
> git pull https://github.com/davecramer/pgjdbc.git notify
>
> then use maven to build it
>
>
> Dave Cramer
>
> davec@postgresintl.com
> www.postgresintl.com
>
>
>
>>
>> ------------------------------
>> *From: *"David G. Johnston" <david.g.johnston@gmail.com>
>> *To: *"Dave Cramer" <pg@fastcrypt.com>
>> *Cc: *"Philippe Ebersohl" <philippe.ebersohl@dalim.com>, "List" <
>> pgsql-jdbc@postgresql.org>
>> *Sent: *Tuesday, 26 February, 2019 22:17:12
>> *Subject: *Re: A method to asynchronously LISTEN ?
>>
>> On Tue, Feb 26, 2019 at 12:04 PM Dave Cramer <pg@fastcrypt.com> wrote:
>>
>>>
>>>
>>> On Tue, 26 Feb 2019 at 12:29, David G. Johnston <
>>> david.g.johnston@gmail.com> wrote:
>>>
>>>> The question being asked is whether executeUpdate method performs
>>>> synchronous execution of the listener function queue during its execution.
>>>>
>>>> This after sending the command to the server and the server completing
>>>> execution of the NOTIFY. This assumes that the server places the
>>>> notification on the channel for pick-up immediately (which will not be the
>>>> case within a transaction).
>>>>
>>>> While the client is, IIRC, synchronous, thus the local order of
>>>> operations can be controlled, the server is asynchronous and thus this test
>>>> is exposed to timing issues. Maybe we need something like
>>>> conn.listenSync() that blocks until a notification payload is received on
>>>> the connection...?
>>>>
>>>
>>> kind of defeats the asynchronous aspect, no ?
>>>
>>>>
>>>>>>
>> You'd still want an asynchronous API for people but JavaScript introduced
>> the "async/await" feature for a reason. In this case making it "sync"
>> instead of coding up wait loop seems desirable. That said its quite
>> possible I'm missing some existing feature as I haven't used this API at
>> all.
>>
>> David J.
>>
>>
>> [image: Visit us on EuroDUO 2019 in Lisbon] <https://euroduo.dalim.com/;
>>
>
>
> [image: Visit us on EuroDUO 2019 in Lisbon] <https://euroduo.dalim.com/;
>
>
> [image: Visit us on EuroDUO 2019 in Lisbon] <https://euroduo.dalim.com/;
>
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: A method to asynchronously LISTEN ?
@ 2019-04-10 14:20 Dave Cramer <pg@fastcrypt.com>
parent: Dave Cramer <pg@fastcrypt.com>
0 siblings, 2 replies; 16+ messages in thread
From: Dave Cramer @ 2019-04-10 14:20 UTC (permalink / raw)
To: Philippe Ebersohl <philippe.ebersohl@dalim.com>; +Cc: pgsql-jdbc
Philippe,
Here's what's going on. The FE/BE protocol is somewhat synchronous and the
NOTIFY is not being read until some other activity occurs on the channel.
If you modify your test to do the following it works fine.
public void testNotify() throws SQLException, InterruptedException {
AtomicBoolean flag = new AtomicBoolean(false);
Statement stmt = conn.createStatement();
((PGConnection)conn).addNotificationListener(new PGNotificationListener() {
@Override
public void notification(PGNotification notification) {
System.out.println("Notification Received");
flag.set(true);
}
});
stmt.executeUpdate("LISTEN mynotification");
for (int i=0;i<30; i++) {
stmt.execute("select 1");
Thread.sleep(1000);
}
stmt.close();
Dave Cramer
davec@postgresintl.com
www.postgresintl.com
On Wed, 13 Mar 2019 at 10:37, Dave Cramer <pg@fastcrypt.com> wrote:
>
>
> On Mon, 11 Mar 2019 at 05:41, Philippe Ebersohl <
> philippe.ebersohl@dalim.com> wrote:
>
>>
>> Hello,
>> could you pleas advise what is wrong in our testing ?
>>
>> We retrieved the git sources, build them.
>> Modified the testNotify() as shown below.
>> When performing "NOTIFY mynotification" from an SQL client, we do not
>> see the "Notification received" message as expected.
>>
>> Thank you.
>>
>> Regards,
>>
>> Philippe Ebersohl
>>
>>
>
> Hello Phillipe,
>
> I will look at this as soon as possible. I am currently busy with other
> things.
>
>
> Dave Cramer
>
> davec@postgresintl.com
> www.postgresintl.com
>
>
>
>>
>>
>> ------------------------------
>> *From: *"Philippe Ebersohl" <philippe.ebersohl@dalim.com>
>> *To: *"Dave Cramer" <pg@fastcrypt.com>
>> *Cc: *"David G. Johnston" <david.g.johnston@gmail.com>, "List" <
>> pgsql-jdbc@postgresql.org>
>> *Sent: *Thursday, 28 February, 2019 10:52:44
>> *Subject: *Re: A method to asynchronously LISTEN ?
>>
>> Hello,
>> we retrieved the sources.
>>
>>
>> After starting the testNotify() below, we execute from pgadmin : notify
>> mynotification
>>
>> But the listener is not notified.
>>
>> Did we miss something ?
>>
>>
>>
>> public void testNotify() throws SQLException, InterruptedException {
>> final AtomicBoolean flag = new AtomicBoolean(false);
>> Statement stmt = conn.createStatement();
>>
>> ((org.postgresql.PGConnection)conn).addNotificationListener(new
>> org.postgresql.PGNotificationListener() {
>> @Override
>> public void notification(org.postgresql.PGNotification
>> notification) {
>> flag.set(true);
>>
>> System.out.println("Notification received");
>>
>> }
>> });
>> stmt.executeUpdate("LISTEN mynotification");
>> // stmt.executeUpdate("NOTIFY mynotification");
>>
>> Thread.sleep(30000);
>>
>> org.postgresql.PGNotification[] notifications =
>> conn.unwrap(org.postgresql.PGConnection.class).getNotifications();
>> //assertTrue(flag.get());
>> //assertNotNull(notifications);
>> //assertEquals(1, notifications.length);
>> //assertEquals("mynotification", notifications[0].getName());
>> //long endMillis = System.currentTimeMillis();
>> //long runtime = endMillis - startMillis;
>> //assertNull("There have been notifications, although none
>> have been expected.",notifications);
>> //assertTrue("We didn't wait long enough! runtime=" +
>> runtime, runtime > 450);
>>
>> stmt.close();
>> }
>>
>>
>> Regards.
>>
>> Philippe Ebersohl
>>
>>
>> ------------------------------
>> *From: *"Dave Cramer" <pg@fastcrypt.com>
>> *To: *"Philippe Ebersohl" <philippe.ebersohl@dalim.com>
>> *Cc: *"David G. Johnston" <david.g.johnston@gmail.com>, "List" <
>> pgsql-jdbc@postgresql.org>
>> *Sent: *Wednesday, 27 February, 2019 11:53:59
>> *Subject: *Re: A method to asynchronously LISTEN ?
>>
>>
>>
>> On Wed, 27 Feb 2019 at 05:47, Philippe Ebersohl <
>> philippe.ebersohl@dalim.com> wrote:
>>
>>> Hello,
>>> I do not think there is a need for something like conn.listenSync().
>>> We were just intrigued about the test.
>>>
>>> In fact the current proposition should just work fine and we would like
>>> to test it.
>>> How could we have access to a postgresql-*.jdbc.jar that includes this
>>> feature ?
>>>
>>> Regards,
>>> Philippe
>>>
>>
>> I just rebased it over the current code
>> https://github.com/pgjdbc/pgjdbc/pull/579
>> You should be able to build it manually using the commandline
>> instructions to get the pull
>>
>> git checkout -b davecramer-notify master
>> git pull https://github.com/davecramer/pgjdbc.git notify
>>
>> then use maven to build it
>>
>>
>> Dave Cramer
>>
>> davec@postgresintl.com
>> www.postgresintl.com
>>
>>
>>
>>>
>>> ------------------------------
>>> *From: *"David G. Johnston" <david.g.johnston@gmail.com>
>>> *To: *"Dave Cramer" <pg@fastcrypt.com>
>>> *Cc: *"Philippe Ebersohl" <philippe.ebersohl@dalim.com>, "List" <
>>> pgsql-jdbc@postgresql.org>
>>> *Sent: *Tuesday, 26 February, 2019 22:17:12
>>> *Subject: *Re: A method to asynchronously LISTEN ?
>>>
>>> On Tue, Feb 26, 2019 at 12:04 PM Dave Cramer <pg@fastcrypt.com> wrote:
>>>
>>>>
>>>>
>>>> On Tue, 26 Feb 2019 at 12:29, David G. Johnston <
>>>> david.g.johnston@gmail.com> wrote:
>>>>
>>>>> The question being asked is whether executeUpdate method performs
>>>>> synchronous execution of the listener function queue during its execution.
>>>>>
>>>>> This after sending the command to the server and the server completing
>>>>> execution of the NOTIFY. This assumes that the server places the
>>>>> notification on the channel for pick-up immediately (which will not be the
>>>>> case within a transaction).
>>>>>
>>>>> While the client is, IIRC, synchronous, thus the local order of
>>>>> operations can be controlled, the server is asynchronous and thus this test
>>>>> is exposed to timing issues. Maybe we need something like
>>>>> conn.listenSync() that blocks until a notification payload is received on
>>>>> the connection...?
>>>>>
>>>>
>>>> kind of defeats the asynchronous aspect, no ?
>>>>
>>>>>
>>>>>>>
>>> You'd still want an asynchronous API for people but JavaScript
>>> introduced the "async/await" feature for a reason. In this case making it
>>> "sync" instead of coding up wait loop seems desirable. That said its quite
>>> possible I'm missing some existing feature as I haven't used this API at
>>> all.
>>>
>>> David J.
>>>
>>>
>>> [image: Visit us on EuroDUO 2019 in Lisbon] <https://euroduo.dalim.com/;
>>>
>>
>>
>> [image: Visit us on EuroDUO 2019 in Lisbon] <https://euroduo.dalim.com/;
>>
>>
>> [image: Visit us on EuroDUO 2019 in Lisbon] <https://euroduo.dalim.com/;
>>
>
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: A method to asynchronously LISTEN ?
@ 2019-04-12 20:03 Philippe Ebersohl <philippe.ebersohl@dalim.com>
parent: Dave Cramer <pg@fastcrypt.com>
1 sibling, 0 replies; 16+ messages in thread
From: Philippe Ebersohl @ 2019-04-12 20:03 UTC (permalink / raw)
To: Dave Cramer <pg@fastcrypt.com>; +Cc: pgsql-jdbc
Thanks for the update, I forward it to the devs.
Best regards,
Philippe
From: "Dave Cramer" <pg@fastcrypt.com>
To: "Philippe Ebersohl" <philippe.ebersohl@dalim.com>
Cc: "List" <pgsql-jdbc@postgresql.org>
Sent: Wednesday, 10 April, 2019 16:20:39
Subject: Re: A method to asynchronously LISTEN ?
Philippe,
Here's what's going on. The FE/BE protocol is somewhat synchronous and the NOTIFY is not being read until some other activity occurs on the channel.
If you modify your test to do the following it works fine.
public void testNotify() throws SQLException, InterruptedException {
AtomicBoolean flag = new AtomicBoolean( false );
Statement stmt = conn .createStatement();
((PGConnection) conn ).addNotificationListener( new PGNotificationListener() {
@Override
public void notification(PGNotification notification) {
System. out .println( "Notification Received" );
flag .set( true );
}
});
stmt.executeUpdate( "LISTEN mynotification" );
for ( int i= 0 ;i< 30 ; i++) {
stmt.execute( "select 1" );
Thread. sleep ( 1000 );
}
stmt.close();
Dave Cramer
[ mailto:davec@postgresintl.com | davec@postgresintl.com ]
[ http://www.postgresintl.com/ | www.postgresintl.com ]
On Wed, 13 Mar 2019 at 10:37, Dave Cramer < [ mailto:pg@fastcrypt.com | pg@fastcrypt.com ] > wrote:
On Mon, 11 Mar 2019 at 05:41, Philippe Ebersohl < [ mailto:philippe.ebersohl@dalim.com | philippe.ebersohl@dalim.com ] > wrote:
BQ_BEGIN
Hello,
could you pleas advise what is wrong in our testing ?
We retrieved the git sources, build them.
Modified the testNotify() as shown below.
When performing "NOTIFY mynotification" from an SQL client, we do not see the " Notification received" message as expected.
Thank you.
Regards,
Philippe Ebersohl
Hello Phillipe,
I will look at this as soon as possible. I am currently busy with other things.
Dave Cramer
[ mailto:davec@postgresintl.com | davec@postgresintl.com ]
[ http://www.postgresintl.com/ | www.postgresintl.com ]
BQ_BEGIN
From: "Philippe Ebersohl" < [ mailto:philippe.ebersohl@dalim.com | philippe.ebersohl@dalim.com ] >
To: "Dave Cramer" < [ mailto:pg@fastcrypt.com | pg@fastcrypt.com ] >
Cc: "David G. Johnston" < [ mailto:david.g.johnston@gmail.com | david.g.johnston@gmail.com ] >, "List" < [ mailto:pgsql-jdbc@postgresql.org | pgsql-jdbc@postgresql.org ] >
Sent: Thursday, 28 February, 2019 10:52:44
Subject: Re: A method to asynchronously LISTEN ?
Hello,
we retrieved the sources.
After starting the testNotify() below, we execute from pgadmin : notify mynotification
But the listener is not notified.
Did we miss something ?
public void testNotify() throws SQLException, InterruptedException {
final AtomicBoolean flag = new AtomicBoolean(false);
Statement stmt = conn.createStatement();
((org.postgresql.PGConnection)conn).addNotificationListener(new org.postgresql.PGNotificationListener() {
@Override
public void notification(org.postgresql.PGNotification notification) {
flag.set(true);
System.out.println("Notification received");
}
});
stmt.executeUpdate("LISTEN mynotification");
// stmt.executeUpdate("NOTIFY mynotification");
Thread.sleep(30000);
org.postgresql.PGNotification[] notifications = conn.unwrap(org.postgresql.PGConnection.class).getNotifications();
//assertTrue(flag.get());
//assertNotNull(notifications);
//assertEquals(1, notifications.length);
//assertEquals("mynotification", notifications[0].getName());
//long endMillis = System.currentTimeMillis();
//long runtime = endMillis - startMillis;
//assertNull("There have been notifications, although none have been expected.",notifications);
//assertTrue("We didn't wait long enough! runtime=" + runtime, runtime > 450);
stmt.close();
}
Regards.
Philippe Ebersohl
From: "Dave Cramer" < [ mailto:pg@fastcrypt.com | pg@fastcrypt.com ] >
To: "Philippe Ebersohl" < [ mailto:philippe.ebersohl@dalim.com | philippe.ebersohl@dalim.com ] >
Cc: "David G. Johnston" < [ mailto:david.g.johnston@gmail.com | david.g.johnston@gmail.com ] >, "List" < [ mailto:pgsql-jdbc@postgresql.org | pgsql-jdbc@postgresql.org ] >
Sent: Wednesday, 27 February, 2019 11:53:59
Subject: Re: A method to asynchronously LISTEN ?
On Wed, 27 Feb 2019 at 05:47, Philippe Ebersohl < [ mailto:philippe.ebersohl@dalim.com | philippe.ebersohl@dalim.com ] > wrote:
BQ_BEGIN
Hello,
I do not think there is a need for something like conn.listenSync().
We were just intrigued about the test.
In fact the current proposition should just work fine and we would like to test it.
How could we have access to a postgresql-*.jdbc.jar that includes this feature ?
Regards,
Philippe
BQ_END
I just rebased it over the current code [ https://github.com/pgjdbc/pgjdbc/pull/579 | https://github.com/pgjdbc/pgjdbc/pull/579 ]
You should be able to build it manually using the commandline instructions to get the pull
git checkout -b davecramer-notify master
git pull [ https://github.com/davecramer/pgjdbc.git | https://github.com/davecramer/pgjdbc.git ] notify
then use maven to build it
Dave Cramer
[ mailto:davec@postgresintl.com | davec@postgresintl.com ]
[ http://www.postgresintl.com/ | www.postgresintl.com ]
BQ_BEGIN
From: "David G. Johnston" < [ mailto:david.g.johnston@gmail.com | david.g.johnston@gmail.com ] >
To: "Dave Cramer" < [ mailto:pg@fastcrypt.com | pg@fastcrypt.com ] >
Cc: "Philippe Ebersohl" < [ mailto:philippe.ebersohl@dalim.com | philippe.ebersohl@dalim.com ] >, "List" < [ mailto:pgsql-jdbc@postgresql.org | pgsql-jdbc@postgresql.org ] >
Sent: Tuesday, 26 February, 2019 22:17:12
Subject: Re: A method to asynchronously LISTEN ?
On Tue, Feb 26, 2019 at 12:04 PM Dave Cramer < [ mailto:pg@fastcrypt.com | pg@fastcrypt.com ] > wrote:
BQ_BEGIN
On Tue, 26 Feb 2019 at 12:29, David G. Johnston < [ mailto:david.g.johnston@gmail.com | david.g.johnston@gmail.com ] > wrote:
BQ_BEGIN
The question being asked is whether executeUpdate method performs synchronous execution of the listener function queue during its execution.
This after sending the command to the server and the server completing execution of the NOTIFY. This assumes that the server places the notification on the channel for pick-up immediately (which will not be the case within a transaction).
While the client is, IIRC, synchronous, thus the local order of operations can be controlled, the server is asynchronous and thus this test is exposed to timing issues. Maybe we need something like conn.listenSync() that blocks until a notification payload is received on the connection...?
BQ_END
kind of defeats the asynchronous aspect, no ?
BQ_BEGIN
BQ_BEGIN
BQ_BEGIN
BQ_END
BQ_END
BQ_END
BQ_END
You'd still want an asynchronous API for people but JavaScript introduced the "async/await" feature for a reason. In this case making it "sync" instead of coding up wait loop seems desirable. That said its quite possible I'm missing some existing feature as I haven't used this API at all.
David J.
[ https://euroduo.dalim.com/ ]
BQ_END
[ https://euroduo.dalim.com/ ]
[ https://euroduo.dalim.com/ ]
BQ_END
BQ_END
^ permalink raw reply [nested|flat] 16+ messages in thread
* Re: A method to asynchronously LISTEN ?
@ 2019-04-18 14:48 Philippe Ebersohl <philippe.ebersohl@dalim.com>
parent: Dave Cramer <pg@fastcrypt.com>
1 sibling, 0 replies; 16+ messages in thread
From: Philippe Ebersohl @ 2019-04-18 14:48 UTC (permalink / raw)
To: Dave Cramer <pg@fastcrypt.com>; +Cc: pgsql-jdbc
Hello,
This is not what was expected, when using the pgjdbc-ng driver there is no need to poll.
( [ https://github.com/impossibl/pgjdbc-ng | https://github.com/impossibl/pgjdbc-ng ] )
Do you think this feature could be added to the pgsql-jdbc driver ?
If not, our devs will have to use both drivers, the pgjdbc-ng for the asynchronous notifications without polling and the pgsql-jdbc for the dbcp.
Best regards,
Philippe Ebersohl
I got an example, and the declaration is much alike:
public void listen() throws SQLException {
PGNotificationListener listener = new PGNotificationListener() {
public void notification ( int processId , String channelName , String payload ) {
System. out .println( "Received Notification: " + processId + ", " + channelName + ", " + payload );
}
public void closed () {
// initiate reconnection & restart listening
}
};
Statement statement = conn .createStatement() ;
statement .execute( "LISTEN " + QNAME );
statement .close();
conn .addNotificationListener( listener );
System. out .println( "Wait for events" );
}
But there is no SELECT involved.
The main just does:
postgresNG .listen();
Object lock = new Object();
synchronized ( lock )
{
lock . wait ();
}
And when NOTIFY is issued from pgAdmin for example, the answer is printed immediately by the java program.
From: "Dave Cramer" <pg@fastcrypt.com>
To: "Philippe Ebersohl" <philippe.ebersohl@dalim.com>
Cc: "List" <pgsql-jdbc@postgresql.org>
Sent: Wednesday, 10 April, 2019 16:20:39
Subject: Re: A method to asynchronously LISTEN ?
Philippe,
Here's what's going on. The FE/BE protocol is somewhat synchronous and the NOTIFY is not being read until some other activity occurs on the channel.
If you modify your test to do the following it works fine.
public void testNotify() throws SQLException, InterruptedException {
AtomicBoolean flag = new AtomicBoolean( false );
Statement stmt = conn .createStatement();
((PGConnection) conn ).addNotificationListener( new PGNotificationListener() {
@Override
public void notification(PGNotification notification) {
System. out .println( "Notification Received" );
flag .set( true );
}
});
stmt.executeUpdate( "LISTEN mynotification" );
for ( int i= 0 ;i< 30 ; i++) {
stmt.execute( "select 1" );
Thread. sleep ( 1000 );
}
stmt.close();
Dave Cramer
[ mailto:davec@postgresintl.com | davec@postgresintl.com ]
[ http://www.postgresintl.com/ | www.postgresintl.com ]
On Wed, 13 Mar 2019 at 10:37, Dave Cramer < [ mailto:pg@fastcrypt.com | pg@fastcrypt.com ] > wrote:
On Mon, 11 Mar 2019 at 05:41, Philippe Ebersohl < [ mailto:philippe.ebersohl@dalim.com | philippe.ebersohl@dalim.com ] > wrote:
BQ_BEGIN
Hello,
could you pleas advise what is wrong in our testing ?
We retrieved the git sources, build them.
Modified the testNotify() as shown below.
When performing "NOTIFY mynotification" from an SQL client, we do not see the " Notification received" message as expected.
Thank you.
Regards,
Philippe Ebersohl
Hello Phillipe,
I will look at this as soon as possible. I am currently busy with other things.
Dave Cramer
[ mailto:davec@postgresintl.com | davec@postgresintl.com ]
[ http://www.postgresintl.com/ | www.postgresintl.com ]
BQ_BEGIN
From: "Philippe Ebersohl" < [ mailto:philippe.ebersohl@dalim.com | philippe.ebersohl@dalim.com ] >
To: "Dave Cramer" < [ mailto:pg@fastcrypt.com | pg@fastcrypt.com ] >
Cc: "David G. Johnston" < [ mailto:david.g.johnston@gmail.com | david.g.johnston@gmail.com ] >, "List" < [ mailto:pgsql-jdbc@postgresql.org | pgsql-jdbc@postgresql.org ] >
Sent: Thursday, 28 February, 2019 10:52:44
Subject: Re: A method to asynchronously LISTEN ?
Hello,
we retrieved the sources.
After starting the testNotify() below, we execute from pgadmin : notify mynotification
But the listener is not notified.
Did we miss something ?
public void testNotify() throws SQLException, InterruptedException {
final AtomicBoolean flag = new AtomicBoolean(false);
Statement stmt = conn.createStatement();
((org.postgresql.PGConnection)conn).addNotificationListener(new org.postgresql.PGNotificationListener() {
@Override
public void notification(org.postgresql.PGNotification notification) {
flag.set(true);
System.out.println("Notification received");
}
});
stmt.executeUpdate("LISTEN mynotification");
// stmt.executeUpdate("NOTIFY mynotification");
Thread.sleep(30000);
org.postgresql.PGNotification[] notifications = conn.unwrap(org.postgresql.PGConnection.class).getNotifications();
//assertTrue(flag.get());
//assertNotNull(notifications);
//assertEquals(1, notifications.length);
//assertEquals("mynotification", notifications[0].getName());
//long endMillis = System.currentTimeMillis();
//long runtime = endMillis - startMillis;
//assertNull("There have been notifications, although none have been expected.",notifications);
//assertTrue("We didn't wait long enough! runtime=" + runtime, runtime > 450);
stmt.close();
}
Regards.
Philippe Ebersohl
From: "Dave Cramer" < [ mailto:pg@fastcrypt.com | pg@fastcrypt.com ] >
To: "Philippe Ebersohl" < [ mailto:philippe.ebersohl@dalim.com | philippe.ebersohl@dalim.com ] >
Cc: "David G. Johnston" < [ mailto:david.g.johnston@gmail.com | david.g.johnston@gmail.com ] >, "List" < [ mailto:pgsql-jdbc@postgresql.org | pgsql-jdbc@postgresql.org ] >
Sent: Wednesday, 27 February, 2019 11:53:59
Subject: Re: A method to asynchronously LISTEN ?
On Wed, 27 Feb 2019 at 05:47, Philippe Ebersohl < [ mailto:philippe.ebersohl@dalim.com | philippe.ebersohl@dalim.com ] > wrote:
BQ_BEGIN
Hello,
I do not think there is a need for something like conn.listenSync().
We were just intrigued about the test.
In fact the current proposition should just work fine and we would like to test it.
How could we have access to a postgresql-*.jdbc.jar that includes this feature ?
Regards,
Philippe
BQ_END
I just rebased it over the current code [ https://github.com/pgjdbc/pgjdbc/pull/579 | https://github.com/pgjdbc/pgjdbc/pull/579 ]
You should be able to build it manually using the commandline instructions to get the pull
git checkout -b davecramer-notify master
git pull [ https://github.com/davecramer/pgjdbc.git | https://github.com/davecramer/pgjdbc.git ] notify
then use maven to build it
Dave Cramer
[ mailto:davec@postgresintl.com | davec@postgresintl.com ]
[ http://www.postgresintl.com/ | www.postgresintl.com ]
BQ_BEGIN
From: "David G. Johnston" < [ mailto:david.g.johnston@gmail.com | david.g.johnston@gmail.com ] >
To: "Dave Cramer" < [ mailto:pg@fastcrypt.com | pg@fastcrypt.com ] >
Cc: "Philippe Ebersohl" < [ mailto:philippe.ebersohl@dalim.com | philippe.ebersohl@dalim.com ] >, "List" < [ mailto:pgsql-jdbc@postgresql.org | pgsql-jdbc@postgresql.org ] >
Sent: Tuesday, 26 February, 2019 22:17:12
Subject: Re: A method to asynchronously LISTEN ?
On Tue, Feb 26, 2019 at 12:04 PM Dave Cramer < [ mailto:pg@fastcrypt.com | pg@fastcrypt.com ] > wrote:
BQ_BEGIN
On Tue, 26 Feb 2019 at 12:29, David G. Johnston < [ mailto:david.g.johnston@gmail.com | david.g.johnston@gmail.com ] > wrote:
BQ_BEGIN
The question being asked is whether executeUpdate method performs synchronous execution of the listener function queue during its execution.
This after sending the command to the server and the server completing execution of the NOTIFY. This assumes that the server places the notification on the channel for pick-up immediately (which will not be the case within a transaction).
While the client is, IIRC, synchronous, thus the local order of operations can be controlled, the server is asynchronous and thus this test is exposed to timing issues. Maybe we need something like conn.listenSync() that blocks until a notification payload is received on the connection...?
BQ_END
kind of defeats the asynchronous aspect, no ?
BQ_BEGIN
BQ_BEGIN
BQ_BEGIN
BQ_END
BQ_END
BQ_END
BQ_END
You'd still want an asynchronous API for people but JavaScript introduced the "async/await" feature for a reason. In this case making it "sync" instead of coding up wait loop seems desirable. That said its quite possible I'm missing some existing feature as I haven't used this API at all.
David J.
[ https://euroduo.dalim.com/ ]
BQ_END
[ https://euroduo.dalim.com/ ]
[ https://euroduo.dalim.com/ ]
BQ_END
BQ_END
^ permalink raw reply [nested|flat] 16+ messages in thread
end of thread, other threads:[~2019-04-18 14:48 UTC | newest]
Thread overview: 16+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-02-15 16:55 A method to asynchronously LISTEN ? Philippe Ebersohl <philippe.ebersohl@dalim.com>
2019-02-22 19:03 ` Dave Cramer <pg@fastcrypt.com>
2019-02-25 09:15 ` Philippe Ebersohl <philippe.ebersohl@dalim.com>
2019-02-25 15:13 ` Dave Cramer <pg@fastcrypt.com>
2019-02-26 10:58 ` Philippe Ebersohl <philippe.ebersohl@dalim.com>
2019-02-26 17:29 ` David G. Johnston <david.g.johnston@gmail.com>
2019-02-26 19:04 ` Dave Cramer <pg@fastcrypt.com>
2019-02-26 21:17 ` David G. Johnston <david.g.johnston@gmail.com>
2019-02-27 10:47 ` Philippe Ebersohl <philippe.ebersohl@dalim.com>
2019-02-27 10:53 ` Dave Cramer <pg@fastcrypt.com>
2019-02-28 09:52 ` Philippe Ebersohl <philippe.ebersohl@dalim.com>
2019-03-11 09:41 ` Philippe Ebersohl <philippe.ebersohl@dalim.com>
2019-03-13 14:37 ` Dave Cramer <pg@fastcrypt.com>
2019-04-10 14:20 ` Dave Cramer <pg@fastcrypt.com>
2019-04-12 20:03 ` Philippe Ebersohl <philippe.ebersohl@dalim.com>
2019-04-18 14:48 ` Philippe Ebersohl <philippe.ebersohl@dalim.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox