Hi My test environment : CentOS 6.3 6.4 Ubuntu 13.10 For CentOS 6.4 libvirt-java-0.4.9-1.el6.noarch libvirt-python-0.10.2-29.el6.x86_64 libvirt-client-0.10.2-29.el6.x86_64 libvirt-0.10.2-29.el6.x86_64 I am try to use java bindings to event callback. int register = conn.domainEventRegisterAny(null, 0, cb); But always get the following error message: libvirt: Remote Driver error : adding cb to list exception caught:org.libvirt.LibvirtException: adding cb to list level:VIR_ERR_ERROR code:VIR_ERR_RPC domain:VIR_FROM_REMOTE hasConn:false hasDom:false hasNet:false message:adding cb to list str1:%s str2:adding cb to list str3:null int1:-1 int2:-1 By the way I also trace the mail list *[libvirt] [PATCH] Java bindings for domain events* (2008 Nov 07) *[libvirt] [PATCH 1/2] Java bindings for domain events**[libvirt] [PATCH 2/2] Java bindings for domain events* (2008 Nov 18) --> Reject patch*Re: [libvirt] [PATCH 1/2] Java bindings for domain events* (2008 Dec) —>No Result*[libvirt-users] Using Java bindings to event callback * (2010 Jul) —>No Result *[libvirt] [PATCH 0/2] Libvirt-java event handling (2011Jul)* —> I think most drivers don't support that. We have a custom driver for our hypervisor and it works. *[libvirt] [libvirt-java] [PATCH 00/12] event support* (2013 Jan) —> *Re: [libvirt] [libvirt-java] [PATCH 00/12] event support (2013 Mar)* --> No Result Any suggestions? Thanks, Howie
Claudio Bley
2014-Jan-23 10:57 UTC
Re: [libvirt-users] Using Java bindings to event callback
At Thu, 5 Dec 2013 16:26:36 +0800, Howie wrote:> > Hi > > My test environment : > > CentOS 6.3 6.4 > Ubuntu 13.10 > > For CentOS 6.4 > > libvirt-java-0.4.9-1.el6.noarch > libvirt-python-0.10.2-29.el6.x86_64 > libvirt-client-0.10.2-29.el6.x86_64 > libvirt-0.10.2-29.el6.x86_64 > > I am try to use java bindings to event callback. > > int register = conn.domainEventRegisterAny(null, 0, cb); > > But always get the following error message: > > libvirt: Remote Driver error : adding cb to list > exception caught:org.libvirt.LibvirtException: adding cb to list > level:VIR_ERR_ERROR > code:VIR_ERR_RPC > domain:VIR_FROM_REMOTE > hasConn:false > hasDom:false > hasNet:false > message:adding cb to list > str1:%s > str2:adding cb to list > str3:null > int1:-1 > int2:-1At first, you need to initialize an event loop - before connecting to the libvirt daemon. Then you need to run that event loop in order to process the events. If you're using an official libvirt-java release your out of luck as this is not really supported.> By the way I also trace the mail list > > *[libvirt] [PATCH] Java bindings for domain events* (2008 Nov 07) > *[libvirt] [PATCH 1/2] Java bindings for domain events**[libvirt] > [PATCH 2/2] Java bindings for domain events* (2008 Nov 18) --> Reject > patch*Re: [libvirt] [PATCH 1/2] Java bindings for domain events* (2008 > Dec) —>No Result*[libvirt-users] Using Java bindings to event > callback * (2010 Jul) —>No Result > *[libvirt] [PATCH 0/2] Libvirt-java event handling (2011Jul)* —> > I think most drivers don't support that. We have a custom driver for > our hypervisor and it works. > > *[libvirt] [libvirt-java] [PATCH 00/12] event support* (2013 Jan) > —> *Re: [libvirt] [libvirt-java] [PATCH 00/12] event support (2013 > Mar)* --> No Result > Any suggestions?I'm the author of the latter patches. I haven't had the time working on these and didn't receive solid reviews on the development list. A month ago, I began working on them again and have changed large parts of the interface to simplify it and add more features. Currently I'm testing the implementation - looks good so far; a small test program is now running since 9 days straight. Here's a small sample code to wet your appetite: ---- import org.libvirt.* import org.libvirt.event.*; class Monitor implements RebootListener, LifecycleListener { @Override public void onReboot(Domain d) { ... } @Override public int onLifecycleChange(Domain d, DomainEvent event) { ... return 0; } } // required! Connect.initEventLoop(); Connect c = new Connect("qemu:///system"); Monitor m = new Monitor(); c.addRebootListener(m); c.addLifecycleListener(m); // run event loop c.setKeepAlive(5, 3); while (c.isAlive) c.processEvent(); ---- I hope to get this upstream someday, but momentarily I'm not totally satisfied and would like to think about it once more. Anyway, comments are very welcome! Claudio -- AV-Test GmbH, Henricistraße 20, 04155 Leipzig, Germany Phone: +49 341 265 310 19 Web:<http://www.av-test.org> Eingetragen am / Registered at: Amtsgericht Stendal (HRB 114076) Geschaeftsfuehrer (CEO): Andreas Marx, Guido Habicht, Maik Morgenstern