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

[libvirt] [libvirt-java] [PATCH 11/15] Remove processError method from Stream class



Wrap any fallible libvirt function in a call to
ErrorHandler.processError(..).

Also correct wrong javadoc comments stating that methods would return
a value in case an error occurs.
---
 src/main/java/org/libvirt/Stream.java | 64 +++++++++++------------------------
 1 file changed, 20 insertions(+), 44 deletions(-)

diff --git a/src/main/java/org/libvirt/Stream.java b/src/main/java/org/libvirt/Stream.java
index bd8e87f..fae9729 100644
--- a/src/main/java/org/libvirt/Stream.java
+++ b/src/main/java/org/libvirt/Stream.java
@@ -3,6 +3,7 @@ package org.libvirt;
 import org.libvirt.jna.Libvirt;
 import org.libvirt.jna.StreamPointer;
 import static org.libvirt.Library.libvirt;
+import static org.libvirt.ErrorHandler.processError;
 
 import com.sun.jna.NativeLong;
 
@@ -28,11 +29,11 @@ public class Stream {
     /**
      * Request that the in progress data transfer be cancelled abnormally before
      * the end of the stream has been reached
+     *
+     * @return <em>ignore</em> (always 0)
      */
     public int abort() throws LibvirtException {
-        int returnValue = libvirt.virStreamAbort(VSP);
-        processError();
-        return returnValue;
+        return processError(libvirt.virStreamAbort(VSP));
     }
 
     /**
@@ -46,13 +47,11 @@ public class Stream {
      *            the events to monitor
      * @param cb
      *            the callback method
-     * @return 0 for success, -1 for failure
+     * @return <em>ignore</em> (always 0)
      * @throws LibvirtException
      */
     public int addCallback(int events, Libvirt.VirStreamEventCallback cb) throws LibvirtException {
-        int returnValue = libvirt.virStreamEventAddCallback(VSP, events, cb, null, null);
-        processError();
-        return returnValue;
+        return processError(libvirt.virStreamEventAddCallback(VSP, events, cb, null, null));
     }
 
     @Override
@@ -64,27 +63,24 @@ public class Stream {
      * Indicate that there is no further data is to be transmitted on the
      * stream.
      *
-     * @return 0 if success, -1 if failure
+     * @return <em>ignore</em> (always 0)
      * @throws LibvirtException
      */
     public int finish() throws LibvirtException {
-        int returnValue = libvirt.virStreamFinish(VSP);
-        processError();
-        return returnValue;
+        return processError(libvirt.virStreamFinish(VSP));
     }
 
     /**
      * Decrement the reference count on a stream, releasing the stream object if
      * the reference count has hit zero.
      *
+     * @return <em>ignore</em> (always 0)
      * @throws LibvirtException
-     * @return 0 on success, or -1 on error.
      */
     public int free() throws LibvirtException {
         int success = 0;
         if (VSP != null) {
-            success = libvirt.virStreamFree(VSP);
-            processError();
+            processError(libvirt.virStreamFree(VSP));
             VSP = null;
         }
 
@@ -92,14 +88,6 @@ public class Stream {
     }
 
     /**
-     * Error handling logic to throw errors. Must be called after every libvirt
-     * call.
-     */
-    protected void processError() throws LibvirtException {
-        virConnect.processError();
-    }
-
-    /**
      * Receives data from the stream into the buffer provided.
      *
      * @param data
@@ -108,9 +96,7 @@ public class Stream {
      * @throws LibvirtException
      */
     public int receive(byte[] data) throws LibvirtException {
-        int returnValue = libvirt.virStreamRecv(VSP, data, new NativeLong(data.length));
-        processError();
-        return returnValue;
+        return processError(libvirt.virStreamRecv(VSP, data, new NativeLong(data.length)));
     }
 
     /**
@@ -119,26 +105,22 @@ public class Stream {
      * @see <a href="http://www.libvirt.org/html/libvirt-libvirt.html#virStreamRecvAll";>virStreamRecvAll</a>
      * @param handler
      *            the callback handler
-     * @return 0 if successfule, -1 otherwise
+     * @return <em>ignore</em> (always 0)
      * @throws LibvirtException
      */
     public int receiveAll(Libvirt.VirStreamSinkFunc handler) throws LibvirtException {
-        int returnValue = libvirt.virStreamRecvAll(VSP, handler, null);
-        processError();
-        return returnValue;
+        return processError(libvirt.virStreamRecvAll(VSP, handler, null));
     }
 
     /**
      * Remove an event callback from the stream
      *
      * @see <a href="http://www.libvirt.org/html/libvirt-libvirt.html#virStreamEventRemoveCallback";>Libvirt Docs</a>
-     * @return 0 for success, -1 for failure
+     * @return <em>ignore</em> (always 0)
      * @throws LibvirtException
      */
     public int removeCallback() throws LibvirtException {
-        int returnValue = libvirt.virStreamEventRemoveCallback(VSP);
-        processError();
-        return returnValue;
+        return processError(libvirt.virStreamEventRemoveCallback(VSP));
     }
 
     /**
@@ -151,9 +133,7 @@ public class Stream {
      * @throws LibvirtException
      */
     public int send(String data) throws LibvirtException {
-        int returnValue = libvirt.virStreamSend(VSP, data, new NativeLong(data.length()));
-        processError();
-        return returnValue;
+        return processError(libvirt.virStreamSend(VSP, data, new NativeLong(data.length())));
     }
 
     /**
@@ -164,13 +144,11 @@ public class Stream {
      *      Documentation</a>
      * @param handler
      *            the callback handler
-     * @return 0 if successfule, -1 otherwise
+     * @return <em>ignore</em> (always 0)
      * @throws LibvirtException
      */
     public int sendAll(Libvirt.VirStreamSourceFunc handler) throws LibvirtException {
-        int returnValue = libvirt.virStreamSendAll(VSP, handler, null);
-        processError();
-        return returnValue;
+        return processError(libvirt.virStreamSendAll(VSP, handler, null));
     }
 
     /**
@@ -179,12 +157,10 @@ public class Stream {
      * @see <a href="http://www.libvirt.org/html/libvirt-libvirt.html#virStreamEventUpdateCallback";>Libvirt Docs</a>
      * @param events
      *            the events to monitor
-     * @return 0 for success, -1 for failure
+     * @return <em>ignore</em> (always 0)
      * @throws LibvirtException
      */
     public int updateCallback(int events) throws LibvirtException {
-        int returnValue = libvirt.virStreamEventUpdateCallback(VSP, events);
-        processError();
-        return returnValue;
+        return processError(libvirt.virStreamEventUpdateCallback(VSP, events));
     }
 }
-- 
1.8.5.2.msysgit.0


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