comparison rep/ServerMainLoop.java @ 491:5945266c970d

before unMergedCmds fix , deadlockTimer API
author one
date Sat, 23 Oct 2010 12:34:46 +0900
parents cc262a519b8a
children
comparison
equal deleted inserted replaced
490:168909388479 491:5945266c970d
41 protected int receive_port; 41 protected int receive_port;
42 protected int parent_port; 42 protected int parent_port;
43 protected static final int DEFAULT_PORT = 8766; 43 protected static final int DEFAULT_PORT = 8766;
44 private SessionManagerEvent execAfterConnect = null; 44 private SessionManagerEvent execAfterConnect = null;
45 private boolean running = true; 45 private boolean running = true;
46 // dead lock detection in msec, -1 means no deadlock detection
47 public int deadlockTime = -1;
46 48
47 49
48 public void setReceivePort(int port) { 50 public void setReceivePort(int port) {
49 receive_port = port; 51 receive_port = port;
50 } 52 }
57 serverInit(); 59 serverInit();
58 mainLoop(); 60 mainLoop();
59 } 61 }
60 62
61 public void mainLoop() throws IOException { 63 public void mainLoop() throws IOException {
62 int deadlock = 0; 64 int deadlock = deadlockTime;
63 while(running){ 65 while(running){
64 manager.checkWaitingCommandInMerge(); 66 manager.checkWaitingCommandInMerge();
65 if (checkInputEvent() || 67 if (checkInputEvent() ||
66 checkWaitingWrite()) { 68 checkWaitingWrite()) {
67 continue; 69 continue;
68 // try to do fair execution for waiting task 70 // try to do fair execution for waiting task
69 //if(selector.selectNow() > 0) select(); 71 //if(selector.selectNow() > 0) select();
70 //continue; 72 //continue;
71 } 73 }
72 // now we can wait for input packet or event 74 // now we can wait for input packet or event
73 if (deadlock++>1000) deadlockDetected(); 75 if (deadlock-- ==0) deadlockDetected();
74 selector.select(1); 76 selector.select(1);
75 if (select()) deadlock=0; 77 if (select()) deadlock=deadlockTime;
76 } 78 }
77 } 79 }
78 80
79 public void deadlockDetected() throws IOException { 81 public void deadlockDetected() throws IOException {
80 } 82 }
275 } 277 }
276 278
277 public void setManager(SessionManager sessionManager) { 279 public void setManager(SessionManager sessionManager) {
278 manager = sessionManager; 280 manager = sessionManager;
279 } 281 }
282
283 public void setDeadlockTime(int t) {
284 deadlockTime = t;
285 }
280 286
281 } 287 }