[libvirt-java] [PATCH 38/65] Implement Connect.setKeepAlive

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

 



This wraps the virConnectSetKeepAlive libvirt function available since
version 0.9.8.

Signed-off-by: Claudio Bley <cbley@xxxxxxxxxx>
---
 src/main/java/org/libvirt/Connect.java     |   34 ++++++++++++++++++++++++++++
 src/main/java/org/libvirt/jna/Libvirt.java |    1 +
 2 files changed, 35 insertions(+)

diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java
index d4868f0..0a45ac8 100644
--- a/src/main/java/org/libvirt/Connect.java
+++ b/src/main/java/org/libvirt/Connect.java
@@ -1395,4 +1395,38 @@ public class Connect {
     public boolean isAlive() throws LibvirtException {
         return (1 == processError(libvirt.virConnectIsAlive(VCP)));
     }
+
+    /**
+     * Start sending keepalive messages.
+     *
+     * After {@code interval} seconds of inactivity, consider the
+     * connection to be broken when no response is received after
+     * {@code count} keepalive messages sent in a row.
+     * <p>
+     * In other words, sending {@code count + 1} keepalive message
+     * results in closing the connection.
+     * <p>
+     * When interval is <= 0, no keepalive messages will be sent.
+     * <p>
+     * When count is 0, the connection will be automatically closed after
+     * interval seconds of inactivity without sending any keepalive
+     * messages.
+     * <p>
+     * <em>Note</em>: client has to implement and run event loop to be
+     * able to use keepalive messages. Failure to do so may result in
+     * connections being closed unexpectedly.
+     * <p>
+     * <em>Note</em>: This API function controls only keepalive messages sent by
+     * the client. If the server is configured to use keepalive you still
+     * need to run the event loop to respond to them, even if you disable
+     * keepalives by this function.
+     *
+     * @param interval  number of seconds of inactivity before a keepalive
+     *                  message is sent
+     * @param count     number of messages that can be sent in a row
+     * @return {@code true} when successful, {@code false} otherwise.
+     */
+    public boolean setKeepAlive(int interval, int count) throws LibvirtException {
+        return (0 == processError(libvirt.virConnectSetKeepAlive(VCP, interval, count)));
+    }
 }
diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java
index 69dabe2..2bc5b6b 100644
--- a/src/main/java/org/libvirt/jna/Libvirt.java
+++ b/src/main/java/org/libvirt/jna/Libvirt.java
@@ -162,6 +162,7 @@ public interface Libvirt extends Library {
     ConnectionPointer virConnectOpen(String name);
     ConnectionPointer virConnectOpenAuth(String name, virConnectAuth auth, int flags);
     ConnectionPointer virConnectOpenReadOnly(String name);
+    int virConnectSetKeepAlive(ConnectionPointer virConnectPtr, int interval, int count);
 
     /**
      * @deprecated as of libvirt 0.6.0, all errors reported in the
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]