Exemplo n.º 1
0
 def __init__(self, in_address, out_addresses):
     self._in_socket = nanomsg.Socket(nanomsg.PULL)
     self._in_socket.bind(in_address)
     self._out_sockets = [nanomsg.Socket(nanomsg.PUSH) for i in out_addresses]
     for socket, address in zip(self._out_sockets, out_addresses):
         socket.bind(address)
     self._loop = asyncio.get_event_loop()
Exemplo n.º 2
0
    def setup_broker(self):
        self.brokerChanged = False
        if self.bsub != None:
            self.bsub.close()
            self.bsub = None

        self.apply_timeouts()

        if self.broker_address == "unknown":
            logger.error("Deferring broker setup as address is still unknown.")
            return

        self.bsub = nn.Socket(nn.SUB)
        self.bsub.connect("tcp://%s:8687" % (self.broker_address))
        self.bsub.set_string_option(nn.SUB, nn.SUB_SUBSCRIBE, "global")
        self.bsub.set_string_option(nn.SUB, nn.SUB_SUBSCRIBE, "local")
        self.bsub.set_string_option(nn.SUB, nn.SUB_SUBSCRIBE, "notlocal")
        if self.jobid != None:
            self.bsub.set_string_option(nn.SUB, nn.SUB_SUBSCRIBE, self.jobid)
        self.bsub.set_string_option(nn.SUB, nn.SUB_SUBSCRIBE, "tracker")
        self.apply_timeouts()

        self.bpub = nn.Socket(nn.PUB)
        self.bpub.connect("tcp://%s:8686" % (self.broker_address))

        logger.info("Broker setup complete")
Exemplo n.º 3
0
    def __init__( self, app, appconfig, workdata ):
        WorkerBase.__init__( self, app, appconfig, workdata )
        self.surveyorname = workdata["hostname"]
        self.vsub = nn.Socket( nn.SUB, domain=nn.AF_SP )
        self.vpub = nn.Socket( nn.PUB, domain=nn.AF_SP )
        self.broker_address = None

        self.bonjour = BonjourResolver( "_vertexremap._tcp", self.cb_broker_changed )
        self.bonjour.start()

        inputfile = os.path.join( self.remaproot, "data", self.workdata["inputfile"] )
        outputdir = os.path.join( self.remaproot, "job", self.jobid, "part" )

        self.input = self.app.create_vertex_reader( inputfile )
        self.outputdir = outputdir
        self.partitions = {}

        self.mode = MODE_IDLE

        self.surveyor = nn.Socket( nn.RESPONDENT )
        self.surveyor.connect( "tcp://%s:8688"%(self.surveyorname) )
        # 6 seconds
        self.surveyor.set_int_option( nn.SOL_SOCKET, nn.RCVTIMEO, 50 )
        self.vertices = {}

        logger.info("Waiting to get vertex broker host from bonjour")

        self.ready = False
Exemplo n.º 4
0
 def connect(self):
     if self._server is None:
         self._server = nmsg.Socket(nmsg.REP)
         self._server_endpoint = self._server.bind(self._uri)
         self._client = nmsg.Socket(nmsg.REQ)
         self._client_endpoint = self._client.connect(self._uri)
     return self._server
def main():

    # declare a socket
    subscriber_sock = nn.Socket(domain=nn.AF_SP, protocol=nn.SUB)
    subscriber_sock.set_string_option(level=nn.SUB,
                                      option=nn.SUB_SUBSCRIBE,
                                      value="")

    # bind the above socket to an endpoint
    subscriber_sock.connect("tcp://127.0.0.1:50000")

    # global counters for messaging stats
    subscriber_sock_msg_processed = 0

    try:

        start_time = time.time()

        while (1):

            print subscriber_sock.recv()

            subscriber_sock_msg_processed = subscriber_sock_msg_processed + 1

    except KeyboardInterrupt, e:
        end_time = time.time()
        delta = end_time - start_time

        print 'total messages processed by subscriber_sock: %s' % subscriber_sock_msg_processed
        print 'messages processed by subscriber_sock per second: %s' % str(
            int(subscriber_sock_msg_processed / delta))
