Comments (11)
The problem here is that when you connect to dbus for the first time, if the remote dbus is terminated and started again, the dbus connection is not established and it says No connection
Sounds like the remote end is not accepting connections. Are you able to connect to it using other utilities like 'dbus-send' or even telnet if you use TCP for connection?
For me it does not look like an issue of dbus-java. I tried your example with the EmbeddedDBusDaemon of dbus-java, just works as intended:
09:31:05.589 [Thread-0] INFO o.f.d.c.transports.TransportBuilder - Using transport dbus-java-transport-tcp for address tcp:host=localhost,port=36827
Connected to DBUS
Disconnected from DBUS
09:31:15.407 [Thread-2] INFO o.f.d.c.transports.TransportBuilder - Using transport dbus-java-transport-tcp for address tcp:host=localhost,port=36827
Connected to DBUS
Disconnected from DBUS
09:31:25.408 [Thread-4] INFO o.f.d.c.transports.TransportBuilder - Using transport dbus-java-transport-tcp for address tcp:host=localhost,port=36827
Connected to DBUS
Disconnected from DBUS
09:31:35.409 [Thread-6] INFO o.f.d.c.transports.TransportBuilder - Using transport dbus-java-transport-tcp for address tcp:host=localhost,port=36827
Connected to DBUS
Disconnected from DBUS
09:31:45.410 [Thread-8] INFO o.f.d.c.transports.TransportBuilder - Using transport dbus-java-transport-tcp for address tcp:host=localhost,port=36827
Connected to DBUS
Disconnected from DBUS
09:31:55.411 [Thread-10] INFO o.f.d.c.transports.TransportBuilder - Using transport dbus-java-transport-tcp for address tcp:host=localhost,port=36827
Connected to DBUS
Disconnected from DBUS
from dbus-java.
Yes, when i use the dbus-send there is no problem. Can i use EmbeddedDBusDaemon for my purpose ?
from dbus-java.
Please could you add the full source code with EmbeddedDBusDaemon ?
from dbus-java.
EmbeddedDBusDaemon is a Java implementation of the regular dbus daemon used on most modern Linux systems.
I don't think that this is a suitable replacement in your case because any media player (e.g. VLC) will automatically use the session bus of the executing user. That means the interfaces will be exposed to the default dbus daemon instead of the Java version. I would not recommend to replace the system wide default dbus daemon with the Java implementation (never tried that).
Example code can be found here
from dbus-java.
My tcp configuration file added as attachment. If you change its extension as conf and then run with
dbus-daemon --config-file=/path/dbus-tcp.conf
you can simulate my case instead of EmbeddedDBusDaemon.
Thank you
from dbus-java.
I re-run the test with different setups.
First using dbus daemon of Ubuntu 23.10.1 running in a virtual machine, configured to provide access by TCP. To ensure it actually really connects to the bus, I request the introspection data of the Gnome DisplayManager running on the Ubuntu VM.
Works fine all the time.
Second test: using your provided config in a separate DBus instance - Wrote a small test app to export something to the second dbus instance and used your test-code to connect to the second DBus instance and call a method on the exported object retrieving a string. Also no issues:
12:08:45.942 [Thread-0] INFO o.f.d.c.transports.TransportBuilder - Using transport dbus-java-transport-tcp for address tcp:host=localhost,port=2334
Connected to DBUS
You are connected to ws4711, connect number: 1
Disconnected from DBUS
12:08:55.760 [Thread-2] INFO o.f.d.c.transports.TransportBuilder - Using transport dbus-java-transport-tcp for address tcp:host=localhost,port=2334
Connected to DBUS
You are connected to ws4711, connect number: 2
Disconnected from DBUS
12:09:05.761 [Thread-4] INFO o.f.d.c.transports.TransportBuilder - Using transport dbus-java-transport-tcp for address tcp:host=localhost,port=2334
Connected to DBUS
You are connected to ws4711, connect number: 3
Disconnected from DBUS
12:09:15.761 [Thread-6] INFO o.f.d.c.transports.TransportBuilder - Using transport dbus-java-transport-tcp for address tcp:host=localhost,port=2334
Connected to DBUS
You are connected to ws4711, connect number: 4
This was my sample apps code:
package com.github.hypfvieh.dbus.vmtest;
import org.freedesktop.dbus.connections.impl.DBusConnectionBuilder;
import org.freedesktop.dbus.interfaces.DBusInterface;
import java.time.LocalDateTime;
public class VMTestApp {
public static void main(String[] args) {
try (var con = DBusConnectionBuilder.forAddress("tcp:host=127.0.0.1,port=2334").build()) {
QueryTestClz queryTestClz = new QueryTestClz();
con.requestBusName(VMTestApp.class.getPackageName());
con.exportObject(queryTestClz);
while (true) {
Thread.sleep(1000);
}
} catch (Exception _ex) {
_ex.printStackTrace();
}
}
public interface QueryTest extends DBusInterface {
String doQueryTest();
}
public static class QueryTestClz implements QueryTest {
private int callCounter = 0;
@Override
public String getObjectPath() {
return "/vmtest";
}
@Override
public String doQueryTest() {
String str = "You are connected to %s, connect number: %d".formatted(getHostName(), ++callCounter);
System.out.println("[" + LocalDateTime.now() + "] " + str);
return str;
}
static String getHostName() {
try {
return java.net.InetAddress.getLocalHost().getHostName();
} catch (java.net.UnknownHostException _ex) {
return "unknown host name";
}
}
}
}
from dbus-java.
But i stop the dbus daemon after connection is established then my code try to reconnect and print "No connection to DBUS". After this line printed i run the dbus daemon again but no connection is established in client side so always print "No connection to DBUS". I didnt see no connection line in your side. Did you stop the dbus daemon when client code is running ?
from dbus-java.
This stopping of the daemon makes the difference. This is in deed a problem in dbus-java when using shared connections (which is the default).
When creating the second connection (the first reconnect attempt), dbus-java sees that there already is a connection and shared usage is enabled. Then it just returns that connection no matter if the underlying transport already disconnected.
I fixed that issue right now. Now when shared connections are enabled the transport status is checked before a existing connection will be re-used. If the transport is dead already, the connection object is dropped and a new one will be created.
from dbus-java.
Thank you for the quick response and fix. But how can i use this updated version ? Normally i use 4.3.1 version in my project which is developed in java 11. I think you updated the current one and it requires java 17, am i right ?
from dbus-java.
Correct it is only fixed in 5.0.0-SNAPSHOT. If you need to stick to Java 11, you may disable shared connections:
DBusConnectionBuilder.forAddress(busAddress).withShared(false).build()
This should work fine in your case. Sharing a connection is only useful if you have many connections to the same bus and if you are using unix sockets instead of TCP.
from dbus-java.
Thank you so much
from dbus-java.
Related Issues (20)
- Documentation example does not work correctly. HOT 1
- In version 5, `withAutoConnect(false)` appears broken. HOT 2
- Cleanup AbstractConnection
- `default` interface methods. Or not. HOT 7
- problem to execute DBusViewer HOT 3
- How to export/publish Property in interface? HOT 2
- Properties Get method endless waiting HOT 1
- Sending signal with byte[] fails with verbose logging HOT 1
- [Feature request] Any plan in adding a module-info ? HOT 2
- Custom ITransportProvider cannot be found by ServiceLoader HOT 4
- Something a bit wrong with `@DBusBoundProperty` HOT 9
- Incorrect code generation for systemd StartTransientUnit HOT 3
- Add dbus-java-transport-junixsocket to dbus-java-bom
- Help with DBusConnectionBuilder HOT 2
- CodeGenerator does not create @DBusBoundProperty annotated fields properly for types TypeRef ans Struct HOT 2
- GetAll is not callable when using @DBusBoundProperty on a List<DBusPath> property HOT 1
- Memory leak in AbstractConnectionBase#importedObjects HOT 5
- Remove dependency on missing UnixSystem class HOT 1
- Graal Native Image Support HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dbus-java.