Changeset 31166 in vbox
- Timestamp:
- Jul 28, 2010 2:38:35 PM (14 years ago)
- Location:
- trunk/src/VBox/Main/glue
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/glue/glue-java.xsl
r31096 r31166 2510 2510 } 2511 2511 2512 private static VirtualBoxManager mgr;2513 2514 public static synchronized VirtualBoxManager getInstance(String home)2515 { 2516 if ( mgr != null)2517 return mgr;2512 private static boolean hasInstance = false; 2513 2514 public static synchronized VirtualBoxManager createInstance(String home) 2515 { 2516 if (hasInstance) 2517 throw new VBoxException(null, "only one instance at the time allowed"); 2518 2518 2519 2519 if (home == null) … … 2531 2531 } 2532 2532 2533 mgr = new VirtualBoxManager(mozilla, servMgr); 2534 return mgr; 2533 hasInstance = true; 2534 2535 return new VirtualBoxManager(mozilla, servMgr); 2535 2536 } 2536 2537 … … 2545 2546 mozilla.shutdownXPCOM(servMgr); 2546 2547 mozilla = null; 2548 hasInstance = false; 2547 2549 } 2548 2550 … … 3006 3008 ISession s = getSessionObject(); 3007 3009 m.lockMachine(s, LockType.Shared); 3008 return s; 3009 } 3010 3010 return s; 3011 } 3012 3011 3013 public void closeMachineSession(ISession s) 3012 3014 { … … 3015 3017 } 3016 3018 3017 private static VirtualBoxManager mgr; 3018 3019 public static synchronized VirtualBoxManager getInstance(String home) 3020 { 3021 if (mgr != null) 3022 return mgr; 3023 3024 if (home == null) 3025 home = System.getProperty("vbox.home"); 3026 3027 mgr = new VirtualBoxManager(); 3028 return mgr; 3019 private static boolean hasInstance = false; 3020 3021 public static synchronized VirtualBoxManager createInstance(String home) 3022 { 3023 if (hasInstance) 3024 throw new VBoxException(null, "only one instance at the time allowed"); 3025 3026 hasInstance = true; 3027 return new VirtualBoxManager(); 3029 3028 } 3030 3029 … … 3032 3031 { 3033 3032 deinitPerThread(); 3034 mgr = null;3033 hasInstance = false; 3035 3034 } 3036 3035 … … 3207 3206 List<T2> ret = new ArrayList<T2>(values.size()); 3208 3207 for (T1 v : values) { 3209 // static method is called with null this 3208 // static method is called with null this 3210 3209 ret.add((T2)fromValue.invoke(null, v.name())); 3211 3210 } … … 3460 3459 } 3461 3460 3462 private static VirtualBoxManager mgr; 3463 3464 public static synchronized VirtualBoxManager getInstance(String home) 3465 { 3466 if (mgr != null) 3467 return mgr; 3468 3469 mgr = new VirtualBoxManager(); 3470 return mgr; 3461 public static synchronized VirtualBoxManager createInstance(String home) 3462 { 3463 return new VirtualBoxManager(); 3471 3464 } 3472 3465 -
trunk/src/VBox/Main/glue/tests/TestVBox.java
r31135 r31166 96 96 } 97 97 98 static void testMultiServer() 99 { 100 VirtualBoxManager mgr1 = VirtualBoxManager.createInstance(null); 101 VirtualBoxManager mgr2 = VirtualBoxManager.createInstance(null); 102 103 try { 104 mgr1.connect("http://i7:18083", "", ""); 105 mgr2.connect("http://main:18083", "", ""); 106 107 String mach1 = mgr1.getVBox().getMachines().get(0).getName(); 108 String mach2 = mgr2.getVBox().getMachines().get(0).getName(); 109 110 mgr1.startVm(mach1, null, 7000); 111 mgr2.startVm(mach2, null, 7000); 112 } finally { 113 mgr1.cleanup(); 114 mgr2.cleanup(); 115 } 116 } 117 98 118 public static void main(String[] args) 99 119 { 100 VirtualBoxManager mgr = VirtualBoxManager. getInstance(null);120 VirtualBoxManager mgr = VirtualBoxManager.createInstance(null); 101 121 102 122 boolean ws = false;
Note:
See TracChangeset
for help on using the changeset viewer.