-
-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Signals are not handled in the order they are sent #159
Comments
This is really an "old" issue. It has been raised several times. Waiting for signals in "main" thread is not a suitable solution. It will always block the whole process and is also single-threaded. Actually there already is a method to change the threadpool size (Using |
Oh, thanks for quick reply :) So there is! Ok, thanks, that'll do for now. |
That's got it. Slightly strange signature on that method, its actually a I wonder if an annotation on the signal impl might be a nice way to solve this. Anyway. Feel free to close. |
Nice that this is working for you. The main problem is, that all messages retrieved from DBus (responses) will be put in the same threadpool. To address this, I removed the threadpool (and the method to change its size) and will now use multiple threadpools - one for each type of message. While method-return, signal and error are single threaded pools, the pool for method-call has 4 threads to allow recursive calls of remote methods (a remote method which calls another remote method etc). I also removed some useless code like the "Disconnect" signal which is not part of the DBus protocol spec. DBus spec says a connection can be terminated by the client at any time by closing the connection. There is no need to send a "disconnect" message. It would be great if you can try the latest changes. As I'm not sure if this is really working code right now, I added a new branch ( |
Awesome. I've tried this out with the notification API, that all works good. A second more substantial app that uses a lot more of dbus, and in particular makes heavy use of signals, also still works as expected. However, the removal of the So I am not against the removal of this signal, if there is some other way to know when the bus disappears. I realise I could re-implement the |
This is what the dbus specification says:
So in my eyes doing anything like the With the removal of the Disconnect signal I was able to remove some ugly workarounds and special treatments for a feature which is only used if dbus-java is connecting against dbus-java has no use when connecting to the "real" DBus. The
This means you have some sort of "partial" disconnect where you still send a message but do not want to read any incoming messages. So if disconnection signaling is a crucial part of your application, it should be implemented on the application itself. This would also allow you to do additional things before the actual connection is closed. |
Ok understood. I think what I actually want here is notification the underyling transport for a I don't think I can handle this reliably in my own application without creating a custom transport? It would not be possible to extend |
Handling unexpected disconnections is always a difficult topic. The transport is providing the connection over an arbitrary channel (e.g. tcp/unix/udp/pipe/whatever). This means if the connection is killed for any reason, an The question is: When do you want to get notified? Only on unintended disconnects (when |
Yes that sounds perfect. On the client, I do not need to know if the disconnection was intended, i.e. I do not personally need to capture disconnections on the server, although can see that it may be useful. |
I just updated the branch adding support for I will also put some more time in clean-up stuff... Some parts of the library do not "feel good". I'm thinking about deprecating the various constructors and add a factory or builder to create new connections (like I did for transports). This way it would be possible to chain all required options for bootstrapping the connection before it will be connected at all. Also the 'shared' connection stuff in |
That works well. Only one very minor point, is that the logging output is slightly excessive. You'll see 2 exceptions when the connection is severed.
And I look forward to further improvements :) |
I merged the changes of the branch and also added some more changes like Builder for connections, allow changing the thread pool sizes, etc. |
I am using the Freedesktop Notification API (https://specifications.freedesktop.org/notification-spec/latest/ar01s09.html). Everything works fine, except for handling of "Actions", i.e. Buttons on the notification popup (or the default click).
When a notification action is activated, two signals will be sent. Firstly,
ActionInvoked
will be sent, followed closely by aNotificationClosed
signal. Both of these signals of course contain the ID of the popup.However, on the client side, there is no guarantee the signals will be processed in the same order they were sent. This makes it impossible to reliably track which popup the signal has come from. In my user code, I am keeping a map of the popup ID and the action handling code. This mapping gets removed when
NotificationClosed
, is received, so whenActionInvoked
is received as the 2nd signal, its mapping has gone. Now I could add a work around in my code, and keep the mapping around for a little while after the notification is closed, but this seems hacky.The cause is
AbstractConnection.workerThreadPool
and its default size of 4 threads. Signal handling occurs on this pool, so this explains how signals can arrive out of order.I am not sure what the DBus specification says about this (if anything), so I haven't created a PR yet. The following ideas occur.
THREAD_COUNT
to a fixed value of 1. If users want put their own signal handling on a different thread they can.workerThreadPool
at all, just call on main thread.THREAD_COUNT
configurable on the connection with a default value of 4 to preserve existing behavior.THREAD_COUNT
configurable on the connection with a default value of 1.The text was updated successfully, but these errors were encountered: