[Title] emulator-manager : add monitoring emulator's start
authorjihye kim <jihye1128.kim@samsung.com>
Tue, 2 Apr 2013 04:12:05 +0000 (13:12 +0900)
committerjihye kim <jihye1128.kim@samsung.com>
Tue, 2 Apr 2013 04:16:16 +0000 (13:16 +0900)
[Desc.] add monitoring emulator's start
[Issue] N/A

Change-Id: I7e8dd39535bd758a2f00ce42a215c8e16981b3a8

package/changelog
package/pkginfo.manifest
src/org/tizen/emulator/manager/EmulatorManager.java
src/org/tizen/emulator/manager/console/ConsoleProcessor.java
src/org/tizen/emulator/manager/image/SkinList.java
src/org/tizen/emulator/manager/tool/CheckVirtualization.java
src/org/tizen/emulator/manager/tool/SelectWorkspace.java
src/org/tizen/emulator/manager/vms/Launcher.java
src/org/tizen/emulator/manager/vms/MonitoringEmulator.java [new file with mode: 0644]
src/org/tizen/emulator/manager/vms/VMsWorker.java

index 351a4d4..961dd1a 100644 (file)
@@ -1,3 +1,7 @@
+* 2.1.4
+- add monitoring emulator's start
+== jihye kim <jihye1128.kim@samsung.com> 2013-04-02
+
 * 2.1.3
 - modify module of open browser (tizendevelop site)
 == jihye kim <jihye1128.kim@samsung.com> 2013-03-21
index 0eb1f7a..3be9bcf 100644 (file)
@@ -1,5 +1,5 @@
 Source: emulator-manager
-Version: 2.1.3
+Version: 2.1.4
 Maintainer: Yeong-Kyoon Lee<yeongkyoon.lee@samsung.com>
 
 Package: emulator-manager
