示例#1
0
    def sendHeartbeat(self):
	while True:
		time.sleep(2) #sends heartbeat every 2 secs
		#print 'sending heartbeat'
		host,port = self.monitors[getMonitor()].partition(":")[::2]
		mon = Monitor(host,int(port),'False')
		mon.senddata('Heartbeat')
    def listen(self):
	print 'listening....' #TODO : log this
	while True:
   	    request, addr = self.sock.recvfrom(1024)
    	    self.pool.apply_async(ServeRequest, args=(request,self.masters,keylocation1,keylocation2))
	    global num_of_requests
	    num_of_requests=num_of_requests+1
	    if num_of_requests > threshold:
	       host,port = self.monitors[getMonitor()].partition(":")[::2]
               mon = Monitor(host,int(port),'False')
               mon.senddata('threshold')
               mon.closeconnection
示例#3
0
    def listen(self):
	print 'listening....' #TODO : log this
	#self.pool.apply_async(savekeymap,args=(self.keylocation,))
	thread = Thread(target = self.sendHeartbeat, args = ())
	thread.start()
	while True:
   	    request, addr = self.sock.recvfrom(1024)
	    req = json.loads(request)
	    if req['request'] == "New":
		with open("config/masters.txt",'a') as fin:
			fin.write(req['data'])
			fin.write("\n")
		self.masters[data.split("=")[0]] = data.split("=")[1]
	    else:
	    	self.pool.apply_async(ServeRequest, args=(request,self.masters,keylocation))
	    global num_of_requests
	    num_of_requests=num_of_requests+1
	    if num_of_requests > threshold:
	       host,port = self.monitors[getMonitor()].partition(":")[::2]
               mon = Monitor(host,int(port),'False')
               mon.senddata('threshold')
               mon.closeconnection