Exemplo n.º 6
0
 def __init__(self, conf, driver_names, use_nanoconfig_service,
              publisher_endpoint, nanoconfig_service_endpoint,
              nanoconfig_update_endpoint, nanoconfig_profile):
     """
     :param conf: Configuration obtained from a configuration file
     :type conf: oslo_config.cfg.ConfigOpts instance
     :param driver_names: The list of driver names to register
     :type driver_names: list of str
     :param use_nanoconfig_service: Indicates whether or not it should use a
         nanoconfig service
     :type use_nanoconfig_service: bool
     :param publisher_endpoint: Publisher server URI
     :type publisher_endpoint: str
     :param nanoconfig_service_endpoint: Nanoconfig service URI
     :type nanoconfig_service_endpoint: str
     :param nanoconfig_update_endpoint: Nanoconfig update service URI
     :type nanoconfig_update_endpoint: str
     :param nanoconfig_profile: Nanoconfig profile URI
     :type nanoconfig_profile: str
     """
     super(Agent, self).__init__(conf, driver_names)
     self.socket = nanomsg.Socket(nanomsg.PUSH)
     self.use_nanoconfig_service = use_nanoconfig_service
     self.publisher_endpoint = publisher_endpoint
     self.nanoconfig_service_endpoint = nanoconfig_service_endpoint
     self.nanoconfig_update_endpoint = nanoconfig_update_endpoint
     self.nanoconfig_profile = nanoconfig_profile
Exemplo n.º 7
0
def main():

    global msg_processed

    # declare a socket
    publisher_sock = nn.Socket(domain=nn.AF_SP, protocol=nn.PUB)

    # bind the above socket to an endpoint
    publisher_sock.bind("tcp://127.0.0.1:50000")

    try:

        start_time = time.time()

        while (1):

            # read the message which the client has sent
            publisher_sock.send("Current time in Bangalore, India: %s" %
                                str(datetime.datetime.now()))

            msg_processed = msg_processed + 1

    except KeyboardInterrupt, e:

        end_time = time.time()

        print 'total messages processed: %s' % str(msg_processed)
        print 'messages processed per second: %s' % str(
            int(msg_processed / (end_time - start_time)))
        print 'messages processed per minute: %s' % str(
            int(msg_processed / (end_time - start_time)) * 60)
Exemplo n.º 8
0
def main():

    # sockets who will communicate among themselves
    s2 = nn.Socket(domain=nn.AF_SP, protocol=nn.PAIR)

    # connect to the above declared endpoint
    s2.connect("ipc://test-ipc-pair")

    # global counters on msgs prrocessed by both peers
    s2_msg_processed = 0

    start_time = time.time()

    try:

        while (1):

            print s2.recv()
            s2_msg_processed = s2_msg_processed + 1
            s2.send("Hi! from s2")

    except KeyboardInterrupt, e:
        end_time = time.time()
        print 'total messages processed by s2: %s' % s2_msg_processed
        print 'total messages processed by s2 per sec: %s' % str(
            int(s2_msg_processed / (end_time - start_time)))
Exemplo n.º 9
0
def main():

    global msg_processed

    # declare a socket
    respondent_sock = nn.Socket(domain=nn.AF_SP, protocol=nn.RESPONDENT)

    # bind the sock
    respondent_sock.connect("tcp://127.0.0.1:50000")

    try:

        start_time = time.time()

        while (1):

            print respondent_sock.recv()

            # read the message which the client has sent
            respondent_sock.send("I provide payments: %s" % str(os.getpid()))
            msg_processed = msg_processed + 1

    except KeyboardInterrupt, e:

        end_time = time.time()

        print 'total messages processed: %s' % str(msg_processed)
        print 'messages processed per second: %s' % str(
            int(msg_processed / (end_time - start_time)))
        print 'messages processed per minute: %s' % str(
            int(msg_processed / (end_time - start_time)) * 60)
