Java D-Bus API: Handling errors with callWithCallback()

Matthew Johnson dbus at matthew.ath.cx
Tue Dec 1 15:51:37 PST 2009


On Tue Dec 01 12:35, Schmottlach, Glenn wrote:
> I am (attempting) to write a Java D-Bus client that uses
> AbstractConnection.callWithCallback() to asynchronously issue requests
> to a D-Bus service. This reason I am using this method versus
> AbstractConnection.callMethodAsync() is that I want to be notified
> (via the callback) when the reply is returned rather than wait (or
> poll) for the response. I have successfully used this method to
> make requests to services and received a response via the callback
> (e.g. it works as advertised). What I want to understand is how to
> handle D-Bus error messages returned instead of a response to a
> request. If I was issuing a blocking call through the remote object's
> interface I could put a try/catch block around the request and "catch"
> the error message. With callWithCallback() method there does not
> appear to be a mechanism to report back any errors. Likewise, there
> does not appear to be a mechanism to either cancel the request or
> specify a timeout on the request. So, to summarize, these are my
> questions:

Sorry, yes, I should do this. You've asked a much harder question though
(-;

Firstly, you're probably the first person to actually use this API, I
added it since it seemed like it might be useful.

> 1) How do I detect errors using callWithCallback()?
> 2) Can I specify a timeout to wait for a response with callWithCallback()?
> 3) Can I cancel a request issued with callWithCallback()?

Currently, no, no and no, having looked at the code (-:

Sensible options would seem to be:

1. add public void handleError(DBusException e); as a method on
CallbackHandler, thus requiring everyone to implement it in their
handlers

... actually, I'm not sure what else would be a sensible suggestion. I
should certainly fix it up so that it discards callbacks when errors
occur.

Matt

-- 
www.matthew.ath.cx
D-Bus Java
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: Digital signature
Url : http://lists.freedesktop.org/archives/dbus/attachments/20091201/5cf55883/attachment.pgp 


More information about the dbus mailing list