Class Bus

java.lang.Object
lol.trq.orpheus.linux.dbus.Bus
All Implemented Interfaces:
AutoCloseable

public final class Bus extends Object implements AutoCloseable
A connection to a D-Bus message bus: authentication, sending, and one reader thread that completes method calls and hands every other message to a listener. Small on purpose: only what talking to media players needs.
  • Method Details

    • connect

      public static Bus connect(String socketPath, Consumer<Message> listener, Runnable onClose) throws IOException
      Opens a Unix socket, authenticates as the current user and starts reading.
      Parameters:
      socketPath - the bus socket
      listener - receives signals and incoming method calls, on the reader thread
      onClose - runs once, on the reader thread, when the connection ends for any reason but close()
      Throws:
      IOException
    • send

      public void send(Message message) throws IOException
      Sends a message without waiting for anything.
      Throws:
      IOException
    • call

      public CompletableFuture<Message> call(Message message)
      Sends a method call. The future completes with the reply, which may be an error reply, or fails when the connection ends first. It never completes on its own if the peer stays silent: callers add a timeout.
    • close

      public void close()
      Closes the connection, fails calls still waiting and stops the reader thread.
      Specified by:
      close in interface AutoCloseable