paper3—Algorithm1-Engine-Trigger-on-FCD—temp
2016-05-04 20:54
423 查看
//source code: /run/media/root/E6B2798BB279614B/.../PAPER/paper-3/twin-engine-trigger-code/server-client-pthread-c
----------------------------------------------------------------------------------
Description: when FCD start, this algorithm will run as a deamon
normterm: normal termination;
normterm=0, SMD is not normal termination;
normterm=1, SMD is normal termination;
smdtime: time of receiving heartbeat from SMD last;
selftime: the most current time of FCD being active;
initconn: Initial connection from SMD to FCD;
initconn=1, initial value is 1;
downtime: suppose server restart time is 30s;
select selftime from fcd_state_table where id=1;
downtime=currenttime - selftime;
update fcd_state_table set selftime=currenttime where id=1;
PROCEDURE: MAIN
socket();
bind();
listen();
while true do
accept(); //waiting for connect from SMD
pthread_create(THREAD);
done
END PROCEDURE
PROCEDURE: THREAD
receive guestname from SMD;
select normterm from user_table where username=guestname;
select processid from process_table where username=guestname and state=active and exectime≈current;
while true do //communication between FCD & SMD
select smdtime from user_table where username=guestname;
period=-1; //used to determine whether SMD access FCD continuously
if receive heartbeat from SMD then
period=currenttime - smdtime;
end if
update user_table set smdtime=currenttime where username=guestname;
if 0< period< 8 or initconn then //normal visits
send heartbeat to SMD;
send information for current process to SMD;
initconn=0;
end if
if receive finish from SMD then //normal termination
update user_table set normterm=1 where username=guestname;
exit; //guest finished his tasks
end if
//server restart, process is not normal end
//after disconnect, SMD reconnect FCD
if downtime > 30 and !normterm or receive reconnect from SMD then
FCD receive current process information from SMD;
update correlative tables where processid=processid;
end if
sleep 1s;
done
END PROCEDURE
----------------------------------------------------------------------------------
Description: when FCD start, this algorithm will run as a deamon
normterm: normal termination;
normterm=0, SMD is not normal termination;
normterm=1, SMD is normal termination;
smdtime: time of receiving heartbeat from SMD last;
selftime: the most current time of FCD being active;
initconn: Initial connection from SMD to FCD;
initconn=1, initial value is 1;
downtime: suppose server restart time is 30s;
select selftime from fcd_state_table where id=1;
downtime=currenttime - selftime;
update fcd_state_table set selftime=currenttime where id=1;
PROCEDURE: MAIN
socket();
bind();
listen();
while true do
accept(); //waiting for connect from SMD
pthread_create(THREAD);
done
END PROCEDURE
PROCEDURE: THREAD
receive guestname from SMD;
select normterm from user_table where username=guestname;
select processid from process_table where username=guestname and state=active and exectime≈current;
while true do //communication between FCD & SMD
select smdtime from user_table where username=guestname;
period=-1; //used to determine whether SMD access FCD continuously
if receive heartbeat from SMD then
period=currenttime - smdtime;
end if
update user_table set smdtime=currenttime where username=guestname;
if 0< period< 8 or initconn then //normal visits
send heartbeat to SMD;
send information for current process to SMD;
initconn=0;
end if
if receive finish from SMD then //normal termination
update user_table set normterm=1 where username=guestname;
exit; //guest finished his tasks
end if
//server restart, process is not normal end
//after disconnect, SMD reconnect FCD
if downtime > 30 and !normterm or receive reconnect from SMD then
FCD receive current process information from SMD;
update correlative tables where processid=processid;
end if
sleep 1s;
done
END PROCEDURE
相关文章推荐
- POJ 2195 Going Home(最小权匹配、KM算法)
- Spark组件之GraphX学习15--we-Google.txt大图分析
- Django笔记:1.创建一个项目
- 使用visual studio code开发Go程序
- Go--基础知识学习二
- 在Visual Studio Code中配置GO开发环境
- Windows环境下vscode-go安装笔记
- Leangoo大讲堂:免费Scrum敏捷开发实战—武汉站
- GO--基础知识学习一
- Go 性能优化技巧 9/10
- Go 性能优化技巧 8/10
- Go 性能优化技巧 7/10
- Go 性能优化技巧 6/10
- Go 性能优化技巧 5/10
- Go 性能优化技巧 4/10
- Go 性能优化技巧 3/10
- Go 性能优化技巧 2/10
- django使用静态文件
- ROS(indigo)机器人操作系统学习资料和常用功能包汇总整理(ubuntu14.04LTS)
- ROS(indigo)机器人操作系统学习资料和常用功能包汇总整理(ubuntu14.04LTS)