From: phjwithyou.park Date: Fri, 17 Aug 2012 10:12:55 +0000 (+0900) Subject: [Title] Source Refactoring X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=13f726a6ab7b37f35a134b881751523a2a978052;p=sdk%2Ftools%2Fdynamic-analyzer.git [Title] Source Refactoring [Type] [Module] [Priority] [CQ#] [Redmine#] [Problem] [Cause] [Solution] [TestCase] --- diff --git a/org.tizen.dynamicanalyzer.workbench/src/org/tizen/dynamicanalyzer/workbench/ApplicationWorkbenchWindowAdvisor.java b/org.tizen.dynamicanalyzer.workbench/src/org/tizen/dynamicanalyzer/workbench/ApplicationWorkbenchWindowAdvisor.java index dab0100..b7c33fa 100755 --- a/org.tizen.dynamicanalyzer.workbench/src/org/tizen/dynamicanalyzer/workbench/ApplicationWorkbenchWindowAdvisor.java +++ b/org.tizen.dynamicanalyzer.workbench/src/org/tizen/dynamicanalyzer/workbench/ApplicationWorkbenchWindowAdvisor.java @@ -40,8 +40,6 @@ import org.tizen.dynamicanalyzer.constants.AnalyzerConstants; import org.tizen.dynamicanalyzer.handlers.ExitHandler; import org.tizen.dynamicanalyzer.ui.views.CoolbarArea; import org.tizen.dynamicanalyzer.utils.AnalyzerUtil; -import org.tizen.dynamicanalyzer.threads.DASingletonCheckThread; - public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { @@ -49,7 +47,6 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { private static final int DEFAULT_HEIGHT = 768; private static final int MIN_WIDTH = 800; private static final int MIN_HEIGHT = 600; - private static final int DARunningTrue = 1; private int width = DEFAULT_WIDTH; private int height = DEFAULT_HEIGHT; @@ -70,28 +67,8 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { @Override public void createWindowContents(Shell shell) { CoolbarArea.createInstance(getWindowConfigurer(), shell); - - // Check DA Singleton Dlg. - DASingletonCheckThread checkFirstPort = new DASingletonCheckThread(); - checkFirstPort.start(); - while (checkFirstPort.bDARunning < 0) { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - DASingletonCheckThread checkSecondPort = new DASingletonCheckThread(); - checkSecondPort.start(); - while (checkSecondPort.bDARunning < 0) { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - if (checkFirstPort.bDARunning == DARunningTrue && checkSecondPort.bDARunning == DARunningTrue) { + if ( DASingletonFocusManager.CheckDASingleton() ) { System.out.print("Already DA Running \n"); DASingletonFocusManager.SetFocusDA(); System.exit(-1); @@ -100,7 +77,6 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { DASingletonFocusManager.SetSaveFocusDAPid(); IDEConnectorManager.InitIDESocketThreadListener(); } - } @Override diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/DASingletonFocusManager.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/DASingletonFocusManager.java index 97178c9..eff5754 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/DASingletonFocusManager.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/DASingletonFocusManager.java @@ -19,12 +19,18 @@ package org.tizen.dynamicanalyzer; +import java.io.File; import java.io.IOException; +import java.io.RandomAccessFile; import java.lang.management.ManagementFactory; import java.lang.management.RuntimeMXBean; +import java.nio.channels.FileChannel; +import java.nio.channels.FileLock; + import org.tizen.dynamicanalyzer.constants.AnalyzerConstants; import org.tizen.dynamicanalyzer.utils.AnalyzerUtil; + public class DASingletonFocusManager { private static String pid = null; private static String Processid = null; @@ -105,4 +111,24 @@ public class DASingletonFocusManager { ConfigureManager.getInstance().setValue( ConfigureManager.SINGLETON_FOCUS_DA_PID, pid); } + + public static boolean CheckDASingleton(){ + + File file = null; + FileLock fileLock = null; + FileChannel fchannel = null; + try { + file = new File( AnalyzerConstants.DA_SINGLETON_FILE_PATH ); + fchannel = new RandomAccessFile(file, "rw").getChannel(); + fileLock = fchannel.tryLock(); + if (fileLock == null) { + return true; + } + } catch (Exception e) { + return true; + } + + return false; + + } } diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/constants/AnalyzerConstants.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/constants/AnalyzerConstants.java index cff7b62..04bdc54 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/constants/AnalyzerConstants.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/constants/AnalyzerConstants.java @@ -93,7 +93,7 @@ public class AnalyzerConstants { public static final String SDB_PATH = PathManager.getSdbPath(); public static final String TARGET_PATH = DYNAMIC_ANALYZER_INSTALL_PATH + File.separator + "target" + File.separator; //$NON-NLS-1$ - + public static final String DA_SINGLETON_FILE_PATH = DYNAMIC_ANALYZER_INSTALL_PATH + File.separator + "fileLock"; //$NON-NLS-1$ public static final String InstallPathForLinux = AnalyzerConstants.TIZEN_ROOT_PATH + "/tools/dynamic-analyzer/tool/windowactivator.sh"; public static final String InstallPathForWindow = AnalyzerConstants.TIZEN_ROOT_PATH+"/tools/dynamic-analyzer/tool/windowactivator.vbs";