Package org.libvirt

Class Library


  • public final class Library
    extends java.lang.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 Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static long getVersion()
      Returns the version of the native libvirt library.
      static void initEventLoop()
      Initialize the event loop.
      static void processEvent()
      Run one iteration of the event loop.
      static void runEventLoop()
      Runs the event loop.
      static void stopEventLoop()
      Stops the event loop.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getVersion

        public static long getVersion()
                               throws LibvirtException
        Returns the version of the native libvirt library.
        Returns:
        major * 1,000,000 + minor * 1,000 + release
        Throws:
        LibvirtException
      • 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.

        Throws:
        LibvirtException - on failure
        See Also:
        processEvent(), runLoop
      • 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.

        Throws:
        LibvirtException - on failure
        See Also:
        initEventLoop()
      • runEventLoop

        public static void runEventLoop()
                                 throws LibvirtException,
                                        java.lang.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.

        Throws:
        LibvirtException - if there was an error during the call of a native libvirt function
        java.lang.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.
        Throws:
        LibvirtException
        See Also:
        runEventLoop()