Exemplo n.º 10
0
def main():

    global msg_processed

    # declare a socket
    push_sock = nn.Socket(domain=nn.AF_SP, protocol=nn.PUSH)

    # bind the above socket to an endpoint
    push_sock.bind("tcp://127.0.0.1:50000")

    try:

        start_time = time.time()

        while (1):

            # send a message
            push_sock.send("Hi! from push_sock at: tcp://127.0.0.1:50000")

            msg_processed = msg_processed + 1

    except KeyboardInterrupt, e:

        end_time = time.time()

        print 'total messages processed: %s' % str(msg_processed)
        print 'messages processed per second: %s' % str(
            int(msg_processed / (end_time - start_time)))
        print 'messages processed per minute: %s' % str(
            int(msg_processed / (end_time - start_time)) * 60)
Exemplo n.º 11
0
    def __init__(self):
        super(ReaderThread, self).__init__()
        self.inst = None
        self.interrupted = False

        self.soc_pub = nanomsg.Socket(nanomsg.PUB)
        self.soc_pub.bind("tcp://*:12345")
Exemplo n.º 12
0
    def __create_NN_subscriber(self):
        """Function used to create a NN publisher"""
        try:
            import nanomsg
            self.NN_installed = True
        except ImportError:
            print("NEP WARNING: Nanomsg not installed")
            self.NN_installed = False

        if self.NN_installed == False:
            msg = "Unable to use surveyor pattern due that Nanomsg is not installed "
            raise ValueError(msg)
        else:
            success, self.port, self.ip = self.__network_selection()
            if success:
                try:
                    self.sock = nanomsg.Socket(nanomsg.SUB)
                    self.sock.set_string_option(nanomsg.SUB,
                                                nanomsg.SUB_SUBSCRIBE,
                                                self.topic)
                    #TODO: zmq.CONFLATE in nanomsg # Only keeps last mesange in queue
                    self.__connect_NN_socket()
                except Exception as e:
                    exc_type, exc_obj, exc_tb = sys.exc_info()
                    fname = os.path.split(
                        exc_tb.tb_frame.f_code.co_filename)[1]
                    print(exc_type, fname, exc_tb.tb_lineno)
def main():

    # sockets who will communicate among themselves
    s1 = nn.Socket(domain=nn.AF_SP, protocol=nn.PAIR)

    # bind to an endpoint
    s1.bind("tcp://127.0.0.1:50000")

    # global counters on msgs prrocessed by both peers
    s1_msg_processed = 0

    start_time = time.time()

    try:

        while (1):

            s1.send("Hi! from s1")
            print s1.recv()
            s1_msg_processed = s1_msg_processed + 1

    except KeyboardInterrupt, e:
        end_time = time.time()
        print 'total messages processed by s1: %s' % s1_msg_processed
        print 'total messages processed by s1 per sec: %s' % str(
            int(s1_msg_processed / (end_time - start_time)))
Exemplo n.º 14
0
def main():

    # declare a socket
    client_sock = nn.Socket(domain=nn.AF_SP, protocol=nn.REQ)

    # bind the above socket to an endpoint
    client_sock.connect("tcp://127.0.0.1:50000")

    # global counters for messaging stats
    client_sock_msg_processed = 0

    try:

        start_time = time.time()

        while (1):

            # send a message to the server
            msg = 'Hi! from a client with os level PID: %s' % os.getpid()
            msg = client_sock.send(msg)

            # process the response from the server
            print client_sock.recv()

            client_sock_msg_processed = client_sock_msg_processed + 1

    except KeyboardInterrupt, e:
        end_time = time.time()
        delta = end_time - start_time

        print 'total messages processed by client_sock: %s' % client_sock_msg_processed
        print 'messages processed by client_sock per second: %s' % str(
            int(client_sock_msg_processed / delta))
