8 from Queue import Queue
10 from load_balancer.random_lb import RandomLoadBalancer
11 # Located in the parent directory; execute from that location or put it in PYTHONPATH
16 class LBWorker(threading.Thread):
18 Load Balancing Worker: chooses a CIS where the request should be forwarded
19 or broadcasts the requests to all CIS machines if required.
22 def __init__(self, id):
24 Initialize Load Balancing Worker.
27 threading.Thread.__init__(self, name = 'LBWorker%02d' % id)
32 job = Server.queue.get()
34 print '%s is working at %s...' % (self.name, repr(job))
37 Server.queue.task_done()
42 def POST(self, request):
44 Server.queue.put( (request, web.data()) )
48 if __name__ == '__main__':
50 Server.queue = Queue()
54 for i in range(0, config.JOB_THREADS_COUNT):
55 lb_worker = RandomLoadBalancer(i, Server.queue)
56 lb_worker.daemon = True
58 lb_workers.append(lb_worker)
61 urls = ('/(.*)', 'Server')
62 app = web.application(urls, globals())