def connect_socket(self): """ Sets up the sockets to do the communication with the source_com process through the forwarders (for the link and the parameters). :return: Nothing """ self.context = zmq.Context() # Setup the socket that receives the parameters of the worker_exec function from the node self.socket_sub_parameters = Socket(self.context, zmq.SUB) self.socket_sub_parameters.setsockopt(zmq.LINGER, 0) self.socket_sub_parameters.subscribe(self.parameters_topic) self.ssh_com.connect_socket_to_local(self.socket_sub_parameters, r'tcp://127.0.0.1', self.port_sub_parameters) self.socket_sub_parameters.subscribe(self.parameters_topic) # Setup the socket that pushes the data to the com self.socket_push_data = Socket(self.context, zmq.PUSH) self.socket_push_data.setsockopt(zmq.LINGER, 0) self.socket_push_data.set_hwm(1) self.socket_push_data.bind(r"tcp://127.0.0.1:{}".format(self.data_port)) # Setup the socket that receives the heartbeat from the com self.socket_pull_heartbeat = self.context.socket(zmq.PULL) self.socket_pull_heartbeat.setsockopt(zmq.LINGER, 0) self.ssh_com.connect_socket_to_local(self.socket_pull_heartbeat, r'tcp://127.0.0.1', self.pull_heartbeat_port) # Setup the socket that publishes the fact that the worker_exec is up and running to the node com so that it # can then update the parameters of the worker_exec. self.socket_pub_proof_of_life = Socket(self.context, zmq.PUB) self.socket_pub_proof_of_life.setsockopt(zmq.LINGER, 0) self.ssh_com.connect_socket_to_local(self.socket_pub_proof_of_life, r'tcp://127.0.0.1', self.port_pub_proof_of_life, skip_ssh=True)
def connect_sockets(self): """ Start the required sockets to communicate with the link forwarder and the source_com processes :return: Nothing """ if self.verbose: print('Starting Source Node with PID = {}'.format(os.getpid())) self.context = zmq.Context() # Socket for pulling the data from the worker_exec self.socket_pull_data = Socket(self.context, zmq.PULL) self.socket_pull_data.setsockopt(zmq.LINGER, 0) self.socket_pull_data.set_hwm(1) self.socket_pull_data.connect(r"tcp://127.0.0.1:{}".format(self.pull_data_port)) self.stream_pull_data = zmqstream.ZMQStream(self.socket_pull_data) self.stream_pull_data.on_recv(self.on_receive_data_from_worker) # Socket for publishing the data to the data forwarder self.socket_pub_data = Socket(self.context, zmq.PUB) self.socket_pub_data.setsockopt(zmq.LINGER, 0) self.socket_pub_data.set_hwm(len(self.sending_topics)) self.socket_pub_data.connect(r"tcp://127.0.0.1:{}".format(self.port_pub)) # Socket for publishing the heartbeat to the worker_exec self.socket_push_heartbeat = self.context.socket(zmq.PUSH) self.socket_push_heartbeat.setsockopt(zmq.LINGER, 0) self.socket_push_heartbeat.bind(r'tcp://*:{}'.format(self.heartbeat_port)) self.socket_push_heartbeat.set_hwm(1)
def connect_sockets(self): """ Sets up the sockets to do the communication with the transform_com process through the forwarders (for the link and the parameters). :return: Nothing """ self.context = zmq.Context() # Setup the socket and the stream that receives the data from the com to be worked upon self.socket_pull_data = Socket(self.context, zmq.PULL) self.socket_pull_data.setsockopt(zmq.LINGER, 0) self.socket_pull_data.set_hwm(1) self.ssh_com.connect_socket_to_local(self.socket_pull_data, r'tcp://127.0.0.1', self.pull_data_port) self.stream_pull_data = zmqstream.ZMQStream(self.socket_pull_data) self.stream_pull_data.on_recv(self.data_callback, copy=False) # Setup the socket and the stream that receives the parameters of the worker_exec function from the node (gui_com) self.socket_sub_parameters = Socket(self.context, zmq.SUB) self.socket_sub_parameters.setsockopt(zmq.LINGER, 0) self.ssh_com.connect_socket_to_local(self.socket_sub_parameters, r'tcp://127.0.0.1', self.port_sub_parameters) self.socket_sub_parameters.subscribe(self.parameters_topic) self.stream_parameters = zmqstream.ZMQStream( self.socket_sub_parameters) self.stream_parameters.on_recv(self.parameters_callback, copy=False) # Setup the socket that pushes the end of worker function signal to the com self.socket_push_data = Socket(self.context, zmq.PUSH) self.socket_push_data.setsockopt(zmq.LINGER, 0) self.socket_push_data.set_hwm(1) self.socket_push_data.bind(r"tcp://127.0.0.1:{}".format( self.push_data_port)) # Setup the socket that receives the heartbeat from the com self.socket_pull_heartbeat = self.context.socket(zmq.PULL) self.socket_pull_heartbeat.setsockopt(zmq.LINGER, 0) self.ssh_com.connect_socket_to_local(self.socket_pull_heartbeat, r'tcp://127.0.0.1', self.pull_heartbeat_port) self.stream_heartbeat = zmqstream.ZMQStream(self.socket_pull_heartbeat) self.stream_heartbeat.on_recv(self.heartbeat_callback, copy=False) # Setup the socket that sends (publishes) the fact that the worker_exec is up and running to the node com so that it # can then update the parameters of the worker_exec self.socket_pub_proof_of_life = Socket(self.context, zmq.PUB) self.socket_pub_proof_of_life.setsockopt(zmq.LINGER, 0) self.ssh_com.connect_socket_to_local(self.socket_pub_proof_of_life, r'tcp://127.0.0.1', self.port_pub_proof_of_life, skip_ssh=True)
def initialise_parameters_socket(self): if self.context is None: self.context = zmq.Context() self.socket_pub_parameters = Socket(self.context, zmq.PUB) self.socket_pub_parameters.setsockopt(zmq.LINGER, 0) self.socket_pub_parameters.connect(r"tcp://127.0.0.1:{}".format( ct.PARAMETERS_FORWARDER_SUBMIT_PORT))
def connect_sockets(self): """ Start the required sockets to communicate with the link forwarder and the worker_com processes :return: Nothing """ if self.verbose: print('Starting Sink Node with PID = {}'.format(os.getpid())) self.context = zmq.Context() # Socket for subscribing to data from nodes connected to the input self.socket_sub_data = Socket(self.context, zmq.SUB) self.socket_sub_data.setsockopt(zmq.LINGER, 0) self.socket_sub_data.set_hwm(len(self.receiving_topics)) self.socket_sub_data.connect("tcp://127.0.0.1:{}".format( self.port_sub_data)) for rt in self.receiving_topics: self.socket_sub_data.setsockopt(zmq.SUBSCRIBE, rt.encode('ascii')) self.poller.register(self.socket_sub_data, zmq.POLLIN) # Socket for pushing the data to the worker_exec self.socket_push_data = Socket(self.context, zmq.PUSH) self.socket_push_data.setsockopt(zmq.LINGER, 0) self.socket_push_data.set_hwm(1) self.socket_push_data.bind(r"tcp://*:{}".format(self.push_data_port)) # Socket for pulling the end of worker function signal from the worker_exec self.socket_pull_data = Socket(self.context, zmq.PULL) self.socket_pull_data.setsockopt(zmq.LINGER, 0) self.socket_pull_data.set_hwm(1) self.socket_pull_data.connect(r"tcp://127.0.0.1:{}".format( self.pull_data_port)) self.poller.register(self.socket_pull_data, zmq.POLLIN) # Socket for pushing the heartbeat to the worker_exec self.socket_push_heartbeat = self.context.socket(zmq.PUSH) self.socket_push_heartbeat.setsockopt(zmq.LINGER, 0) self.socket_push_heartbeat.bind(r'tcp://*:{}'.format( self.push_heartbeat_port)) self.socket_push_heartbeat.set_hwm(1)