This wraps the virConnectIsAlive libvirt function available since version 0.9.8. Signed-off-by: Claudio Bley <cbley@xxxxxxxxxx> --- src/main/java/org/libvirt/Connect.java | 12 ++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 1 + src/test/java/org/libvirt/TestJavaBindings.java | 1 + 3 files changed, 14 insertions(+) diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java index d92976e..d4868f0 100644 --- a/src/main/java/org/libvirt/Connect.java +++ b/src/main/java/org/libvirt/Connect.java @@ -1383,4 +1383,16 @@ public class Connect { public boolean isConnected() throws LibvirtException { return ( ( VCP != null ) ? true : false ); } + + /** + * Determine if the connection to the hypervisor is still alive. + * <p> + * A connection will be classed as alive if it is either local, + * or running over a channel (TCP or UNIX socket) which is not closed. + * + * @return {@code true} if alive, {@code false} otherwise. + */ + public boolean isAlive() throws LibvirtException { + return (1 == processError(libvirt.virConnectIsAlive(VCP))); + } } diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index ae03f18..69dabe2 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -128,6 +128,7 @@ public interface Libvirt extends Library { int virConnectDomainEventRegisterAny(ConnectionPointer virConnectPtr, DomainPointer virDomainPtr, int eventID, Libvirt.VirConnectDomainEventGenericCallback cb, Pointer opaque, Libvirt.VirFreeCallback freecb); int virConnectDomainEventDeregisterAny(ConnectionPointer virConnectPtr, int callbackID) ; void virConnSetErrorFunc(ConnectionPointer virConnectPtr, Pointer userData, VirErrorCallback callback); + int virConnectIsAlive(ConnectionPointer virConnectPtr); int virConnectIsEncrypted(ConnectionPointer virConnectPtr) ; int virConnectIsSecure(ConnectionPointer virConnectPtr) ; String virConnectFindStoragePoolSources(ConnectionPointer virConnectPtr, String type, String srcSpec, int flags); diff --git a/src/test/java/org/libvirt/TestJavaBindings.java b/src/test/java/org/libvirt/TestJavaBindings.java index 91f8df4..5cc77e7 100644 --- a/src/test/java/org/libvirt/TestJavaBindings.java +++ b/src/test/java/org/libvirt/TestJavaBindings.java @@ -42,6 +42,7 @@ public final class TestJavaBindings extends TestCase { assertTrue("conn.getLibVirVersion()", conn.getLibVirVersion() > 6000); assertTrue("conn.connectionVersion()", Connect.connectionVersion(conn) > 6000); assertEquals("conn.getVersion()", 2, conn.getVersion()); + assertTrue("conn.isAlive", conn.isAlive()); assertTrue("conn.isEncrypted", conn.isEncrypted() == 0); assertTrue("conn.isSecure", conn.isSecure() == 1); } -- 1.7.9.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list