index 56fe688..be1fc5a 100755 (executable)
@@ -282,7 +282,7 @@ public class EmulatorManager {
                if (isConsoleMode) {
                        instance.startConsoleProcessor();
                } else {
-                       EMLogger.getLogger().log(Level.INFO, "Start Emulator Manager!!" + StringResource.NEW_LINE);
+                       EMLogger.getLogger().log(Level.INFO, "Start Emulator Manager!!");
 
                        instance.preare();
                        instance.DrawUI();
index f682944..11c16a7 100644 (file)
@@ -40,8 +40,10 @@ import org.tizen.emulator.manager.image.BaseImage;
 import org.tizen.emulator.manager.image.Platform;
 import org.tizen.emulator.manager.logging.EMLogger;
 import org.tizen.emulator.manager.tool.About;
+import org.tizen.emulator.manager.vms.CheckingRunningEmulator;
 import org.tizen.emulator.manager.vms.EmulatorVMs;
 import org.tizen.emulator.manager.vms.Launcher;
+import org.tizen.emulator.manager.vms.MonitoringEmulator;
 import org.tizen.emulator.manager.vms.VMCreateHelper;
 import org.tizen.emulator.manager.vms.VMsProperty;
 import org.tizen.emulator.manager.vms.VMsWorkerException;
@@ -234,8 +236,20 @@ public class ConsoleProcessor {
                                return false;
                        }
 
-                       if (launcher.launch(cmd)) {
-                               System.out.println("Success: To start emulator is completed.");
+                       CheckingRunningEmulator.addEmulator(prop.getName());
+                       MonitoringEmulator monitor = new MonitoringEmulator(prop);
+                       Process process = launcher.launch(cmd);
+                       if (process != null) {
+                               monitor.setProcess(process, 5);
+                               monitor.start();
+                               try {
+                                       monitor.join();
+                               } catch (InterruptedException e) {
+                                       System.out.println(e.getMessage());
+                               }
+                               if (monitor.isSuccess()) {
+                                       System.out.println("Success: To start emulator is completed.");
+                               }
                        } else {
                                System.out.println("Error: Faile to start emulator.");
                                return false;
index c17d06f..691ed26 100644 (file)
@@ -59,11 +59,13 @@ public class SkinList {
                        EMLogger.getLogger().warning(e.getMessage());
                }
 
+               /*
                try {
                        skinsList.add(new Skins(new File(FilePath.getInstance().getDataSkinPath())));
                } catch (IOException e) {
                        EMLogger.getLogger().warning(e.getMessage());
                }
+               */
 
                for (Skins skins : skinsList) {
                        for (Skin s : skins.getSkinList()) {
index 3b3c320..66edfa5 100644 (file)
@@ -148,13 +148,13 @@ public class CheckVirtualization {
                                        process = pb.start();
                                        process.waitFor();
                                        exitValue = process.exitValue();
-                                       EMLogger.getLogger().log(Level.INFO, "Check-hax.exe's exit value : " + exitValue);
+                                       EMLogger.getLogger().log(Level.INFO, "Check-hax.exe's exit value: " + exitValue);
                                } catch (IOException e) {
-                                       EMLogger.getLogger().log(Level.INFO, "IOException" + e.getMessage());
+                                       EMLogger.getLogger().log(Level.WARNING, "IOException" + e.getMessage());
                                }  catch (InterruptedException e) {
-                                       EMLogger.getLogger().log(Level.INFO, "InterruptedException" + e.getMessage());
+                                       EMLogger.getLogger().log(Level.WARNING, "InterruptedException" + e.getMessage());
                                }  catch (Exception e) {
-                                       EMLogger.getLogger().log(Level.INFO, "Exception" + e.getMessage());
+                                       EMLogger.getLogger().log(Level.WARNING, "Exception" + e.getMessage());
                                }
 
                                if(exitValue == 0) {
@@ -194,7 +194,7 @@ public class CheckVirtualization {
                                process = pb.start();
                                process.waitFor();
                                exitValue = process.exitValue();
-                               EMLogger.getLogger().log(Level.WARNING, "'check-gl's exit value : " + exitValue);
+                               EMLogger.getLogger().log(Level.INFO, "'check-gl's exit value: " + exitValue);
                        } catch (IOException e) {
                                EMLogger.getLogger().log(Level.WARNING, "IOException" + e.getMessage());
                        }  catch (InterruptedException e) {
index 35fff3b..ad9f381 100644 (file)
@@ -76,7 +76,8 @@ public class SelectWorkspace {
                try {
                        inputStream = new FileInputStream(workspaceConfPath);
                } catch (FileNotFoundException e1) {
-                       EMLogger.getLogger().log(Level.WARNING, "Faile to get current workspace: \n"+ e1.getMessage());
+                       EMLogger.getLogger().log(Level.WARNING, "Faile to get current workspace:"
+                                               + StringResource.NEW_LINE + e1.getMessage());
                        createPropertyFile(workspaceConfPath);
                        return false;
                }
@@ -84,7 +85,8 @@ public class SelectWorkspace {
                try {
                        prop.load(inputStream);
                } catch (IOException e) {
-                       EMLogger.getLogger().log(Level.WARNING, "Faile to get current workspace: \n" + e.getMessage());
+                       EMLogger.getLogger().log(Level.WARNING, "Faile to get current workspace:"
+                                               + StringResource.NEW_LINE + e.getMessage());
                        result = false;
                }
 
@@ -257,7 +259,7 @@ public class SelectWorkspace {
                        }
 
                logger.log(Level.INFO, String.format(
-                               "Network name = %s, MAC = %s\n",
+                               "Network name = %s, MAC = %s",
                                ni.getDisplayName(), macAddr));
        }
 
@@ -279,12 +281,12 @@ public class SelectWorkspace {
                } catch (SocketException e) {
                        logger.log(
                                        Level.WARNING,
-                                       String.format("Failed to get MAC address of host: %s\n",
+                                       String.format("Failed to get MAC address of host: %s",
                                                        e.getMessage()));
                } catch (UnknownHostException e) {
                        logger.log(
                                        Level.WARNING,
-                                       String.format("Failed to get MAC address of host: %s\n",
+                                       String.format("Failed to get MAC address of host: %s",
                                                        e.getMessage()));
                }
 
@@ -391,7 +393,7 @@ public class SelectWorkspace {
                                /* means both MAC_ADDRESS key and value are existed */
                                else {
                                        logger.log(Level.INFO,
-                                                       String.format("Use original MAC = %s\n", macAddr));
+                                                       String.format("Use original MAC = %s", macAddr));
                                }
 
                                if (workspacePath == null) {
@@ -459,11 +461,13 @@ public class SelectWorkspace {
                        if(!fi.mkdirs()) {
                                if (!EmulatorManager.isConsoleMode()) {
                                        MessageDialog msg = new MessageDialog(new Shell(Display.getCurrent()));
-                                       msg.openWarningDialog("Can not organize workspace. Aborting...\n" +
-                                                       "User do not have authority to use [" + path + "]"); 
+                                       msg.openWarningDialog("Can not organize workspace. Aborting..."
+                                                       + StringResource.NEW_LINE
+                                                       + "User do not have authority to use [" + path + "]");
                                }
-                               EMLogger.getLogger().log(Level.WARNING, "Can not organize workspace. Aborting...\n" +
-                                                                               "User do not have authority to use [" + path + "]");
+                               EMLogger.getLogger().log(Level.WARNING, "Can not organize workspace. Aborting..."
+                                                       + StringResource.NEW_LINE
+                                                       + "User do not have authority to use [" + path + "]");
                                EmulatorManager.exitEmulatorManager(-1);
                        }
                }
index 2896d9a..53208a8 100644 (file)
 
 package org.tizen.emulator.manager.vms;
 
-import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.IOException;
-import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.logging.Level;
@@ -384,7 +382,9 @@ public class Launcher {
 
                CheckingRunningEmulator.addEmulator(property.getName());
                MonitoringEmulator monitor = new MonitoringEmulator(property);
-               if (launch(cmd)) {
+               Process process = launch(cmd);
+               if (process != null) {
+                       monitor.setProcess(process);
                        monitor.start();
                        return true;
                } else {
@@ -394,7 +394,7 @@ public class Launcher {
                }
        }
 
-       public boolean launch(List<String> cmd) {
+       public Process launch(List<String> cmd) {
                FilePath fio = FilePath.getInstance();
                ProcessBuilder pb = new ProcessBuilder(cmd);
                
@@ -403,76 +403,17 @@ public class Launcher {
                } else {
                        pb.directory(new File(this.binPath));
                }
-               
+               Process process = null;
                try {
-                       Process process = pb.start();
-
-                       final InputStream in1 = new BufferedInputStream(process.getInputStream());
-                       final InputStream in2 = new BufferedInputStream(process.getErrorStream());
-                       
-                       new Thread(new Runnable() {
-                               @Override
-                               public void run() {
-                                       try {
-                                               in1.read();
-                                       } catch (IOException e) {
-                                               e.printStackTrace();
-                                       }
-                               }
-                       }).start();
-
-                       new Thread(new Runnable() {
-                               @Override
-                               public void run() {
-                                       try {
-                                               in2.read();
-                                       } catch (IOException e) {
-                                               e.printStackTrace();
-                                       }
-                               }
-                       }).start();
-
+                       process = pb.start();
                } catch (IOException e) {
                        if (!isConsole) {                       
                                MessageDialog msg = new MessageDialog(new Shell(Display.getCurrent()));
                                msg.openWarningDialog("Failed to launch\n" + e.getMessage());
                        }
                        EMLogger.getLogger().log(Level.WARNING, "Failed to launch.\n" + e.getMessage());
-                       return false;
                }
                
-               return true;
-       }
-}
-
-class MonitoringEmulator extends Thread {
-       private VMsProperty property;
-       public MonitoringEmulator(VMsProperty property) {
-               this.property = property;
-               this.setDaemon(true);
-       }
-
-       public void run() {
-               boolean isChecking = false;
-               for (int i = 0; i < 8 ; i++) {
-                       if (VMsWorker.checking(property)) {
-                               isChecking = true;
-                               CheckingRunningEmulator.removeEmulator(property.getName());
-                               break;
-                       }
-
-                       synchronized(this) {
-                               try {
-                                       this.wait(1000);
-                               } catch (InterruptedException e) {
-                                       EMLogger.getLogger().warning(e.getMessage());
-                                       break;
-                               }
-                       }
-               }
-
-               if (!isChecking) {
-                       CheckingRunningEmulator.removeEmulator(property.getName());
-               }
+               return process;
        }
 }
\ No newline at end of file
diff --git a/src/org/tizen/emulator/manager/vms/MonitoringEmulator.java b/src/org/tizen/emulator/manager/vms/MonitoringEmulator.java
new file mode 100644 (file)
index 0000000..a4643aa
--- /dev/null
@@ -0,0 +1,175 @@
+package org.tizen.emulator.manager.vms;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import org.eclipse.swt.widgets.Display;
+import org.tizen.emulator.manager.EmulatorManager;
+import org.tizen.emulator.manager.logging.EMLogger;
+import org.tizen.emulator.manager.tool.StringResource;
+import org.tizen.emulator.manager.ui.MessageDialog;
+
+public class MonitoringEmulator extends Thread {
+       private VMsProperty property;
+       private Process process;
+       private int count = 8;
+
+       public MonitoringEmulator(VMsProperty property) {
+               this.property = property;
+               this.setDaemon(true);
+       }
+
+       public void setProcess(Process process) {
+               this.process = process;
+       }
+
+       public void setProcess(Process process, int count) {
+               this.process = process;
+               this.count = count;
+       }
+
+       private BufferedReader readerOut   = null;
+       private BufferedReader readerError = null;
+       private StdOut stdOut = null;
+       private StdOut stdErr = null;
+       private boolean success = true;
+
+       public void run() {
+               /*
+               boolean isChecking = false;
+               for (int i = 0; i < 8 ; i++) {
+                       if (VMsWorker.checking(property)) {
+                               isChecking = true;
+                               CheckingRunningEmulator.removeEmulator(property.getName());
+                               break;
+                       }
+
+                       synchronized(this) {
+                               try {
+                                       this.wait(1000);
+                               } catch (InterruptedException e) {
+                                       EMLogger.getLogger().warning(e.getMessage());
+                                       break;
+                               }
+                       }
+               }
+
+               if (!isChecking) {
+                       CheckingRunningEmulator.removeEmulator(property.getName());
+               }
+               */
+               if (process == null || property == null) {
+                       return;
+               }
+
+               InputStreamReader in1 = new InputStreamReader(process.getInputStream());
+               InputStreamReader in2 = new InputStreamReader(process.getErrorStream());
+               readerOut = new BufferedReader(in1);
+               readerError = new BufferedReader(in2);
+
+               stdOut = new StdOut(readerOut, property.getName());
+               stdErr = new StdOut(readerError, property.getName());
+
+               new Thread(stdOut).start();
+               new Thread(stdErr).start();
+
+               for (int i = 0; i < count; i++) {
+                       try {
+                               if (process.exitValue() != 0) {
+                                       setSuccess(false);
+                                       stdOut.printMessageList();
+                                       stdErr.printMessageList();
+                                       EMLogger.getLogger().warning("Emulator has been terminated. Exit value: " + process.exitValue()
+                                                       + StringResource.NEW_LINE
+                                                       + "You can see more information in the emulator-manager.log or "
+                                                       + property.getName() + "'s logs directory.");
+                                       if (!EmulatorManager.isConsoleMode()) {
+                                               Display.getDefault().asyncExec(new Runnable(){
+
+                                                       @Override
+                                                       public void run() {
+                                                               new MessageDialog().openWarningDialog("Emulator has been terminated."
+                                                                               + StringResource.NEW_LINE
+                                                                               + "You can see more information "
+                                                                               + StringResource.NEW_LINE
+                                                                               + "in the emulator-manager.log or "
+                                                                               + property.getName() + "'s logs directory.");
+                                                       }
+
+                                               });
+                                       }
+                                       break;
+                               } else {
+                                       EMLogger.getLogger().warning("Emulator has been terminated. Exit value: " + process.exitValue());
+                                       stdOut.printMessageList();
+                                       stdErr.printMessageList();
+                                       break;
+                               }
+                       } catch(IllegalThreadStateException e) {
+                               // empty
+                               //System.out.println(e.getMessage());
+                       }
+
+                       synchronized(this) {
+                               try {
+                                       this.wait(1000);
+                               } catch (InterruptedException e) {
+                                       EMLogger.getLogger().warning(e.getMessage());
+                                       break;
+                               }
+                       }
+               }
+
+               CheckingRunningEmulator.removeEmulator(property.getName());
+       }
+
+       public boolean isSuccess() {
+               return success;
+       }
+
+       public void setSuccess(boolean success) {
+               this.success = success;
+       }
+}
+
+class StdOut implements Runnable {
+       private BufferedReader reader;
+       private String emName;
+       private final ArrayList<String> list =  new ArrayList<String>();
+       public StdOut(BufferedReader reader, String name) {
+               this.reader = reader;
+               this.emName = name;
+       }
+
+       public StdOut(InputStreamReader in, String name) {
+               this.reader = new BufferedReader(in);
+               this.emName = name;
+       }
+
+       @ Override
+       public void run() {
+               String msg;
+               do {
+                       try {
+                               msg = reader.readLine();
+                               list.add(msg);
+                       } catch (IOException e) {
+                               EMLogger.getLogger().info(e.getMessage());
+                       }
+
+               } while (CheckingRunningEmulator.isContains(emName));
+               if (error) {
+                       for (String s : list) {
+                               if (s != null && !s.isEmpty()) {
+                                       EMLogger.getLogger().warning("Print Log From Emulator: " + s);
+                               }
+                       }
+               }
+       }
+
+       private boolean error = false;
+       public void printMessageList() {
+               error = true;
+       }
+}
index 6d831ac..c150d31 100644 (file)
@@ -352,7 +352,7 @@ public class VMsWorker {
             }
 
                        if (!result) {
-                               logger.log(Level.INFO, "The same name of VM not exist anywhere. You can continue your job.\n");
+                               logger.log(Level.INFO, "The same name of VM not exist anywhere. You can continue your job.");
                        }
                        return result;                                                   
                } catch (IOException err) {