class Protocol: def __init__(self, recv_queue, send_queues, master_send_queue): self.connection = Connection() self.receiver = self.connection.create_distributed_work_receiver( recv_queue) self.senders = {} for queue in send_queues: self.senders[queue] = self.connection.create_direct_sender(queue) self.master_sender = self.connection.create_direct_sender( master_send_queue) def start_connection(self, callback, callback_eof): self.callback = callback self.callback_eof = callback_eof self.receiver.start_receiving(self.data_read) def send_data(self, data, where): self.senders[where].send(NORMAL, data) def send_master_ended(self): self.master_sender.send(EOF, "") def data_read(self, method, msg_type, msg): if msg_type == EOF: self.callback_eof() self.receiver.send_ack(method) self.receiver.close() self.send_master_ended() self.connection.close() else: self.callback(msg) self.receiver.send_ack(method)
class Protocol: def __init__(self, recv_queue, send_queue, total_workers): self.connection = Connection() self.pending_connections = total_workers self.receiver = self.connection.create_direct_receiver(recv_queue) self.sender = self.connection.create_direct_sender(send_queue) def start_connection(self, callback): self.callback = callback self.receiver.start_receiving(self.data_read) def data_read(self, msg_type, msg): if msg_type == EOF: #self.receiver.close() self.pending_connections -= 1 if self.pending_connections == 0: self.receiver.close() else: self.callback(json.loads(msg)) def send_data(self, top_cities): self.sender.send(TOP_CITIES, json.dumps(top_cities)) 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()
class Protocol: def __init__(self, recv_queue, send_queue, master_queue): self.connection = Connection() self.receiver = self.connection.create_direct_receiver(recv_queue) self.sender = self.connection.create_direct_sender(send_queue) self.master_sender = self.connection.create_direct_sender(master_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, json.dumps(data)) self.sender.send(EOF, "") #self.master_sender.send(EOF, "") def data_read(self, msg_type, msg): if msg_type == EOF: self.receiver.close() else: self.callback(msg)
class Protocol: def __init__(self, recv_queue, send_queue): self.connection = Connection() self.receiver = self.connection.create_direct_receiver(recv_queue) self.sender = self.connection.create_direct_sender(send_queue) def start_connection(self, callback): self.callback = callback self.receiver.start_receiving(self.data_read) def data_read(self, msg_type, msg): if msg_type == EOF: self.receiver.close() else: [positivi, deceduti] = msg.split(',') self.callback(int(positivi), int(deceduti)) def send_data(self, percentage): self.sender.send(TOTAL_COUNT, str(percentage)) self.sender.send(EOF, '')
class Protocol: def __init__(self, recv_queue, send_queue, total_workers): self.connection = Connection() self.pending_connections = total_workers self.receiver = self.connection.create_direct_receiver(recv_queue) self.sender = self.connection.create_direct_sender(send_queue) self.send_queue = send_queue def start_connection(self): self.receiver.start_receiving(self.data_read) def data_read(self, msg_type, msg): if msg_type == EOF: self.pending_connections -= 1 if self.pending_connections == 0: self.receiver.close() self.sender.send(EOF, '') self.connection.close()