Class ServiceProxy

java.lang.Object
com.lucimber.dbus.proxy.ServiceProxy

public final class ServiceProxy extends Object
Factory for creating dynamic proxies for D-Bus service clients.

This class simplifies D-Bus method calls by allowing you to define a Java interface with annotations and automatically handling the underlying D-Bus communication.

Note: ServiceProxy is designed for simple client-side request/response scenarios only. It does not support:

  • Receiving D-Bus signals
  • Implementing D-Bus services (use StandardInterfaceHandler instead)
  • Complex argument marshalling (currently limited to methods without arguments)

Relationship to StandardInterfaceHandler:

  • ServiceProxy - Client-side proxy for calling remote D-Bus services
  • StandardInterfaceHandler - Server-side handler for implementing D-Bus services

Example usage:


 @DBusInterface("org.freedesktop.DBus")
 public interface DBusService {
     @DBusMethod("ListNames")
     CompletableFuture<String[]> listNames();

     @DBusMethod("GetId")
     String getId();
 }

 // Create proxy
 DBusService service = ServiceProxy.create(
     connection,
     "org.freedesktop.DBus",
     "/org/freedesktop/DBus",
     DBusService.class
 );

 // Use it - synchronous
 String id = service.getId();

 // Or asynchronous
 service.listNames().thenAccept(names -> {
     for (String name : names) {
         System.out.println(name);
     }
 });
 
  • Method Details

    • create

      public static <T> T create(Connection connection, String destination, String objectPath, Class<T> interfaceClass)
      Creates a proxy instance for the specified D-Bus service interface.
      Type Parameters:
      T - the interface type
      Parameters:
      connection - the D-Bus connection
      destination - the D-Bus service name (e.g., "org.freedesktop.DBus")
      objectPath - the object path (e.g., "/org/freedesktop/DBus")
      interfaceClass - the Java interface class with D-Bus annotations
      Returns:
      a proxy instance implementing the interface
    • create

      public static <T> T create(Connection connection, String objectPath, Class<T> interfaceClass)
      Creates a proxy with automatic interface name detection. Uses the @DBusInterface annotation value as the destination.
      Type Parameters:
      T - the interface type
      Parameters:
      connection - the D-Bus connection
      objectPath - the object path
      interfaceClass - the Java interface class with D-Bus annotations
      Returns:
      a proxy instance implementing the interface