Example #1
0
def main():
    zk = ZooKeeper()

    # create the root node used for master election
    if not zk.exists('/election'):
        zk.create('/election')

    print 'Starting 10 agents ...'
    agents = [Agent(id) for id in range(0, 15)]

    map(Agent.start, agents)
    map(Agent.join, agents)

    zk.delete('/election')
Example #2
0
def main():
    zk = ZooKeeper()
    zk.start_session(expire=60)

    if not zk.exists('/queue'):
        zk.create('/queue')
    q = Queue('/queue', zk)

    print 'Pushing to queue 1 ... 5'
    map(q.put, [1, 2, 3, 4, 5])

    print 'Extracting ...'
    while True:
        el = q.fetch()
        if el is None:
            break
        print el

    zk.close_session()
    zk.delete('/queue')

    print 'Done.'
Example #3
0
 def __init__(self, id):
     super(Agent, self).__init__()
     self.zk = ZooKeeper()
     self.id = id
Example #4
0
 def setUp(self):
     self.zk = ZooKeeper(self.BASE_URI)