예제 #1
0
 def on_message(self, headers, message):
     logDS.info('received a message "%s"' % message)
     global conn
     for i in range(10):
         time.sleep(1)
         logDS.info('sleep %ds' % i)
     conn.ack(headers["message-id"], 0)
예제 #2
0
def startService():
    thread_list = []
    for i in range(4):
        thread = thread_process(i)
        thread.start()
        time.sleep(1)
        thread_list.append(thread)

    global is_new
    index = 0
    while False == check_thread_staus(thread_list):
        #for i in range(1000):
        #time.sleep(2)
        cv.acquire()
        is_new = True
        if False:
            cv.notify_all()
        else:
            cv.notify()
        if index % 10000 == 0:
            logDS.info("xxxxxxxxxxxxxxxxxxxxxxxxxxx %d" % (index))
        cv.release()
        index = index + 1
    logDS.info("xxxxxxxxxxxxxxxxxxxxxxxxxxx notify finished %d" % (index))

    for t in thread_list:
        t.join()
예제 #3
0
def thread_process2(index):
    logDS.info("begin %d" % index)
    try:
        Container(Server(url, url.path, index)).run()
    except KeyboardInterrupt:
        pass
    logDS.info("exit %d" % index)
예제 #4
0
def thread_process2(index):
    logDS.info("begin %d" % index)
    client = mqtt.Client()
    client.on_connect = on_connect
    client.on_message = on_message

    client.connect("172.10.3.111", 1883, 60)
    client.loop_forever()
    logDS.info("exit %d" % index)
예제 #5
0
def thread_process2(index):
    global is_new
    for i in range(10000):
        cv.acquire()
        if False == is_new:
            cv.wait()
        is_new = False
        cv.release()
        logDS.info("thread_process2 %d %d" % (index, i))
    logDS.info("thread_process2 exit %d" % (index))
예제 #6
0
def thread_process2(index):
    logDS.info("begin %d" % index)
    client = mqtt.Client()
    client.on_connect = on_connect
    client.on_message = on_message
    client.enable_logger(logDS.logger)

    client.connect("172.10.3.111", 1883, 60)
    client.subscribe("queue/test")
    client.loop_forever()
    logDS.info("exit %d" % index)
예제 #7
0
def thread_process2(index):
    loop_num = int(sys.argv[1])
    logDS.info("begin %d" % index)
    client = mqtt.Client(userdata="test_publish_%d" % index)
    client.on_connect = on_connect
    client.on_message = on_message
    client.enable_logger(logDS.logger)

    client.connect("172.10.3.111", 1883, 60)
    for i in range(loop_num):
        client.publish("/my/topic", payload="msg%d" % i)
    time.sleep(2)
    logDS.info("exit %d" % index)
예제 #8
0
def thread_process2(index):
    loop_num = int(sys.argv[1])
    logDS.info("begin %d"%index)
    client = mqtt.Client()
    client.on_connect = on_connect
    client.on_message = on_message
    client.enable_logger(logDS.logger)

    client.connect("172.10.3.111", 1883, 60)
    for i in range(loop_num):
        client.publish("queue/test", payload="msg%d"%i)
        #client.publish("queue/test", retain=True, payload="msg%d" % i)
        #client.publish("queue/test",retain=True)
    time.sleep(2)
    logDS.info("exit %d"%index)
def thread_process2(index):
    logDS.info("begin %d" % index)
    zk = KazooClient(hosts='172.10.3.111:2181', logger=logDS.logger)
    zk.start()
    root = "/electionpath"
    election = zk.Election(root, "identifier:%d" % 0)

    # blocks until the election is won, then calls
    # my_leader_function()
    election.run(my_leader_function)
    print(election.contenders())
    #logDS.info("thread_process2 88")
    #time.sleep(10)
    zk.stop()
    logDS.info("exit %d" % index)
예제 #10
0
def thread_process2(index):
    logDS.info("begin %d"%index)
    conn = stomp.Connection([('172.10.3.111', 61613)])
    conn.set_listener('', MyListener())
    #conn.set_listener('stats', StatsListener())
    #conn.set_listener('print', PrintingListener())
    conn.start()
    #conn.connect()
    conn.connect('guest', 'guest', wait=True)
    conn.subscribe('/queue/test', 123)
    for i in range(2):
        conn.send('/queue/test', 'a test message %d'%i)
    #conn.send(body=' '.join(sys.argv[1:]), destination='/queue/test')
    time.sleep(2)
    conn.disconnect()
    logDS.info("exit %d"%index)
