def lineReceived(self, line):
     stdout.write("Server%d Received Data: %s\n" %( Configuration.getMyID(), line))
     delMsgs = self.algorithm.receiveMsg(line, self.node)
     #return the jsonmsg to various nodes 
     #send jsonmsg to nodes to notify them 
     #it's for conflicts
     #self.send2Node(0, "fake conflict notification")
     if delMsgs:
         for delMsg in delMsgs: 
             #put delete event into the log and execute delete
             e = self.node.createEvent(delMsg)
         for i in range(self.algorithm.n):#@TODO this line is broadcast  
             jsonmsg = self.algorithm.sendMsg2Node(i) 
             self.send2Node(i, jsonmsg)
 def sendMsg2Node(self, nodek):
     #@TODO load log from database
     log = self.dc.getLogs(0,sys.maxint)
     NP = {} #partial log
     ES = {} #event lists
     matrix =  [[0 for _ in range(self.n) ] for _ in range(self.n)]
     for i in range(self.n):
         for j in range(self.n):
             matrix[i][j] = self.dc.getTime(i, j)
     for (id,name,time,content) in log:
         event = Event(id,name,time,content)
         if not self.__hasRec(matrix, event, nodek):
            ES[event.name] = (event.time, event.node, event.content)  
            logging.debug((event.time, event.node, event.content))
     NP["matrix"] = matrix
     NP["events"] = ES 
     NP["senderID"] = Configuration.getMyID() 
     NP["receiverID"] = nodek 
     logging.debug(json.dumps(NP))
     return json.dumps(NP)
 def __init__(self):
     self.n = Configuration.getN()
     self.C = 0
     self.ID = Configuration.getMyID()
     self.dc = DataConn()
 def send2Node(self, nodeId, data):
     for name, protocol in self.users.iteritems():
         if name == nodeId and nodeId != Configuration.getMyID(): 
             protocol.sendLine(data)
             return
     logging.warning("One server's message not reply to client because no connection found or it's itself.")