| @@ -14,8 +14,9 @@ type openIDSession struct { | |||
| } | |||
| type workDone struct { | |||
| openID string //which user | |||
| consumed int //job done | |||
| openID string //which user | |||
| consumed int //job done | |||
| data openIDSessionData //modified, updated sessiondata | |||
| } | |||
| //SessionManager manage all sessions | |||
| @@ -89,10 +90,9 @@ func (m *SessionManager) createSession(openID string) openIDSession { | |||
| func (m *SessionManager) clearJobDone(d workDone) { | |||
| s, found := m.sessions[d.openID] | |||
| log.Println("SessionMgr/clearJobDone: start clearning jobs ... ") | |||
| log.Println(s) | |||
| log.Println(d) | |||
| if found { | |||
| s.count -= d.consumed | |||
| s.data = d.data //updated session data | |||
| m.sessions[d.openID] = s //update | |||
| if s.count == 0 { //no job to do | |||
| //remove from memory | |||
| @@ -126,23 +126,23 @@ func (m *SessionManager) destroySession(openID string) { | |||
| //worker thread, cannot change session info | |||
| func (m *SessionManager) startJob(openID string) { | |||
| log.Println("SessionMgr/startJob: enter...") | |||
| jobFinished := workDone{openID, 0} | |||
| s := m.sessions[openID] | |||
| jobFinished := workDone{openID, 0, openIDSessionData{}} | |||
| //process all jobs in the channel | |||
| hasJob := true | |||
| for hasJob { | |||
| select { | |||
| case v := <-m.sessions[openID].jobs: | |||
| m.checkOpenID(openID, v) | |||
| s := m.sessions[openID] | |||
| s.data.incomingMsg(v) //<=== main logic for processing each incoming message | |||
| log.Printf("after incoming message %s", s.data.Procedure) | |||
| m.sessions[openID] = s | |||
| log.Printf("procedure after incoming message %s", s.data.Procedure) | |||
| jobFinished.consumed++ | |||
| default: | |||
| hasJob = false | |||
| } | |||
| } | |||
| m.done <- jobFinished //notify parent that we have done | |||
| jobFinished.data = s.data //update session data | |||
| m.done <- jobFinished //notify parent that we have done | |||
| return | |||
| } | |||