예제 #11
0
def thread_process2(index):
    loop_num = int(sys.argv[1])
    logDS.info("begin %d"%index)
    conn = stomp.Connection([('172.10.3.111', 61613)])
    conn.set_listener('', MyListener())
    conn.start()

    #conn.connect()
    conn.connect('guest', 'guest', wait=True)
    for i in range(loop_num):
        #time.sleep(1)
        headers = {}
        conn.send('/topic/test', 'a test message %d'%i, headers=headers)
    #conn.send(body=' '.join(sys.argv[1:]), destination='/queue/test')
    time.sleep(2)
    conn.disconnect()
    logDS.info("exit %d"%index)
예제 #12
0
def thread_process2(index):
    global is_stop
    global is_new
    global data_cache
    indexT = 0
    while True:
        data = data_cache.pop_front()
        if data == 0:
            # must before cv.wait
            if is_stop:
                break
            cv.acquire()
            if False == is_new:
                cv.wait()
            is_new = False
            cv.release()
        indexT = indexT + 1
        if indexT % 10000 == 0:
            logDS.info("thread_process2 %d %d %s" % (index, indexT, data))
    logDS.info("thread_process2 exit %d" % (index))
def thread_process2(index):
    logDS.info("begin %d" % index)
    global is_stop
    try:
        conn = stomp.Connection([('172.10.3.111', 61613)])
        conn.set_listener('', MyListener())
        #conn.set_listener('stats', StatsListener())
        #conn.set_listener('print', PrintingListener())
        conn.start()
        #conn.connect()
        user = '******' % index
        password = user
        conn.connect(user, password, wait=True)
        conn.subscribe('/topic/test', index)
        while False == is_stop:
            time.sleep(2)
        conn.disconnect()
    except Exception as ex:
        logDS.error('thread_process2 %s:%s' % (Exception, ex))
        exitDS()

    logDS.info("exit %d" % index)
예제 #14
0
def startService():
    thread_num = int(sys.argv[1])
    loop_time = int(sys.argv[2])
    thread_list = []
    for i in range(thread_num):
        thread = thread_process(i)
        thread.start()
        thread_list.append(thread)

    global is_stop
    global is_new
    global data_cache
    index = 0
    for i in range(loop_time):
        #time.sleep(2)
        data_cache.push_back("%d" % index)
        index = index + 1
        if index % 10000 == 0:
            logDS.info("xxxxxxxxxxxxxxxxxxxxxxxxxxx %d" % (index))
        continue
        cv.acquire()
        is_new = True
        if False:
            cv.notify_all()
        else:
            cv.notify()
        cv.release()

    logDS.info("xxxxxxxxxxxxxxxxxxxxxxxxxxx notify finished %d" % (index))

    is_stop = True
    cv.acquire()
    is_new = True
    cv.notify_all()
    cv.release()

    for t in thread_list:
        t.join()
예제 #15
0
def thread_process2(index):
    logDS.info("begin %d" % index)
    zk = KazooClient(hosts='172.10.3.111:2181', logger=logDS.logger)
    zk.start()
    node = "/my/lockpath"
    lock = zk.Lock(node, "my-identifier")
    with lock:  # blocks waiting for lock acquisition
        # do something with the lock
        logDS.info("get the lock %d" % index)
        global gindex
        if gindex != index:
            logDS.error("error xxxx %d %d" % (gindex, index))
        gindex = gindex + 1
        if index == 0:
            time.sleep(10)
    zk.stop()
    logDS.info("exit %d" % index)
예제 #16
0
 def on_disconnected(self):
     logDS.info('disconnected.')
예제 #17
0
 def on_message(self, headers, message):
     logDS.info('received a message "%s"' % message)
예제 #18
0
 def on_error(self, headers, message):
     logDS.info('received an error "%s"' % message)
예제 #19
0
def my_leader_function():
    logDS.info("my_leader_function")
    time.sleep(5)
예제 #20
0
def on_connect(client, userdata, flags, rc):
    logDS.info("Connected with result code " + str(rc))

    # Subscribing in on_connect() means that if we lose the connection and
    # reconnect then subscriptions will be renewed.
    client.subscribe("$SYS/#")
예제 #21
0
def on_message(client, userdata, msg):
    logDS.info(msg.topic + " " + str(msg.payload) + " userdata=" +
               str(userdata))
예제 #22
0
def thread_process2(index):
    for i in range(100000):
        logDS.info("thread_process2 %d %d" % (index, i))
        if i % 10000 == 0:
            logDS.show("thread_process2 %d %d" % (index, i), True)
예제 #23
0
def thread_process2(index):
    logDS.info("begin %d"%index)
    Container(HelloWorld("examples")).run()
    logDS.info("exit %d"%index)
예제 #24
0
def thread_process2(index):
    logDS.info("begin %d" % index)

    logDS.info("exit %d" % index)
예제 #25
0
def on_disconnect(client, userdata, rc):
    logDS.info("disconnected with result code " + str(rc))