def main():

  global msg_processed
  
  # declare a socket
  app_sock = nn.Socket(domain=nn.AF_SP, protocol=nn.BUS)

  app_sock.bind("tcp://127.0.0.1:50003")

  # bind the above socket to an endpoint
  app_sock.connect("tcp://127.0.0.1:50000")
  app_sock.connect("tcp://127.0.0.1:50001")
  app_sock.connect("tcp://127.0.0.1:50002") 

  try:

    start_time = time.time()

    while (1):

      # send a response back
      app_sock.send("Hi! app_sock with PID: %s" % str(os.getpid()))

      # read the message which the client has sent
      print app_sock.recv()

      msg_processed = msg_processed + 1

  except KeyboardInterrupt, e:

    end_time = time.time()

    print 'total messages processed: %s' % str(msg_processed)
    print 'messages processed per second: %s' % str(int(msg_processed/(end_time - start_time)))
    print 'messages processed per minute: %s' % str(int(msg_processed/(end_time - start_time)) * 60) 
Exemplo n.º 16
0
def main():

    # declare a socket
    pull_sock = nn.Socket(domain=nn.AF_SP, protocol=nn.PULL)

    # bind the above socket to an endpoint
    pull_sock.connect("tcp://127.0.0.1:50000")

    # global counters for messaging stats
    pull_sock_msg_processed = 0

    try:

        start_time = time.time()

        while (1):

            # process the response from the server
            print pull_sock.recv()

            pull_sock_msg_processed = pull_sock_msg_processed + 1

    except KeyboardInterrupt, e:
        end_time = time.time()
        delta = end_time - start_time

        print 'total messages processed by pull_sock: %s' % pull_sock_msg_processed
        print 'messages processed by pull_sock per second: %s' % str(
            int(pull_sock_msg_processed / delta))
Exemplo n.º 17
0
    def start(self):

        exe_dir = path.join(conf.get('home'), 'bin')
        exe_path = path.join(exe_dir, 'jamovi-engine')

        si = None
        stdout = sys.stdout
        stderr = sys.stderr
        if platform.uname().system == 'Windows':
            si = subprocess.STARTUPINFO()
            si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
            stdout = None
            stderr = None  # stdouts seem to break things on windows

        # be a bit wary to make changes to the Popen call
        # seemingly inconsequential changes can break things on windows

        address = self._conn_root + '-' + str(self._index)
        con = '--con={}'.format(address)
        pth = '--path={}'.format(self._session_path)
        self._process = subprocess.Popen([exe_path, con, pth],
                                         startupinfo=si,
                                         stdout=stdout,
                                         stderr=stderr)

        self._socket = nanomsg.Socket(nanomsg.PAIR)
        self._socket._set_recv_timeout(500)
        self._socket.bind(address)

        self._thread = threading.Thread(target=self._run)
        self._thread.start()
Exemplo n.º 18
0
    def __init__(self, source, elements, output):
        self.source = source
        self.elements = elements
        self.output = output

        self.interrupted = False

        self.soc_sub = nanomsg.Socket(nanomsg.SUB)
Exemplo n.º 19
0
 def init_socket(self):
     self.request = nanomsg.Socket(nanomsg.REQ)
     # self.request.setsockopt(zmq.IDENTITY, "xraycli-" + str(os.getpid()))
     self.request.recv_timeout = 1000
     self.request.send_timeout = 1000
     self.request.connect('ipc://{}/{}'.format(self.XRAY_NODES_PATH,
                                               self.node))
     self.intiated = True
Exemplo n.º 20
0
    def __init__(self, address, encoder=None, authenticator=None,
                 socket=None, bind=False, timeouts=(None, None)):

        # Defaults
        socket = socket or nanomsg.Socket(nanomsg.REQ)
        encoder = encoder or MsgPackEncoder()

        super(Requester, self).__init__(
            socket, address, bind, encoder, authenticator, timeouts)
Exemplo n.º 21
0
    def __init__(self, workdata, config):
        FileModule.__init__(self,workdata,config)
        self.surveyor = nn.Socket( nn.SURVEYOR )
        self.surveyor.bind( "tcp://0.0.0.0:8688" )

        # 10 seconds max
        self.surveyor.set_int_option( nn.SURVEYOR, nn.SURVEYOR_DEADLINE, 10000 )
        self.superstep = 0
        self.mode = MODE_SHIFT
        self.first = True
