Package org.libvirt

Class Library


public final class Library extends Object
This class represents an instance of the JNA mapped libvirt library. The library will get loaded when first accessing this class. Additionally, this class contains internal methods to ease implementing the public API.
  • Method Details

    • getVersion

      public static long getVersion() throws LibvirtException
      Returns the version of the native libvirt library.
      major * 1,000,000 + minor * 1,000 + release
    • initEventLoop

      public static void initEventLoop() throws LibvirtException
      Initialize the event loop. Registers a default event loop implementation based on the poll() system call.

      Once registered, the application has to invoke processEvent() in a loop or call runEventLoop() in another thread.

      Note: You must call this function before connecting to the hypervisor.

      LibvirtException - on failure
      See Also:
    • processEvent

      public static void processEvent() throws LibvirtException
      Run one iteration of the event loop.

      Applications will generally want to have a thread which invokes this method in an infinite loop:

       while (true) connection.processEvent(); 

      Failure to do so may result in connections being closed unexpectedly as a result of keepalive timeout.

      LibvirtException - on failure
      See Also:
    • runEventLoop

      public static void runEventLoop() throws LibvirtException, InterruptedException
      Runs the event loop. This method blocks until stopEventLoop() is called or an exception is thrown.

      Usually, this method is run in another thread.

      LibvirtException - if there was an error during the call of a native libvirt function
      InterruptedException - if this thread was interrupted by a call to Thread.interrupt()
    • stopEventLoop

      public static void stopEventLoop() throws LibvirtException
      Stops the event loop. This methods stops an event loop when an event loop is currently running, otherwise it does nothing.
      See Also: