class Protocol: def __init__(self, recv_queue, send_queue, total_workers): self.connection = Connection() self.total_workers = total_workers self.receiver = self.connection.create_direct_receiver(recv_queue) self.sender = self.connection.create_distributed_work_sender( send_queue) def start_connection(self): #, callback): #self.callback = callback self.receiver.start_receiving(self.data_read) #def send_data(self, data): # self.sender.send(NORMAL, data) def data_read(self, msg_type, msg): self.receiver.close() self.send_eof() self.connection.close() '''if msg_type == "EOF": self.receiver.close() self.send_eof() self.connection.close() else: self.callback(msg)''' def send_eof(self): for i in range(0, self.total_workers): self.sender.send(EOF, '')
class Protocol: def __init__(self, queue_map, queue_date, queue_count, eof_map, eof_date, eof_count, topic_places): self.connection = Connection() self.sender_map = self.connection.create_distributed_work_sender( queue_map) self.sender_date = self.connection.create_distributed_work_sender( queue_date) self.sender_count = self.connection.create_distributed_work_sender( queue_count) self.sender_places = self.connection.create_topic_sender(topic_places) self.eof_map = self.connection.create_direct_sender(eof_map) self.eof_date = self.connection.create_direct_sender(eof_date) self.eof_count = self.connection.create_direct_sender(eof_count) def process_places(self, region, latitude, longitude): message = region + "," + latitude + "," + longitude self.sender_places.send(NORMAL, message) def send_no_more_places(self): self.sender_places.send(EOF, "") def process(self, date, latitude, longitude, result): message = date + "," + latitude + "," + longitude + "," + result self.sender_map.send(NORMAL, message) self.sender_date.send(NORMAL, message) self.sender_count.send(NORMAL, message) def close(self): #self.sender_map.send(EOF, "") #self.sender_date.send(EOF, "") #self.sender_count.send(EOF, "") self.eof_map.send(EOF, "") self.eof_date.send(EOF, "") self.eof_count.send(EOF, "") self.connection.close()