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.
"The given session is busy"
-
rafaelbraga
- Posts: 3
- Joined: 1. Sep 2011, 21:20
- Primary OS: Ubuntu other
- VBox Version: OSE Debian
- Guest OSses: Ubuntu
-
Sasquatch
- Volunteer
- Posts: 17798
- Joined: 17. Mar 2008, 13:41
- Primary OS: Debian other
- VBox Version: VirtualBox+Oracle ExtPack
- Guest OSses: Windows XP, Windows 7, Linux
- Location: /dev/random
Re: "The given session is busy"
Where's the machine to edit?
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org
Retired from this Forum since OSSO introduction.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org
Retired from this Forum since OSSO introduction.
-
rafaelbraga
- Posts: 3
- Joined: 1. Sep 2011, 21:20
- Primary OS: Ubuntu other
- VBox Version: OSE Debian
- Guest OSses: Ubuntu
Re: "The given session is busy"
on my own computer. everything happens on my machine: the Java code and virtual machines.
-
Sasquatch
- Volunteer
- Posts: 17798
- Joined: 17. Mar 2008, 13:41
- Primary OS: Debian other
- VBox Version: VirtualBox+Oracle ExtPack
- Guest OSses: Windows XP, Windows 7, Linux
- Location: /dev/random
Re: "The given session is busy"
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.
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org
Retired from this Forum since OSSO introduction.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org
Retired from this Forum since OSSO introduction.
-
Leak
- Posts: 242
- Joined: 31. Mar 2009, 13:00
- Primary OS: MS Windows 7
- VBox Version: VirtualBox+Oracle ExtPack
- Guest OSses: Debian Testing, Windows XP, Windows Server 2003/2008 R2
Re: "The given session is busy"
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*.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
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?
-
rafaelbraga
- Posts: 3
- Joined: 1. Sep 2011, 21:20
- Primary OS: Ubuntu other
- VBox Version: OSE Debian
- Guest OSses: Ubuntu
Re: "The given session is busy"
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();
}
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();
}