Refactoring: Fix null checking logic.
authorminkee.lee <minkee.lee@samsung.com>
Tue, 2 Sep 2014 05:14:05 +0000 (14:14 +0900)
committerminkee.lee <minkee.lee@samsung.com>
Thu, 16 Oct 2014 12:37:12 +0000 (21:37 +0900)
Change-Id: I6cbd545c03a60fe0a20d94db53f212d2c95d46eb
Signed-off-by: minkee.lee <minkee.lee@samsung.com>
common-project/src/org/tizen/emulator/manager/console/ConsoleProcessor.java
common-project/src/org/tizen/emulator/manager/vms/VMProperty.java
common-project/src/org/tizen/emulator/manager/vms/VMWorkerCommon.java
common-project/src/org/tizen/emulator/manager/vms/helper/CheckingRunningEmulator.java

index 461e2ff..41d62af 100644 (file)
@@ -215,7 +215,12 @@ public class ConsoleProcessor {
 
                List<String> cmd;
                try {
-                       cmd = prop.getWorker().getLauncher().getLaunchCommand(prop, path);
+                       ILauncher launcher = prop.getWorker().getLauncher();
+                       if (launcher == null) {
+                               throw new VMWorkerException("Fail to get launcher");
+                       }
+                       cmd = launcher.getLaunchCommand(prop, path);
+
                } catch (VMWorkerException e) {
                        EMLogger.getLogger().log(Level.WARNING, "Failed to launch :" + e.getMessage());
                        System.out.println("Error: " + "Failed to launch: " + e.getMessage());
index 58c8b16..90b8e92 100644 (file)
@@ -83,10 +83,14 @@ public class VMProperty {
                if (item != null) {
                        worker = (VMWorkerCommon)item.createInstance();
                }
-               if (worker != null) {
-                       worker.setVMProperty(this);
-                       worker.initLauncher();
+
+               if (worker == null) {
+                       worker = new VMWorkerCommon();
                }
+
+               worker.setVMProperty(this);
+               worker.initLauncher();
+
        }
 
        // TODO
@@ -111,9 +115,13 @@ public class VMProperty {
        }
 
        public VMWorkerCommon getWorker() {
+               if (worker == null) {
+                       worker = new VMWorkerCommon();
+                       worker.setVMProperty(this);
+               }
                return worker;
        }
-       
+
        public String getName() {
                if(configuration == null
                                || configuration.getBaseInformation() == null) {
index 2e98a9b..836367c 100644 (file)
@@ -50,14 +50,16 @@ import org.tizen.emulator.manager.vms.helper.VMWorkerException;
 import org.tizen.emulator.manager.vms.helper.WorkerLock;
 
 
-public abstract class VMWorkerCommon {
+public class VMWorkerCommon {
        private VMProperty property;
        private ILauncher launcher;
        private WorkerThread worker  = null;
        private String baseImagePath = null;
        private String baseImagePartPath = null;
 
-       public abstract void initLauncher();
+       public void initLauncher() {
+
+       }
 
        protected void setLauncher(ILauncher launcher) {
                this.launcher = launcher;
index 8419106..afa44e0 100644 (file)
@@ -49,6 +49,7 @@ import org.tizen.emulator.manager.logging.EMLogger;
 import org.tizen.emulator.manager.ui.VMsMainView;
 import org.tizen.emulator.manager.ui.dialog.MessageDialog;
 import org.tizen.emulator.manager.vms.EmulatorVMList;
+import org.tizen.emulator.manager.vms.ILauncher;
 import org.tizen.emulator.manager.vms.VMProperty;
 import org.tizen.emulator.manager.vms.helper.VMSocketQueue.QueueObject;
 
@@ -140,8 +141,9 @@ public class CheckingRunningEmulator {
                } else {
                        addLaunchedVMList(prop.getName());
                        connectToECS(prop);
-                       if (prop.getWorker() != null) {
-                               prop.getWorker().getLauncher().sendRemoteLog("start");
+                       ILauncher launcher = prop.getWorker().getLauncher();
+                       if (launcher != null) {
+                               launcher.sendRemoteLog("start");
                        }
                }
        }
@@ -414,14 +416,11 @@ public class CheckingRunningEmulator {
                }
 
                private static void setVMExit(VMSocket vms) {
-                       if (vms != null) {
-                               if (vms.getProperty() != null && vms.getProperty().getWorker() != null) {
-                                       vms.getProperty().getWorker().getLauncher().sendRemoteLog("stop");
+                       if (vms.getProperty() != null) {
+                               ILauncher launcher = vms.getProperty().getWorker().getLauncher();
+                               if (launcher != null) {
+                                       launcher.sendRemoteLog("stop");
                                }
-                               // Check remote.
-//                             if (isRemote(vms.getProperty())) {
-//                                     killServer(vms);
-//                             }
                        }
                        disconnect(vms);
                }