[Title] enhance send queue logic / change log level from WARN to INFO / increate...
authorSon Hyunjun <hj79.son@samsung.com>
Fri, 27 Apr 2012 02:16:53 +0000 (11:16 +0900)
committerSon Hyunjun <hj79.son@samsung.com>
Fri, 27 Apr 2012 02:16:53 +0000 (11:16 +0900)
[Type] Enhancement
[Module] Skin
[Priority] Minor
[CQ#]
[Redmine#]
[Problem]
[Cause]
[Solution]

Change-Id: I5ce9de0594d66c1334c190773ea77da3682908b0

tizen/src/skin/client/src/org/tizen/emulator/skin/comm/sock/SocketCommunicator.java
tizen/src/skin/maruskin_operation.c
tizen/src/skin/maruskin_server.c

index 3d5658b10c9e0488fa1c5976c0c2c7c2dd11208d..51c49499cc57d8f6a69dd80cd59c5624ebaf9b12 100644 (file)
@@ -36,9 +36,11 @@ import java.io.DataOutputStream;
 import java.io.IOException;
 import java.net.Socket;
 import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Timer;
 import java.util.TimerTask;
-import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
@@ -84,15 +86,15 @@ public class SocketCommunicator implements ICommunicator {
        }
 
        public static final int HEART_BEAT_INTERVAL = 1; //second
-       public static final int HEART_BEAT_EXPIRE = 5;
-
-       public final static int SEND_QUEUE_WAIT_INTERVAL = 10; // milli-seconds
+       public static final int HEART_BEAT_EXPIRE = 10;
        
        public final static int SCREENSHOT_WAIT_INTERVAL = 3; // milli-seconds
        public final static int SCREENSHOT_WAIT_LIMIT = 3000; // milli-seconds
        public final static int DETAIL_INFO_WAIT_INTERVAL = 1; // milli-seconds
        public final static int DETAIL_INFO_WAIT_LIMIT = 3000; // milli-seconds
        
+       public final static int MAX_SEND_QUEUE_SIZE = 100000;
+       
        private static int reqId;
        
        private Logger logger = SkinLogger.getSkinLogger( SocketCommunicator.class ).getLogger();
@@ -115,7 +117,7 @@ public class SocketCommunicator implements ICommunicator {
        private DataTranfer detailInfoTransfer;
        
        private Thread sendThread;
-       private ConcurrentLinkedQueue<SkinSendData> sendQueue;
+       private LinkedList<SkinSendData> sendQueue;
 
        public SocketCommunicator( EmulatorConfig config, int uId, int windowHandleId, EmulatorSkin skin ) {
 
@@ -152,19 +154,22 @@ public class SocketCommunicator implements ICommunicator {
        @Override
        public void run() {
 
-               try {
+               sendQueue = new LinkedList<SkinSendData>();
 
-                       sendQueue = new ConcurrentLinkedQueue<SkinSendData>();
+               sendThread = new Thread() {
 
-                       sendThread = new Thread() {
-                               @Override
-                               public void run() {
+                       List<SkinSendData> list = new ArrayList<SkinSendData>();
+
+                       @Override
+                       public void run() {
 
-                                       while ( true ) {
+                               while ( true ) {
 
-                                               synchronized ( sendThread ) {
+                                       synchronized ( sendQueue ) {
+
+                                               if ( sendQueue.isEmpty() ) {
                                                        try {
-                                                               sendThread.wait( SEND_QUEUE_WAIT_INTERVAL );
+                                                               sendQueue.wait();
                                                        } catch ( InterruptedException e ) {
                                                                logger.log( Level.SEVERE, e.getMessage(), e );
                                                        }
@@ -174,22 +179,32 @@ public class SocketCommunicator implements ICommunicator {
                                                while ( true ) {
                                                        sendData = sendQueue.poll();
                                                        if ( null != sendData ) {
-                                                               sendToQEMUInternal( sendData );
+                                                               list.add( sendData );
                                                        } else {
                                                                break;
                                                        }
                                                }
 
-                                               if ( isTerminated ) {
-                                                       break;
-                                               }
+                                       }
+
+                                       for ( SkinSendData data : list ) {
+                                               sendToQEMUInternal( data );
+                                       }
 
+                                       list.clear();
+
+                                       if ( isTerminated ) {
+                                               break;
                                        }
 
                                }
-                       };
 
-                       sendThread.start();
+                       }
+               };
+
+               sendThread.start();
+
+               try {
 
                        dis = new DataInputStream( socket.getInputStream() );
                        dos = new DataOutputStream( socket.getOutputStream() );
@@ -423,11 +438,14 @@ public class SocketCommunicator implements ICommunicator {
        
        @Override
        public void sendToQEMU( SendCommand command, ISendData data ) {
-               
-               sendQueue.add( new SkinSendData( command, data ) );
-               
-               synchronized ( sendThread ) {
-                       sendThread.notifyAll();
+
+               synchronized ( sendQueue ) {
+                       if ( MAX_SEND_QUEUE_SIZE < sendQueue.size() ) {
+                               logger.warning( "Send queue size exceeded max value, do not push data into send queue." );
+                       } else {
+                               sendQueue.add( new SkinSendData( command, data ) );
+                               sendQueue.notifyAll();
+                       }
                }
 
        }
@@ -559,9 +577,9 @@ public class SocketCommunicator implements ICommunicator {
                        heartbeatExecutor.shutdownNow();
                }
                
-               if( null != sendThread ) {
-                       synchronized ( sendThread ) {
-                               sendThread.notifyAll();
+               if( null != sendQueue ) {
+                       synchronized ( sendQueue ) {
+                               sendQueue.notifyAll();
                        }
                }
                
index 80e43f392ae1925e129b75edb0d65b273a839d34..b98fb23dca900cb9e09c3cff23a9fe1373e036a6 100644 (file)
@@ -405,7 +405,7 @@ static void* run_timed_shutdown_thread( void* args ) {
         fprintf( stdout, "Wait for shutdown qemu...%d\n", ( i + 1 ) );
     }
 
-    WARN( "Shutdown qemu !!!\n" );
+    INFO( "Shutdown qemu !!!\n" );
     qemu_system_shutdown_request();
 
     return NULL;
index 975b982aec76b155ea7d80d0585f42f57b696163..d5b14e4b9600e375c3f81ddff7e1d083fdd846a9 100644 (file)
@@ -63,8 +63,8 @@ MULTI_DEBUG_CHANNEL( qemu, skin_server );
 #define SEND_BUF_SIZE 512
 
 #define HEART_BEAT_INTERVAL 1
-#define HEART_BEAT_FAIL_COUNT 5
-#define HEART_BEAT_EXPIRE_COUNT 5
+#define HEART_BEAT_FAIL_COUNT 10
+#define HEART_BEAT_EXPIRE_COUNT 10
 
 #if 0 // do not restarting skin process ( prevent from abnormal behavior killing a skin process in Windows )
 #define RESTART_CLIENT_MAX_COUNT 1
@@ -216,7 +216,7 @@ void shutdown_skin_server( void ) {
     }
 
     if ( close_server_socket ) {
-        WARN( "skin client did not send normal shutdown response.\n" );
+        INFO( "skin client did not send normal shutdown response.\n" );
         if ( server_sock ) {
 #ifdef _WIN32
             closesocket( server_sock );
@@ -272,7 +272,7 @@ static void parse_skinconfig_prop( void ) {
     rewind( fp );
 
     if ( 0 >= buf_size ) {
-        WARN( "%s contents is empty.\n", SKIN_CONFIG_PROP );
+        INFO( "%s contents is empty.\n", SKIN_CONFIG_PROP );
         fclose( fp );
         return;
     }
@@ -459,7 +459,7 @@ static void* run_skin_server( void* args ) {
             if ( 0 > read_cnt ) {
 
                 if( is_force_close_client ) {
-                    WARN( "force close client socket.\n" );
+                    INFO( "force close client socket.\n" );
                     is_force_close_client = 0;
                 }else {
                     ERR( "skin_server read error:%d\n", read_cnt );
@@ -1020,9 +1020,9 @@ static void* do_heart_beat( void* args ) {
                     need_restart_skin_client = 0;
                     restart_client_count++;
 
-                    WARN( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" );
-                    WARN( "!!! restart skin client process !!!\n" );
-                    WARN( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" );
+                    INFO( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" );
+                    INFO( "!!! restart skin client process !!!\n" );
+                    INFO( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" );
 
                     is_force_close_client = 1;
                     if ( client_sock ) {