Beispiel #1
0
 def __init__(self, addr, incoming_port, max_proc=10, user="******"):
     self.max_processors = max_proc
     self.addr = addr
     self.name = addr + str(incoming_port)
     self.incoming_port = incoming_port
     self.context = zmq.Context()
     self.proc_queue = Queue()
     from protocol import QuiltProtocol
     from models import QuiltUser
     self.user = QuiltUser(user, user)
     self.protocol = QuiltProtocol(self.name, self.addr, self.incoming_port,
                                   self.user)
     self.incoming = IncomingThread(self.incoming_port, self.proc_queue)
     self.incoming.setDaemon(True)
     for i in range(self.max_processors):
         t = ProcessorThread(self.proc_queue, self.protocol)
         t.start()
Beispiel #2
0
 def __init__(self, addr, incoming_port, max_proc=10, user="******"):
     self.max_processors = max_proc
     self.addr = addr
     self.name = addr + str(incoming_port)
     self.incoming_port = incoming_port
     self.context = zmq.Context()
     self.proc_queue = Queue()
     from protocol import QuiltProtocol
     from models import QuiltUser
     self.user = QuiltUser(user, user)
     self.protocol = QuiltProtocol(self.name, self.addr, self.incoming_port, self.user)
     self.incoming = IncomingThread(self.incoming_port, self.proc_queue)
     self.incoming.setDaemon(True)
     for i in range(self.max_processors):
         t = ProcessorThread(self.proc_queue, self.protocol)
         t.start()
Beispiel #3
0
class QuiltServer(object):
    """
    The main server class for Quilt, spins up threads for incoming connections
    and processing data, and then runs the user interface code

    :type addr: str
    :param addr: address of this server

    :type incoming_port: int
    :param incoming_port: port for incoming connects

    :type: max_proc: int
    :param: max_proc: maximum number of processor threads to use
    """

    def __init__(self, addr, incoming_port, max_proc=10, user="******"):
        self.max_processors = max_proc
        self.addr = addr
        self.name = addr + str(incoming_port)
        self.incoming_port = incoming_port
        self.context = zmq.Context()
        self.proc_queue = Queue()
        from protocol import QuiltProtocol
        from models import QuiltUser
        self.user = QuiltUser(user, user)
        self.protocol = QuiltProtocol(self.name, self.addr, self.incoming_port, self.user)
        self.incoming = IncomingThread(self.incoming_port, self.proc_queue)
        self.incoming.setDaemon(True)
        for i in range(self.max_processors):
            t = ProcessorThread(self.proc_queue, self.protocol)
            t.start()

    def start(self):
        """Start the server and don't do anything else"""
        self.incoming.start()

    def start_with_ui(self):
        """
        Start the server and display and user interface
        """
        self.incoming.start()
        print "Welcome to Quilt"
        while True:
            user_in = raw_input(">>").split(" ")
            cmd = user_in[0]
            if cmd == "/connect":
                if len(user_in) != 3:
                    print "/connect <address> <port>"
                    continue
                self.protocol.connect_to_server(user_in[1], user_in[2])
            elif cmd == "/exit":
                self.terminate_threads()
                break
            else:
                self.protocol.send_msg(user_in[0], " ".join(user_in[1:]))

    def terminate_threads(self):
        """
        Terminates all threads except incoming threads which are auto killed on exit
        """
        for server in self.protocol.outgoing_queues:
            self.protocol.outgoing_queues[server].put(None)
        for i in range(self.max_processors):
            self.proc_queue.put(None)
Beispiel #4
0
class QuiltServer(object):
    """
    The main server class for Quilt, spins up threads for incoming connections
    and processing data, and then runs the user interface code

    :type addr: str
    :param addr: address of this server

    :type incoming_port: int
    :param incoming_port: port for incoming connects

    :type: max_proc: int
    :param: max_proc: maximum number of processor threads to use
    """
    def __init__(self, addr, incoming_port, max_proc=10, user="******"):
        self.max_processors = max_proc
        self.addr = addr
        self.name = addr + str(incoming_port)
        self.incoming_port = incoming_port
        self.context = zmq.Context()
        self.proc_queue = Queue()
        from protocol import QuiltProtocol
        from models import QuiltUser
        self.user = QuiltUser(user, user)
        self.protocol = QuiltProtocol(self.name, self.addr, self.incoming_port,
                                      self.user)
        self.incoming = IncomingThread(self.incoming_port, self.proc_queue)
        self.incoming.setDaemon(True)
        for i in range(self.max_processors):
            t = ProcessorThread(self.proc_queue, self.protocol)
            t.start()

    def start(self):
        """Start the server and don't do anything else"""
        self.incoming.start()

    def start_with_ui(self):
        """
        Start the server and display and user interface
        """
        self.incoming.start()
        print "Welcome to Quilt"
        while True:
            user_in = raw_input(">>").split(" ")
            cmd = user_in[0]
            if cmd == "/connect":
                if len(user_in) != 3:
                    print "/connect <address> <port>"
                    continue
                self.protocol.connect_to_server(user_in[1], user_in[2])
            elif cmd == "/exit":
                self.terminate_threads()
                break
            else:
                self.protocol.send_msg(user_in[0], " ".join(user_in[1:]))

    def terminate_threads(self):
        """
        Terminates all threads except incoming threads which are auto killed on exit
        """
        for server in self.protocol.outgoing_queues:
            self.protocol.outgoing_queues[server].put(None)
        for i in range(self.max_processors):
            self.proc_queue.put(None)