[Title] Refactoring IDECommunicator
authorHyunjong,Pakr <phjwithyou.park@samsung.com>
Mon, 15 Oct 2012 04:28:13 +0000 (13:28 +0900)
committerHyunjong,Pakr <phjwithyou.park@samsung.com>
Mon, 15 Oct 2012 04:28:13 +0000 (13:28 +0900)
[Desc.] Thread and Manager are merged
[Issue] Redmine 7009

org.tizen.dynamicanalyzer.workbench/src/org/tizen/dynamicanalyzer/workbench/ApplicationWorkbenchWindowAdvisor.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/AnalyzerManager.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/IDECommunicator.java [moved from org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/IDECommunicatorManager.java with 66% similarity]
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/IDECommunicatorThread.java [deleted file]
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/handlers/ExitHandler.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/listeners/TableTooltipListener.java

index a21c343..ff461c7 100755 (executable)
@@ -43,6 +43,7 @@ import org.tizen.dynamicanalyzer.common.AnalyzerManager;
 import org.tizen.dynamicanalyzer.common.CommonConstants;
 import org.tizen.dynamicanalyzer.common.DASingletonFocusManager;
 import org.tizen.dynamicanalyzer.common.PathManager;
+import org.tizen.dynamicanalyzer.communicator.IDECommunicator;
 import org.tizen.dynamicanalyzer.communicator.ResourceCommunicator;
 import org.tizen.dynamicanalyzer.handlers.ExitHandler;
 import org.tizen.dynamicanalyzer.ui.toolbar.ToolbarArea;
@@ -112,7 +113,7 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
                ToolbarArea.getInstance().autoStart();
                
                DASingletonFocusManager.setSaveFocusDAPid();