Exemplo n.º 22
0
    def __init__(self, redis, bus_id, channels_bus_list):
        self._id = bus_id

        # create sockets
        self._bus_socket = nanomsg.Socket(nanomsg.BUS)
        self._respondent_socket = nanomsg.Socket(nanomsg.RESPONDENT)

        bus_socket_port_number = get_free_port(redis, CHANNELS_BUS)
        self._bus_socket.bind("tcp://*:%d" % bus_socket_port_number)
        BUS_BY_FD[self.recv_fd] = self
        # connect to other bus sockets
        for remote_bus in channels_bus_list:
            self._bus_socket.connect(remote_bus)
        self.__bus_addr = "tcp://%s:%d" % (socket.getfqdn(),
                                           bus_socket_port_number)

        # respondent socket is used to reply to survey requests
        respondent_socket_port_number = get_free_port(redis,
                                                      CHANNELS_RESPONDENT)
        self._respondent_socket.bind("tcp://*:%d" %
                                     respondent_socket_port_number)
        BUS_BY_FD[self._respondent_socket.recv_fd] = self
        self.__bus_respondent_addr = "tcp://%s:%d" % (
            socket.getfqdn(), respondent_socket_port_number)

        # remove addresses in redis at exit
        atexit.register(_clean_redis, redis, self.addr, self.respondent_addr)

        # receiver thread takes care of dispatching received values to right channels
        global RECEIVER_THREAD
        if RECEIVER_THREAD is None:
            global WAKE_UP_SOCKET_W
            global WAKE_UP_SOCKET_R
            WAKE_UP_SOCKET_W = nanomsg.Socket(nanomsg.PAIR)
            WAKE_UP_SOCKET_W.bind("inproc://beacon/channels/wake_up_loop")
            WAKE_UP_SOCKET_R = nanomsg.Socket(nanomsg.PAIR)
            WAKE_UP_SOCKET_R.connect("inproc://beacon/channels/wake_up_loop")
            RECEIVER_THREAD = threading.start_new_thread(
                receive_channels_values, ())
            atexit.register(stop_receiver_thread)
        else:
            WAKE_UP_SOCKET_W.send('!')
Exemplo n.º 23
0
def main():
    ts_analyser = TSAnalyser()
    socket = nanomsg.Socket(nanomsg.PAIR)
    socket.connect(sys.argv[1])
    start = time.monotonic()
    while True:
        msg = socket.recv()
        print(msg)
        continue
        for diff, spi_diff in process_message(msg):
            ts_analyser.feed(diff, spi_diff)
Exemplo n.º 24
0
def nanomsg_bus_recv():
    with nanomsg.Socket(nanomsg.BUS) as socket:
        socket.connect("tcp://futoke.ru:{}".format(PORT))

        start = time.time()

        for i in range(MSG_COUNT):
            socket.recv()

        end = time.time()
        print(MSG_COUNT / (end - start))
Exemplo n.º 25
0
 def __init__(self, listeners=None, raw_listeners=None, loop=None):
     self._socket = nanomsg.Socket(nanomsg.PULL)
     if listeners is None:
         listeners = []
     self._listeners = listeners
     if raw_listeners is None:
         raw_listeners = []
     self._raw_listeners = raw_listeners
     if loop is None:
         loop = asyncio.get_event_loop()
     self._loop = loop
Exemplo n.º 26
0
def nanomsg_pubsub_recv():
    with nanomsg.Socket(nanomsg.SUB) as socket:
        socket.connect("tcp://futoke.ru:{}".format(PORT))
        socket.set_string_option(nanomsg.SUB, nanomsg.SUB_SUBSCRIBE, '')

        start = time.time()

        for i in range(MSG_COUNT):
            socket.recv()

        end = time.time()
        print(MSG_COUNT / (end - start))
Exemplo n.º 27
0
    def __init__(self, address, encoder=None, authenticator=None,
                 socket=None, bind=True, timeouts=(None, None)):

        # Defaults
        socket = socket or nanomsg.Socket(nanomsg.REP)
        encoder = encoder or MsgPackEncoder()

        super(Responder, self).__init__(
            socket, address, bind, encoder, authenticator, timeouts)

        self.methods = {}
        self.descriptions = {}
