Example #1
0
# -*- coding: utf-8 -*-
import time
import glob
import sys
import os
import threading
import uuid

#import logging
#logging.basicConfig()

import logDS

logDS.init('openwire')
is_stop = False
gindex = 0


def thread_process2(index):
    logDS.info("begin %d" % index)

    logDS.info("exit %d" % index)


class thread_process(threading.Thread):
    def __init__(self, index):
        threading.Thread.__init__(self)
        self.index = index

    def run(self):
        thread_process2(self.index)
# -*- coding: utf-8 -*-
import time
import glob
import sys
import os
import threading
import uuid
from kazoo.client import KazooClient
#import logging
#logging.basicConfig()

import logDS
logDS.init('logDS_%s.log' % uuid.uuid4())
is_stop = False
gindex = 0


def my_leader_function():
    logDS.info("my_leader_function")
    time.sleep(5)


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()
Example #3
0
# -*- coding: utf-8 -*-
import time
import glob
import sys
import os
import threading
import uuid
import stomp
#import logging
#logging.basicConfig()

import logDS

logDS.init('activemq')
is_stop = False
gindex = 0

class MyListener(stomp.ConnectionListener):
    def on_error(self, headers, message):
        logDS.info('received an error "%s"' % message)
    def on_message(self, headers, message):
        logDS.info('received a message "%s"' % message)
        #print("headers",headers)
    def on_disconnected(self):
        logDS.info('disconnected.')

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())
Example #4
0
# -*- coding: utf-8 -*-
import time
import glob
import sys
import os
import threading
import uuid
import paho.mqtt.client as mqtt
#import logging
#logging.basicConfig()

import logDS

logDS.init(uuid.uuid4())
is_stop = False
gindex = 0


# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
    logDS.info(msg.topic + " " + str(msg.payload) + " userdata=" +
               str(userdata))
    #print(type(msg),type(msg.payload))


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/#")
# -*- coding: utf-8 -*-
import time
import glob
import sys
import os
import threading
import uuid

import logDS
logDS.init('%s' % uuid.uuid4())
is_stop = False
gindex = 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)


class thread_process(threading.Thread):
    def __init__(self, index):
        threading.Thread.__init__(self)
        self.index = index

    def run(self):
        thread_process2(self.index)


def startService():
Example #6
0
import time
import glob
import sys
import os
import threading
import uuid
import optparse
from proton import Message, Url
from proton.handlers import MessagingHandler
from proton.reactor import Container

import logDS

logDS.init('amqp')
is_stop = False
gindex = 0


class Server(MessagingHandler):
    def __init__(self, url, address, index):
        super(Server, self).__init__()
        self.url = url
        self.address = address
        self.index = index

    def on_start(self, event):
        print("Listening on", self.url, self.index)
        self.container = event.container
        self.conn = event.container.connect(self.url)
        self.receiver = event.container.create_receiver(
            self.conn, self.address)
Example #7
0
# -*- coding: utf-8 -*-
import time
import glob
import sys
import os
import threading
import uuid
import stomp
#import logging
#logging.basicConfig()

import logDS

logDS.init('activemq.log')
is_stop = False
gindex = 0


class MyListener(stomp.ConnectionListener):
    def on_error(self, headers, message):
        print('received an error "%s"' % message)
    def on_message(self, headers, message):
        print('received a message "%s"' % message)

class StatsListener(stomp.ConnectionListener):
    def on_error(self, headers, message):
        print('StatsListener received an error "%s"' % message)
    def on_message(self, headers, message):
        print('StatsListener received a message "%s"' % message)

class PrintingListener(stomp.ConnectionListener):
Example #8
0
# -*- coding: utf-8 -*-
import time
import glob
import sys
import os
import threading
import uuid
import paho.mqtt.client as mqtt
#import logging
#logging.basicConfig()

import logDS

logDS.init('mqtt')
is_stop = False
gindex = 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/#")


# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
    logDS.info(msg.topic + " " + str(msg.payload))