Page 1 of 1

"The given session is busy"

Posted: 1. Sep 2011, 21:24
by rafaelbraga
Hello, I am beginner in virtualbox java API and now I need
change the memory size of a vm. I am using the following code:

public void setMemorySize() {
VirtualBoxManager mgr = VirtualBoxManager.createInstance(null);
ISession session = mgr.getSessionObject();
IVirtualBox vbox = mgr.getVBox();

IMachine machine = vbox.getMachines().get(1);
IProgress progress = machine.launchVMProcess(session, "gui", "");
progress.waitForCompletion(-1);
machine.lockMachine(session, LockType.Write); // machine is now locked for writing
IMachine mutable = session.getMachine();
// obtain the mutable machine copy
mutable.setMemorySize((long) 1024);
mutable.saveSettings();
// write settings to XML
session.unlockMachine();
}

But, returns the following error:

Exception in thread "main" org.virtualbox_4_1.VBoxException: The function "lockMachine" returned an error condition: "The given session is busy" (0x80bb0007)
at org.virtualbox_4_1.IMachine.lockMachine(IMachine.java:798)
at teste.elasticidade.IniciaVM.setMemorySize(IniciaVM.java:51)
at teste.elasticidade.IniciaVM.main(IniciaVM.java:37)


what may be happening?

thanks a lot.

Re: "The given session is busy"

Posted: 1. Sep 2011, 23:43
by Sasquatch
Where's the machine to edit?

Re: "The given session is busy"

Posted: 2. Sep 2011, 00:26
by rafaelbraga
on my own computer. everything happens on my machine: the Java code and virtual machines.

Re: "The given session is busy"

Posted: 2. Sep 2011, 19:34
by Sasquatch
I meant in the code. There is no VM defined. From what I know about Java, you had to either put it in the code, or give it as a variable from an argument or something. I'm missing that, including some more code. In order to help you, we need the whole program to see if you actually provide a VM name. Else it makes perfect sense, because you can't change something that doesn't exist. It then gives the error about being busy as it doesn't know what you want.

Re: "The given session is busy"

Posted: 3. Sep 2011, 12:06
by Leak
rafaelbraga wrote:

Code: Select all

        IMachine machine = vbox.getMachines().get(1);
        IProgress progress = machine.launchVMProcess(session, "gui", "");
        progress.waitForCompletion(-1);
        machine.lockMachine(session, LockType.Write); // machine is now locked for writing
Now, I haven't ever used any of the supported APIs to manipulate VMs, but what you're doing here is basically starting up a VM and then trying to change it's assigned amount of memory *while it is running*.

That of course isn't possible when doing it by hand from the VirtualBox GUI, so what made you think it would work programmatically?

Or were you just copying and pasting code examples without considering what was happening?

Re: "The given session is busy"

Posted: 3. Sep 2011, 14:03
by rafaelbraga
see the class:

package test.elasticity;

import org.virtualbox_4_1.*;

public class StartVM {

public void setMemorySize() {
VirtualBoxManager mgr = VirtualBoxManager.createInstance(null);
ISession session = mgr.getSessionObject();
IVirtualBox vbox = mgr.getVBox();

IMachine machine = vbox.getMachines().get(1); // the number of the machine, isn't identify by name.
IProgress progress = machine.launchVMProcess(session, "gui", "");
progress.waitForCompletion(-1);
machine.lockMachine(session, LockType.Write); // machine is now locked for writing
IMachine mutable = session.getMachine();
// obtain the mutable machine copy
mutable.setMemorySize((long) 1024);
mutable.saveSettings();
// write settings to XML
session.unlockMachine();
}

public static void main(String[] args) {
StartVM vm = new StartVM();
vm.setMemorySize();
}