import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
}
public static final int HEART_BEAT_INTERVAL = 1; //second
- public static final int HEART_BEAT_EXPIRE = 10;
-
+ public static final int HEART_BEAT_EXPIRE = 15;
+
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 Logger logger =
+ SkinLogger.getSkinLogger(SocketCommunicator.class).getLogger();
private EmulatorConfig config;
private int uId;
private boolean isTerminated;
private boolean isSensorDaemonStarted;
private boolean isRamdump;
- private ScheduledExecutorService heartbeatExecutor;
+ private TimerTask heartbeatExecutor;
+ private Timer heartbeatTimer;
private DataTranfer screenShotDataTransfer;
private DataTranfer detailInfoTransfer;
this.progressDataTransfer.maxWaitTime = SCREENSHOT_WAIT_LIMIT;
this.heartbeatCount = new AtomicInteger(0);
- this.heartbeatExecutor = Executors.newSingleThreadScheduledExecutor();
+ //this.heartbeatExecutor = Executors.newSingleThreadScheduledExecutor();
+ this.heartbeatTimer = new Timer();
try {
boolean ignoreHeartbeat = config.getArgBoolean( ArgsConstants.TEST_HEART_BEAT_IGNORE );
- if ( ignoreHeartbeat ) {
- logger.info( "Ignore Skin heartbeat." );
+ if (ignoreHeartbeat) {
+ logger.info("Ignore Skin heartbeat.");
} else {
-
- heartbeatExecutor.scheduleAtFixedRate( new Runnable() {
-
+ heartbeatExecutor = new TimerTask() {
@Override
public void run() {
-
increaseHeartbeatCount();
- if ( isHeartbeatExpired() ) {
+ if (isHeartbeatExpired()) {
+ logger.info("heartbeat was expired");
terminate();
}
-
}
+ };
- }, 0, HEART_BEAT_INTERVAL, TimeUnit.SECONDS );
-
+ heartbeatTimer.schedule(heartbeatExecutor, 1, HEART_BEAT_INTERVAL * 1000);
}
while ( true ) {
public byte[] getReceivedData( DataTranfer dataTranfer ) {
- if( null == dataTranfer ) {
+ if (null == dataTranfer) {
return null;
}
-
- synchronized ( dataTranfer ) {
-
+
+ synchronized (dataTranfer) {
+
int count = 0;
byte[] receivedData = null;
long sleep = dataTranfer.sleep;
private void increaseHeartbeatCount() {
int count = heartbeatCount.incrementAndGet();
- if ( logger.isLoggable( Level.FINE ) ) {
- logger.fine( "HB count : " + count );
+
+ if (logger.isLoggable(Level.FINE)) {
+ logger.info("HB count : " + count);
}
}
}
private void resetHeartbeatCount() {
- heartbeatCount.set( 0 );
+ heartbeatCount.set(0);
+
+ if (logger.isLoggable(Level.FINE)) {
+ logger.info("HB count reset");
+ }
}
@Override
public void terminate() {
-
isTerminated = true;
-
- if ( null != heartbeatExecutor ) {
- heartbeatExecutor.shutdownNow();
- }
-
- if( null != sendQueue ) {
- synchronized ( sendQueue ) {
+ logger.info("terminated");
+
+ if (null != sendQueue) {
+ synchronized (sendQueue) {
sendQueue.notifyAll();
}
}
-
- IOUtil.closeSocket( socket );
-
- synchronized ( this ) {
+
+ if (null != heartbeatTimer) {
+ heartbeatTimer.cancel();
+ }
+
+ IOUtil.closeSocket(socket);
+
+ synchronized (this) {
skin.shutdown();
}
-
}
public void resetSkin( EmulatorSkin skin ) {
private SendCommand command;
private ISendData data;
- public SkinSendData( SendCommand command, ISendData data ) {
+ public SkinSendData(SendCommand command, ISendData data) {
this.command = command;
this.data = data;
}
static int stop_heartbeat = 0;
static int recv_heartbeat_count = 0;
static pthread_t thread_id_heartbeat;
-static pthread_mutex_t mutex_heartbeat = PTHREAD_MUTEX_INITIALIZER;
-static pthread_cond_t cond_heartbeat = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t mutex_recv_heartbeat_count = PTHREAD_MUTEX_INITIALIZER;
static int skin_argc = 0;
int need_restart_skin_client = 0;
int shutdown = 0;
- int booting_handicap_cnt = 0;
-
- struct timeval current;
- struct timespec ts_heartbeat;
+ unsigned int booting_handicap_cnt = 0;
+ unsigned int hb_interval = HEART_BEAT_INTERVAL * 1000;
while ( 1 ) {
- gettimeofday( ¤t, NULL );
-
if (booting_handicap_cnt < 5) {
booting_handicap_cnt++;
- ts_heartbeat.tv_sec = current.tv_sec +
- (HEART_BEAT_INTERVAL * 10);
+
+#ifdef CONFIG_WIN32
+ Sleep(hb_interval * 10); /* 10sec */
+#else
+ usleep(hb_interval * 1000 * 10);
+#endif
} else {
- ts_heartbeat.tv_sec = current.tv_sec + HEART_BEAT_INTERVAL;
+#ifdef CONFIG_WIN32
+ Sleep(hb_interval); /* 1sec */
+#else
+ usleep(hb_interval * 1000);
+#endif
}
- ts_heartbeat.tv_nsec = current.tv_usec * 1000;
-
- pthread_mutex_lock( &mutex_heartbeat );
- pthread_cond_timedwait( &cond_heartbeat, &mutex_heartbeat, &ts_heartbeat );
- pthread_mutex_unlock( &mutex_heartbeat );
-
- if ( stop_heartbeat ) {
- INFO( "[HB] stop heart beat.\n" );
+ if (stop_heartbeat) {
+ INFO("[HB] stop heart beat.\n");
break;
}
send_fail_count = 0;
}
} else {
- // fail to get socket in accepting or client is not yet accepted.
+ /* fail to get socket in accepting or client is not yet accepted */
send_fail_count++;
TRACE( "[HB] client socket is NULL yet.\n" );
}
static void stop_heart_beat(void)
{
- pthread_mutex_lock(&mutex_heartbeat);
-
stop_heartbeat = 1;
- pthread_cond_signal(&cond_heartbeat);
-
- pthread_mutex_unlock(&mutex_heartbeat);
}