Skip to content
Permalink
Browse files
重构方法名称
  • Loading branch information
JoeCao committed Apr 12, 2015
1 parent 94584ee commit 99ed0ec819e1468af8454320123be3881c58e8a6
Showing 3 changed files with 6 additions and 6 deletions.
@@ -10,7 +10,7 @@


class Registry(object):
def add_provider_listener(self, provide_name):
def subscribe(self, provide_name):
"""
监听注册中心的服务上下线
:param provide_name: 类似com.ofpay.demo.api.UserProvider这样的服务名
@@ -51,11 +51,11 @@ def __state_listener(self, state):
self.__connect_state = state
elif state == KazooState.SUSPENDED:
# Handle being disconnected from Zookeeper
print 'disconnect from zookeeper'
# print 'disconnect from zookeeper'
self.__connect_state = state
else:
# Handle being connected/reconnected to Zookeeper
print 'connected'
# print 'connected'
self.__connect_state = state

def __event_listener(self, event):
@@ -106,7 +106,7 @@ def __do_event(self, event):
children = self.__zk.get_children(event.path, watch=self.__event_listener)
self.__handler_nodes(provide_name, children)

def add_provider_listener(self, interface, **kwargs):
def subscribe(self, interface, **kwargs):
"""
监听注册中心的服务上下线
:param interface: 类似com.ofpay.demo.api.UserProvider这样的服务名
@@ -29,7 +29,7 @@ def __init__(self, interface, registry, **kwargs):
self.registry = registry
self.group = kwargs.get('group', '')
self.version = kwargs.get('version', '')
self.registry.add_provider_listener(interface)
self.registry.subscribe(interface)

def call(self, method, *args, **kwargs):
provides = self.registry.get_provides(self.interface, {}, version=self.version, group=self.group)
@@ -4,5 +4,5 @@

if __name__ == '__main__':
registry = ZookeeperRegistry('172.19.65.33:2181')
registry.add_provider_listener('com.ofpay.demo.api.UserProvider')
registry.subscribe('com.ofpay.demo.api.UserProvider')
print registry.get_provides('com.ofpay.demo.api.UserProvider')

0 comments on commit 99ed0ec

Please sign in to comment.