|
|
@ -93,7 +93,7 @@ public class MpMasterService extends Service {
|
|
|
|
|
|
|
|
|
|
|
|
private static int mStateService = STATE_SERVICE.NOT_CONNECTED;
|
|
|
|
private static int mStateService = STATE_SERVICE.NOT_CONNECTED;
|
|
|
|
|
|
|
|
|
|
|
|
private int mMpHeartbeatDuration = 10;
|
|
|
|
private int mMpHeartbeatDuration = 10; // Unit: minute
|
|
|
|
|
|
|
|
|
|
|
|
private boolean mMntnMode = false;
|
|
|
|
private boolean mMntnMode = false;
|
|
|
|
private boolean mQuickHbMode = false;
|
|
|
|
private boolean mQuickHbMode = false;
|
|
|
@ -486,30 +486,37 @@ public class MpMasterService extends Service {
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
String action = intent.getAction();
|
|
|
|
String action = intent.getAction();
|
|
|
|
if (TextUtils.equals(ACTION_HEARTBEAT, action)) {
|
|
|
|
if (TextUtils.equals(ACTION_HEARTBEAT, action)) {
|
|
|
|
mService.logger.info("Heartbeat Timer Fired ACTION=" + action);
|
|
|
|
boolean keepAlive = intent.getBooleanExtra("keepAlive", false);
|
|
|
|
|
|
|
|
if (keepAlive) {
|
|
|
|
|
|
|
|
mService.logger.info("KeepAlive Heartbeat Timer Fired ACTION=" + action);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
mService.logger.info("Heartbeat Timer Fired ACTION=" + action);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mService.mPreviousHB = null;
|
|
|
|
mService.mPreviousHB = null;
|
|
|
|
mService.registerHeartbeatTimer();
|
|
|
|
mService.registerHeartbeatTimer();
|
|
|
|
|
|
|
|
|
|
|
|
mService.startMaster(false);
|
|
|
|
if (!keepAlive) {
|
|
|
|
|
|
|
|
mService.startMaster(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
mService.startMpApp();
|
|
|
|
mService.startMpApp();
|
|
|
|
|
|
|
|
|
|
|
|
} else if (TextUtils.equals(MicroPhotoContext.ACTION_HEARTBEAT_MP, action)) {
|
|
|
|
} else if (TextUtils.equals(MicroPhotoContext.ACTION_HEARTBEAT_MP, action)) {
|
|
|
|
|
|
|
|
|
|
|
|
mService.mPreviousMpHbTime = System.currentTimeMillis();
|
|
|
|
mService.mPreviousMpHbTime = System.currentTimeMillis();
|
|
|
|
mService.mMpHeartbeatDuration = intent.getIntExtra("HeartbeatDuration", 10);
|
|
|
|
if (intent.hasExtra("HeartbeatDuration")) {
|
|
|
|
|
|
|
|
mService.mMpHeartbeatDuration = intent.getIntExtra("HeartbeatDuration", 10);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!mService.mSeparateNetwork && (!mService.mMntnMode)) {
|
|
|
|
mService.logger.info("Heartbeat Timer Fired By MpAPP ACTION=" + action);
|
|
|
|
mService.logger.info("Heartbeat Timer Fired By MpAPP ACTION=" + action);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long ts = System.currentTimeMillis();
|
|
|
|
mService.registerHeartbeatTimer();
|
|
|
|
if (mService.mPreviousHeartbeatTime - ts < mService.mHeartbeatDuration * 1000) {
|
|
|
|
|
|
|
|
mService.registerHeartbeatTimer(mService.mPreviousHeartbeatTime + mService.mHeartbeatDuration * 1000);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!mService.mSeparateNetwork && (!mService.mMntnMode)) {
|
|
|
|
mService.startMaster(true);
|
|
|
|
mService.startMaster(true);
|
|
|
|
mService.startMpApp();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mService.startMpApp();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (TextUtils.equals(ACTION_UPDATE_CONFIGS, action)) {
|
|
|
|
} else if (TextUtils.equals(ACTION_UPDATE_CONFIGS, action)) {
|
|
|
|
int restart = intent.getIntExtra("restart", 0);
|
|
|
|
int restart = intent.getIntExtra("restart", 0);
|
|
|
@ -576,11 +583,13 @@ public class MpMasterService extends Service {
|
|
|
|
private void registerHeartbeatTimer() {
|
|
|
|
private void registerHeartbeatTimer() {
|
|
|
|
|
|
|
|
|
|
|
|
long timeout = mHeartbeatDuration;
|
|
|
|
long timeout = mHeartbeatDuration;
|
|
|
|
|
|
|
|
boolean keepAlive = false;
|
|
|
|
|
|
|
|
long currentTimeMs = System.currentTimeMillis();
|
|
|
|
if (mMntnMode) {
|
|
|
|
if (mMntnMode) {
|
|
|
|
if (mQuickHbMode) {
|
|
|
|
if (mQuickHbMode) {
|
|
|
|
timeout = mQuickHeartbeatDuration;
|
|
|
|
timeout = mQuickHeartbeatDuration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
registerHeartbeatTimer(System.currentTimeMillis() + timeout * 1000);
|
|
|
|
registerHeartbeatTimer(currentTimeMs + timeout * 1000, keepAlive);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
long closestTime = -1;
|
|
|
|
long closestTime = -1;
|
|
|
|
if (mUsingAbsHbTime) {
|
|
|
|
if (mUsingAbsHbTime) {
|
|
|
@ -616,18 +625,30 @@ public class MpMasterService extends Service {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
registerHeartbeatTimer(zeroPoint + closestTime * 1000);
|
|
|
|
if (zeroPoint + closestTime > currentTimeMs + mMpHeartbeatDuration * 60000) {
|
|
|
|
|
|
|
|
keepAlive = true;
|
|
|
|
|
|
|
|
registerHeartbeatTimer(currentTimeMs + timeout * 1000, keepAlive);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
registerHeartbeatTimer(zeroPoint + closestTime * 1000, keepAlive);
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
registerHeartbeatTimer(System.currentTimeMillis() + timeout * 1000);
|
|
|
|
if (mPreviousHeartbeatTime - currentTimeMs < mHeartbeatDuration * 1000) {
|
|
|
|
|
|
|
|
registerHeartbeatTimer(mPreviousHeartbeatTime + mHeartbeatDuration * 1000, keepAlive);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
registerHeartbeatTimer(currentTimeMs + timeout * 1000, keepAlive);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void registerHeartbeatTimer(long triggerTime) {
|
|
|
|
private void registerHeartbeatTimer(long triggerTime, boolean keepAlive) {
|
|
|
|
|
|
|
|
|
|
|
|
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
|
|
|
|
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
|
|
|
|
|
|
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
|
|
|
|
|
|
if (mPreviousHB != null) {
|
|
|
|
if (mPreviousHB != null) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
logger.info(String.format("Cancel Previos HB: " + format.format(new Date(mPreviousHeartbeatTime))));
|
|
|
|
alarmManager.cancel(mPreviousHB);
|
|
|
|
alarmManager.cancel(mPreviousHB);
|
|
|
|
mPreviousHB = null;
|
|
|
|
mPreviousHB = null;
|
|
|
|
} catch (Exception ex) {
|
|
|
|
} catch (Exception ex) {
|
|
|
@ -636,11 +657,18 @@ public class MpMasterService extends Service {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Intent alarmIntent = new Intent();
|
|
|
|
Intent alarmIntent = new Intent();
|
|
|
|
alarmIntent.setAction(ACTION_HEARTBEAT);
|
|
|
|
alarmIntent.setAction(ACTION_HEARTBEAT);
|
|
|
|
|
|
|
|
if (keepAlive) {
|
|
|
|
|
|
|
|
alarmIntent.putExtra("keepAlive", keepAlive);
|
|
|
|
|
|
|
|
}
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, 0);
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, 0);
|
|
|
|
|
|
|
|
|
|
|
|
Date dt = new Date(triggerTime);
|
|
|
|
Date dt = new Date(triggerTime);
|
|
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
|
|
logger.info(String.format("Register HB:" + format.format(dt)) + " MntnMode" + (mMntnMode ? "1" : "0") + " QuickHb=" + (mQuickHbMode ? "1" : "0"));
|
|
|
|
if (keepAlive) {
|
|
|
|
|
|
|
|
logger.info(String.format("Register KeepAlive HB: " + format.format(dt)) + " MntnMode=" + (mMntnMode ? "1" : "0") + " QuickHb=" + (mQuickHbMode ? "1" : "0"));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
logger.info(String.format("Register HB: " + format.format(dt)) + " MntnMode=" + (mMntnMode ? "1" : "0") + " QuickHb=" + (mQuickHbMode ? "1" : "0"));
|
|
|
|
|
|
|
|
}
|
|
|
|
mPreviousHB = pendingIntent;
|
|
|
|
mPreviousHB = pendingIntent;
|
|
|
|
mPreviousHeartbeatTime = triggerTime;
|
|
|
|
mPreviousHeartbeatTime = triggerTime;
|
|
|
|
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, triggerTime, pendingIntent);
|
|
|
|
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, triggerTime, pendingIntent);
|
|
|
|