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;
}
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();
private DataTranfer detailInfoTransfer;
private Thread sendThread;
- private ConcurrentLinkedQueue<SkinSendData> sendQueue;
+ private LinkedList<SkinSendData> sendQueue;
public SocketCommunicator( EmulatorConfig config, int uId, int windowHandleId, EmulatorSkin skin ) {
@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 );
}
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() );
@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();
+ }
}
}
heartbeatExecutor.shutdownNow();
}
- if( null != sendThread ) {
- synchronized ( sendThread ) {
- sendThread.notifyAll();
+ if( null != sendQueue ) {
+ synchronized ( sendQueue ) {
+ sendQueue.notifyAll();
}
}
#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
}
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 );
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;
}
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 );
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 ) {