Skip to content

Commit

Permalink
cleanup register and lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamid Zare committed Feb 23, 2017
1 parent 631bbef commit 19e0176
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 25 deletions.
12 changes: 0 additions & 12 deletions .TODO

This file was deleted.

7 changes: 0 additions & 7 deletions classes/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,20 @@ def __init__(self, knownEsAddress, strength ,topic):
self.strength = strength

def register(self,serverAddress):
# TODO address = lookup(self.topic)
self.socket.disconnect("tcp://" + self.knownEsAddress)
self.socket.connect("tcp://" + serverAddress)
heartbeatClient(self.pId,serverAddress).start()
msg = {'msgType':'publisherRegisterReq','pId':self.pId,'address':self.addr, 'topic':self.topic,'os':self.strength}
self.socket.send_string(json.dumps(msg))
self.socket.recv()
# self.socket.send_string("rp{}-{}, {}, {}".format(self.pId, self.addr,self.topic,self.strength))
logger.info('register request sent')

def lookup(self,key):
# TODO call to any known eventservice to findout where it should register.
# return: ES address (ip:port)
msg = {'msgType':'nodeLookup', 'key': key}
self.socket.send_string(json.dumps(msg))
designatedServer = self.socket.recv()
print('designated server:' , designatedServer)

self.register(designatedServer)
return designatedServer
# TODO go register to the designate



Expand Down
5 changes: 0 additions & 5 deletions classes/subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,19 @@ def __init__(self,esAddr = "127.0.0.1:5555"):
# logging.basicConfig(filename="log/{}.log".format('S' + self.addr),level=logging.DEBUG)

def register(self,topic, serverAddress):
# TODO address = lookup(topic)
self.socket.disconnect("tcp://" + getPubFromAddress(self.knownEsAddress))
self.socket.connect("tcp://" + serverAddress)
msg = {'msgType':'subscriberRegisterReq','sId':self.sId,'address':self.addr, 'topic':topic}
self.reqSocket.send_string(json.dumps(msg))
self.reqSocket.recv()
# self.reqSocket.send_string("rs{}-{}, {}".format(self.sId, self.addr,topic))
logger.info( 'register req sent')

def lookup(self,key):
# TODO call to any known eventservice to findout where it should register.
# return: ES address (ip:port)
msg = {'msgType':'nodeLookup', 'key': key}
self.reqSocket.send_string(json.dumps(msg))
designatedServer = self.reqSocket.recv()
print('designated server:' , designatedServer)
return designatedServer
# TODO go register to the designate

def subscribe(self, sFilter):
# any subscriber must use the SUBSCRIBE to set a subscription, i.e., tell the
Expand Down
3 changes: 2 additions & 1 deletion p1.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
topic = 'book'

p1 = Publisher(eventserver_address,owner_strength,topic)
p1.lookup(topic)
srvAddr = p1.lookup(topic)
p1.register(srvAddr)
# keep publishing
while True:
body = "{}".format(randint(0,9))
Expand Down

0 comments on commit 19e0176

Please sign in to comment.