Exemplo n.º 28
0
    def start(self):

        exe_dir = path.join(conf.get('home'), 'bin')
        exe_path = path.join(exe_dir, 'jamovi-engine')

        env = os.environ.copy()
        env['R_HOME'] = conf.get('r_home', env.get('R_HOME', ''))
        env['R_LIBS'] = conf.get('r_libs', env.get('R_LIBS', ''))
        env['FONTCONFIG_PATH'] = conf.get('fontconfig_path',
                                          env.get('FONTCONFIG_PATH', ''))
        env['JAMOVI_MODULES_PATH'] = conf.get(
            'modules_path', env.get('JAMOVI_MODULES_PATH', ''))

        si = None
        stdout = sys.stdout
        stderr = sys.stderr

        # Additional customizations for windows
        if platform.uname().system == 'Windows':
            si = subprocess.STARTUPINFO()
            stdout = None
            stderr = None  # stdouts seem to break things on windows

            # makes the engine windows visible in debug mode (on windows)
            if not conf.get('debug', False):
                si.dwFlags |= subprocess.STARTF_USESHOWWINDOW

        # be a bit wary to make changes to the Popen call
        # seemingly inconsequential changes can break things on windows

        con = '--con={}'.format(self._conn_path)
        pth = '--path={}'.format(self._data_path)

        try:
            self._process = subprocess.Popen([exe_path, con, pth],
                                             startupinfo=si,
                                             stdout=stdout,
                                             stderr=stderr,
                                             env=env)

            self._socket = nanomsg.Socket(nanomsg.PAIR)
            self._socket._set_recv_timeout(500)
            self._socket.bind(self._conn_path)

            self._thread = threading.Thread(target=self._run)
            self._thread.start()

        except BaseException as e:
            self._parent._notify_engine_event({
                'type': 'error',
                'message': 'Engine process could not be started',
                'cause': str(e),
            })
Exemplo n.º 29
0
    def __init__(self, topic, timeout=1000, node_name="default", debug=False):
        """ Nanomsg surveyor class
            
            Parameters
            ----------

            topic : string
                Surveyor topic

            timeout : int
                Maximun miliseconds waiting for response

            debug: bool
                If True some additional information of the subscriber is shown

            """
        self.topic = topic
        print("SURVEY: " + self.topic + " waiting for NEP master ...")
        self.pid = os.getpid()
        success, port, ip = nep.masterRegister(node_name,
                                               self.topic,
                                               master_ip='127.0.0.1',
                                               master_port=7000,
                                               socket="surveyor",
                                               pid=self.pid,
                                               data_type="json")
        print("SURVEY: " + self.topic + " socket ready")
        self.debug = debug

        if success:

            self.NN_installed = False
            try:
                import nanomsg
                self.NN_installed = True
            except ImportError:
                print("Nanomsg not installed")
                self.NN_installed = False

            if self.NN_installed == False:
                msg = "Unable to use surveyor pattern due that Nanomsg is not installed "
                raise ValueError(msg)

            self.sock = nanomsg.Socket(nanomsg.SURVEYOR)
            endpoint = "tcp://" + ip + ":" + str(port)
            self.sock.bind(endpoint)
            self.sock.set_int_option(nanomsg.SURVEYOR,
                                     nanomsg.SURVEYOR_DEADLINE, timeout)
            time.sleep(1)
            if self.debug:
                print("surveyor started in: " + str(endpoint))
Exemplo n.º 30
0
    def __init__(self, source, conf, limits, steps, doblit=False):
        super(PlottingThread, self).__init__()
        self.interrupted = False

        self.source = source
        self.conf = conf
        self.limits = limits
        self.steps = steps

        self.doblit = doblit

        self.soc_sub = nanomsg.Socket(nanomsg.SUB)
        self.soc_sub.set_string_option(nanomsg.SUB, nanomsg.SUB_SUBSCRIBE, "")
        self.soc_sub.set_int_option(nanomsg.SOL_SOCKET, nanomsg.RECONNECT_IVL, 1000)
        self.soc_sub.set_int_option(nanomsg.SOL_SOCKET, nanomsg.RECONNECT_IVL_MAX, 1000 * 30)
        self.soc_sub.connect(self.source)