[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 02/12] Wrap virConnectIsAlive



This adds the isAlive() method to the Connect class.

Signed-off-by: Claudio Bley <cbley av-test de>
---
 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 8da83f3..69d59b6 100644
--- a/src/main/java/org/libvirt/Connect.java
+++ b/src/main/java/org/libvirt/Connect.java
@@ -1431,4 +1431,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 b5e7503..c82ad24 100644
--- a/src/main/java/org/libvirt/jna/Libvirt.java
+++ b/src/main/java/org/libvirt/jna/Libvirt.java
@@ -120,6 +120,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 bba4cdb..5e07333 100644
--- a/src/test/java/org/libvirt/TestJavaBindings.java
+++ b/src/test/java/org/libvirt/TestJavaBindings.java
@@ -41,6 +41,7 @@ public final class TestJavaBindings extends TestCase {
         assertTrue("conn.getLibVirVersion()", conn.getLibVirVersion() > 6000);
         assertTrue("conn.connectionVersion()", Connect.connectionVersion(conn) > 6000);        
         assertEquals("conn.getLibVirVersion()", 2, conn.getVersion());
+        assertTrue("conn.isAlive", conn.isAlive());
         assertTrue("conn.isEncrypted", conn.isEncrypted() == 0);
         assertTrue("conn.isSecure", conn.isSecure() == 1);        
     }
-- 
1.7.9.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]