-               AnalyzerManager.startIDECommunicatorThread();
+               IDECommunicator.startIDECommunicatorThread();
        }
 
        public boolean preWindowShellClose() {
index 2b1ad37..dba61c9 100755 (executable)
@@ -33,7 +33,6 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 
-import org.tizen.dynamicanalyzer.communicator.IDECommunicatorThread;
 import org.tizen.dynamicanalyzer.handlers.ClearHandler;
 import org.tizen.dynamicanalyzer.logparser.InsertLogQueue;
 import org.tizen.dynamicanalyzer.logparser.InsertLogThread;
@@ -92,7 +91,6 @@ public class AnalyzerManager {
        private static Thread startStopThread = null;
        private static Thread openTraceInputThread = null;
        private static Thread insertLogThread = null;
-       private static Thread IDEcommunicatorThread = null;
        
        private static String startBinaryAddr = null;
        private static String endBinaryAddr = null;
@@ -214,7 +212,6 @@ public class AnalyzerManager {
 
                stopLogQueueObservingThread();
                stopInsertLogThread();
-               stopIDEcommunicatorThread();
 
                leakDetector = null;
                failedChecker = null;
@@ -447,19 +444,6 @@ public class AnalyzerManager {
                        insertLogThread.interrupt();
                }
        }
-
-       public static void startIDECommunicatorThread() {
-               if (null == IDEcommunicatorThread || !IDEcommunicatorThread.isAlive()) {
-                       IDEcommunicatorThread = new Thread(null, new IDECommunicatorThread(),
-                                       AnalyzerConstants.IDE_COMMUNICATOR_THREAD);
-                       IDEcommunicatorThread.start();
-               }
-       }
-       public static void stopIDEcommunicatorThread() {
-               if (null != IDEcommunicatorThread && IDEcommunicatorThread.isAlive()) {
-                       IDEcommunicatorThread.interrupt();
-               }
-       }
        
        public static LeakDetector getLeakDectector() {
 
@@ -32,9 +32,13 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStreamWriter;
+import java.io.RandomAccessFile;
 import java.net.Socket;
 import java.net.UnknownHostException;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileLock;
 
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Display;
@@ -51,50 +55,142 @@ import org.tizen.dynamicanalyzer.ui.toolbar.ToolbarArea;
 import org.tizen.dynamicanalyzer.ui.widgets.DADialog;
 import org.tizen.dynamicanalyzer.utils.AnalyzerUtil;
 
-public class IDECommunicatorManager {
+public class IDECommunicator implements Runnable {
+       private final int MAXBUFSIZE = 1024;
 
        private final String IDE_DA_COMMUNICATION_TYPE_1 = "STATUS";
        private final String IDE_DA_COMMUNICATION_TYPE_2 = "RUN";
-       private final String IDE_DA_COMMUNICATION_TYPE_3 = "SOURCE";
+       private final static String IDE_DA_COMMUNICATION_TYPE_3 = "SOURCE";
        private final String IDE_DA_COMMUNICATION_TYPE_1_RECORD = "record";
        private final String IDE_DA_COMMUNICATION_TYPE_1_STOP = "stop";
-
-       private Socket socket = null;
+       private static Socket socket = null;
        private int port = 0;
-       private BufferedWriter writer = null;
+       private static BufferedWriter writer = null;
+       private static Thread _instance;
        
-       private static IDECommunicatorManager _instance;
+       public void run() {
+               while (true) {
+                       try {
+                               resetSocket();
+                               // Waiting Start IDE
+                               System.out.println(" Waiting Start IDE");
+                               while (true) {
+                                       File file = null;
+                                       FileLock fileLock = null;
+                                       FileChannel fchannel = null;
+                                       try {
+                                               file = new File(AnalyzerPaths.IDE_ACTIVE_PORT_PATH);
+                                               fchannel = new RandomAccessFile(file, "rw").getChannel();
+                                               fileLock = fchannel.tryLock();
+                                               if (fileLock == null) { // Active IDE
+                                                       break; 
+                                                       
+                                               } else {
+                                                       fileLock.release();
+                                                       Thread.sleep(1000);
+                                               }
+                                       } catch (Exception e) {
+                                               continue;
+                                       }
+                               }
+
+                               // Read IDE Port
+                               if (readActiveIdePort() != true) {
+                                       System.out.println("Failed Read Active IDE Port");
+                                       continue;
+                               }
+
+                               // Connect IDE Socket
+                               if (setIDESocket() != true) {
+                                       System.out.println("Failed Connect IDE Socket");
+                                       continue;
+                               }
+                               System.out.println("Connect IDE");
+                               int readSize = 0;
+                               byte receiveBuffer[] = new byte[MAXBUFSIZE];
+                               InputStream in = null;
+                               while (true) {
+                                       try {
+                                               in = getSocket().getInputStream();
+                                               System.out.print("IDE recvMessage Wait\n");
+                                               readSize = in.read(receiveBuffer);
+                                               if (readSize > 0) {
+                                                       parsingReceiveMessage(new String(receiveBuffer));
+                                               } else {
+                                                       break;
+                                               }
+                                       } catch (IOException e) {
+                                               e.printStackTrace();
+                                               break;
+                                       }
+                               }
+                               Thread.sleep(100);
+                               System.out.println("Disconnect IDE");
+                       } catch (InterruptedException e) {
+                               break;
+                       }
+               }
+       }
+       public static void startIDECommunicatorThread() {
+               if (null == _instance || !_instance.isAlive()) {
+                       _instance = new Thread(null, new IDECommunicator(),
+                                       AnalyzerConstants.IDE_COMMUNICATOR_THREAD);
+                       _instance.start();
+               }
+       }
        
-       public static IDECommunicatorManager getInstance() {
-               if (_instance == null) {
-                       _instance = new IDECommunicatorManager();
+       public static void stopIDEcommunicatorThread() {
+               if (null != _instance && _instance.isAlive()) {
+                       _instance.interrupt();
                }
-               return _instance;
        }
        
-       public Socket getSocket(){
+       private Socket getSocket(){
                return socket;
        }
        
-       public void resetSocket(){
+       private void resetSocket(){
                socket = null;
                writer = null;
        }
        
-       public boolean isConnected() {
+       public static boolean isConnected() {
                if (socket == null) {
                        return false;
                }
                return true;
        }
        
+       public static void sendCodeInfoToIDE(final String path,
+                       final String line) {
+               sendMessageToIDE(sendMessageString(
+                               IDE_DA_COMMUNICATION_TYPE_3, path, line));
+       }
+       
+       public static boolean sendMessageToIDE( final String message ){
+               
+               System.out.println("sendMessageOpenIDE " + message);
+               try {
+                       if ( socket != null ) {
+                               writer = new BufferedWriter(new OutputStreamWriter(
+                                               socket.getOutputStream()));
+                               writer.write(message);
+                               writer.flush();
+                       }
+               } catch (IOException e) {
+                       e.printStackTrace();
+                       return false;
+               }
+               return true;
+       }
+
        // Management Receive Message
-       public void parsingReceiveMessage(String msg) {
+       private void parsingReceiveMessage(String msg) {
                String[] strMsg = msg.split(AnalyzerConstants.DATA_PARSING_TOKEN);
                if (strMsg[0].equals(IDE_DA_COMMUNICATION_TYPE_1)) {
                        sendDAStatus();
                } else if (strMsg[0].equals(IDE_DA_COMMUNICATION_TYPE_2)) {
-                       recodApplication(strMsg);
+                       recordApplication(strMsg);
                } else {
                        System.out.println(" wrong receive message ");
                }
@@ -136,7 +232,7 @@ public class IDECommunicatorManager {
        }
 
        // trace Application
-       private static void recodApplication(String[] strMsg) {
+       private void recordApplication(String[] strMsg) {
 
                final String deviceName = new String(strMsg[1].trim());
                final String appName = new String(strMsg[2].trim());
@@ -151,13 +247,7 @@ public class IDECommunicatorManager {
                DASingletonFocusManager.setFocusDA();
        }
 
-       public void sendCodeInfoToIDE(final String path,
-                       final String line) {
-               sendMessageToIDE(sendMessageString(
-                               IDE_DA_COMMUNICATION_TYPE_3, path, line));
-       }
-
-       private static void popupMessage(final String message) {
+       private void popupMessage(final String message) {
                Shell shell = AnalyzerUtil.getWorkbenchWindow().getShell();
                DADialog warning = new DADialog(shell, SWT.NONE);
                warning.setMessage(message);
@@ -165,7 +255,7 @@ public class IDECommunicatorManager {
                warning.open();
        }
 
-       public boolean readActiveIdePort() {
+       private boolean readActiveIdePort() {
                boolean bSuccess = true;
                // read port from current_active_ide_port
                try {
@@ -190,7 +280,7 @@ public class IDECommunicatorManager {
                return bSuccess;
        }
        
-       public boolean setIDESocket() {
+       private boolean setIDESocket() {
                try {
                        socket = new Socket(CommonConstants.LOCAL_HOST, port);
                } catch (UnknownHostException e) {
@@ -204,21 +294,4 @@ public class IDECommunicatorManager {
                }
                return true;
        }
-       
-       public boolean sendMessageToIDE( final String message ){
-               
-               System.out.println("sendMessageOpenIDE " + message);
-               try {
-                       if ( socket != null ) {
-                               writer = new BufferedWriter(new OutputStreamWriter(
-                                               socket.getOutputStream()));
-                               writer.write(message);
-                               writer.flush();
-                       }
-               } catch (IOException e) {
-                       e.printStackTrace();
-                       return false;
-               }
-               return true;
-       }
 }
diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/IDECommunicatorThread.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/IDECommunicatorThread.java
deleted file mode 100644 (file)
index e592085..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- *  Dynamic Analyzer
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: 
- * Hyunjong Park <phjwithyou.park@samsung.com>
- * Juyoung Kim <j0.kim@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * 
- * Contributors:
- * - S-Core Co., Ltd
- * 
- */
-
-package org.tizen.dynamicanalyzer.communicator;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.RandomAccessFile;
-import java.nio.channels.FileChannel;
-import java.nio.channels.FileLock;
-
-import org.tizen.dynamicanalyzer.common.AnalyzerPaths;
-
-public class IDECommunicatorThread implements Runnable {
-       private final int MAXBUFSIZE = 1024;
-
-       public void run() {
-
-               while (true) {
-                       try {
-                               IDECommunicatorManager.getInstance().resetSocket();
-                               // Waiting Start IDE
-                               System.out.println(" Waiting Start IDE");
-                               while (true) {
-                                       File file = null;
-                                       FileLock fileLock = null;
-                                       FileChannel fchannel = null;
-                                       try {
-                                               file = new File(AnalyzerPaths.IDE_ACTIVE_PORT_PATH);
-                                               fchannel = new RandomAccessFile(file, "rw").getChannel();
-                                               fileLock = fchannel.tryLock();
-                                               if (fileLock == null) { // Active IDE
-                                                       break; 
-                                                       
-                                               } else {
-                                                       fileLock.release();
-                                                       Thread.sleep(1000);
-                                               }
-                                       } catch (Exception e) {
-                                               continue;
-                                       }
-                               }
-
-                               // Read IDE Port
-                               if (IDECommunicatorManager.getInstance().readActiveIdePort() != true) {
-                                       System.out.println("Failed Read Active IDE Port");
-                                       continue;
-                               }
-
-                               // Connect IDE Socket
-                               if (IDECommunicatorManager.getInstance().setIDESocket() != true) {
-                                       System.out.println("Failed Connect IDE Socket");
-                                       continue;
-                               }
-                               System.out.println("Connect IDE");
-                               int readSize = 0;
-                               byte receiveBuffer[] = new byte[MAXBUFSIZE];
-                               InputStream in = null;
-                               while (true) {
-                                       try {
-                                               in = IDECommunicatorManager.getInstance().getSocket()
-                                                               .getInputStream();
-                                               System.out.print("IDE recvMessage Wait\n");
-                                               readSize = in.read(receiveBuffer);
-                                               if (readSize > 0) {
-                                                       IDECommunicatorManager
-                                                                       .getInstance().parsingReceiveMessage(new String(
-                                                                                       receiveBuffer));
-                                               } else {
-                                                       break;
-                                               }
-                                       } catch (IOException e) {
-                                               e.printStackTrace();
-                                               break;
-                                       }
-                               }
-                               Thread.sleep(100);
-                               System.out.println("Disconnect IDE");
-                       } catch (InterruptedException e) {
-                               break;
-                       }
-               }
-       }
-}
index 963de0e..ac628e9 100644 (file)
@@ -31,6 +31,7 @@ import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
 import org.tizen.dynamicanalyzer.common.AnalyzerManager;
 import org.tizen.dynamicanalyzer.communicator.DACommunicator;
+import org.tizen.dynamicanalyzer.communicator.IDECommunicator;
 import org.tizen.dynamicanalyzer.logparser.LogSpliter;
 import org.tizen.dynamicanalyzer.ui.toolbar.ToolbarArea;
 import org.tizen.dynamicanalyzer.utils.UpdateViewTimer;
@@ -47,6 +48,7 @@ public class ExitHandler extends AbstractHandler {
                AnalyzerManager.stopLogQueueObservingThread();
                AnalyzerManager.stopInsertLogThread();
                LogSpliter.stopLogQueueObservingThread();
+               IDECommunicator.stopIDEcommunicatorThread();
 
                if (DACommunicator.isDaemonAlive()) {
                        DACommunicator.killDaemon();
index 83fcbf5..556ab01 100644 (file)
@@ -48,7 +48,7 @@ import org.tizen.dynamicanalyzer.common.AnalyzerManager;
 import org.tizen.dynamicanalyzer.common.CommonConstants;\r
 import org.tizen.dynamicanalyzer.common.SymbolManager;\r
 import org.tizen.dynamicanalyzer.common.SymbolManager.SourceLine;\r
-import org.tizen.dynamicanalyzer.communicator.IDECommunicatorManager;\r
+import org.tizen.dynamicanalyzer.communicator.IDECommunicator;\r
 import org.tizen.dynamicanalyzer.logparser.LogCenterConstants;\r
 import org.tizen.dynamicanalyzer.nl.AnalyzerLabels;\r
 import org.tizen.dynamicanalyzer.resources.ColorResources;\r
@@ -406,12 +406,12 @@ public class TableTooltipListener implements Listener {
                }\r
                sl = getSourceLine(item);\r
 \r
-               if ( ( null == sl ) || (!sl.isValid()) || (IDECommunicatorManager.getInstance().isConnected() == false) ) {\r
+               if ( ( null == sl ) || (!sl.isValid()) || (IDECommunicator.isConnected() == false) ) {\r
                        createErrorPopup(AnalyzerLabels.SOURCE_NOT_EXIST);\r
                        return;\r
                }\r
                \r
-               IDECommunicatorManager.getInstance().sendCodeInfoToIDE( sl.getFilePath() ,  Integer.toString( sl.getLineNumber() ) );\r
+               IDECommunicator.sendCodeInfoToIDE( sl.getFilePath() ,  Integer.toString( sl.getLineNumber() ) );\r
        }\r
 \r
        public void setSourceButtonToggle(boolean toggle) {\r