implementing asynchronous notifications - Mailing list pgsql-jdbc

From Andras Kadinger
Subject implementing asynchronous notifications
Date
Msg-id Pine.LNX.4.44.0504100511560.28671-100000@ns.surfnonstop.com
Whole thread Raw
Responses Re: implementing asynchronous notifications
List pgsql-jdbc
Greetings everyone,

A Java beginner here, seeking the insight of more experienced.

" A key limitation of the JDBC driver is that it cannot receive
asynchronous notifications and must poll the backend to check if any
notifications were issued." - http://jdbc.postgresql.org/documentation/80/listennotify.html

I am looking forward to have that limitation lifted.

When we are idle and not in a transaction, the backend actually sends us
notifications right away; in this case there is no need for us to do
polling with empty queries.

Under unix you can get the fd from libpq, select() on it, and then process
notifications by PQConsumeInput() and retrieve them with PQnotifies(). -
see last paragraph at
http://www.postgresql.org/docs/current/static/libpq-notify.html

Does Java provide working infrastucture to implement this reliably? What's
needed is a reliable way to detect that bytes have arrived on our
connection socket.

I am hoping java.net.Socket.getInputStream.available() could be used. Or
even better the new select()-like functionality provided by java.nio since
1.4. Do these actually work?

If java.nio does, would the impact of choosing java.nio, and thereby
excluding pre-1.4 platforms, an acceptable way of conduct? Or is there
infrastructure in the jdbc.postgresql.org project in place to allow us to
preserve backwards-compatibility by simply omitting this feature from
pre-1.4 builds?

Thank you in advance,

Best Regards,
Andras


pgsql-jdbc by date:

Previous
From: "Pedro n/a"
Date:
Subject: FW: Re: Exception "The connection attempt failed." (didn't find anything
Next
From: Oliver Jowett
Date:
Subject: Re: implementing asynchronous notifications