本文整理匯總了Python中pymongo.monitoring.CommandListener方法的典型用法代碼示例。如果您正苦於以下問題:Python monitoring.CommandListener方法的具體用法?Python monitoring.CommandListener怎麽用?Python monitoring.CommandListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pymongo.monitoring
的用法示例。
在下文中一共展示了monitoring.CommandListener方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: register
# 需要導入模塊: from pymongo import monitoring [as 別名]
# 或者: from pymongo.monitoring import CommandListener [as 別名]
def register(listener):
"""Register a global event listener.
:Parameters:
- `listener`: A subclasses of :class:`CommandListener`,
:class:`ServerHeartbeatListener`, :class:`ServerListener`, or
:class:`TopologyListener`.
"""
if not isinstance(listener, _EventListener):
raise TypeError("Listeners for %s must be either a "
"CommandListener, ServerHeartbeatListener, "
"ServerListener, or TopologyListener." % (listener,))
if isinstance(listener, CommandListener):
_LISTENERS.command_listeners.append(listener)
if isinstance(listener, ServerHeartbeatListener):
_LISTENERS.server_heartbeat_listeners.append(listener)
if isinstance(listener, ServerListener):
_LISTENERS.server_listeners.append(listener)
if isinstance(listener, TopologyListener):
_LISTENERS.topology_listeners.append(listener)
# Note - to avoid bugs from forgetting which if these is all lowercase and
# which are camelCase, and at the same time avoid having to add a test for
# every command, use all lowercase here and test against command_name.lower().
示例2: __init__
# 需要導入模塊: from pymongo import monitoring [as 別名]
# 或者: from pymongo.monitoring import CommandListener [as 別名]
def __init__(self, listeners):
self.__command_listeners = _LISTENERS.command_listeners[:]
self.__server_listeners = _LISTENERS.server_listeners[:]
lst = _LISTENERS.server_heartbeat_listeners
self.__server_heartbeat_listeners = lst[:]
self.__topology_listeners = _LISTENERS.topology_listeners[:]
if listeners is not None:
for lst in listeners:
if isinstance(lst, CommandListener):
self.__command_listeners.append(lst)
if isinstance(lst, ServerListener):
self.__server_listeners.append(lst)
if isinstance(lst, ServerHeartbeatListener):
self.__server_heartbeat_listeners.append(lst)
if isinstance(lst, TopologyListener):
self.__topology_listeners.append(lst)
self.__enabled_for_commands = bool(self.__command_listeners)
self.__enabled_for_server = bool(self.__server_listeners)
self.__enabled_for_server_heartbeat = bool(
self.__server_heartbeat_listeners)
self.__enabled_for_topology = bool(self.__topology_listeners)
示例3: __init__
# 需要導入模塊: from pymongo import monitoring [as 別名]
# 或者: from pymongo.monitoring import CommandListener [as 別名]
def __init__(self, listeners):
self.__command_listeners = _LISTENERS.command_listeners[:]
self.__server_listeners = _LISTENERS.server_listeners[:]
lst = _LISTENERS.server_heartbeat_listeners
self.__server_heartbeat_listeners = lst[:]
self.__topology_listeners = _LISTENERS.topology_listeners[:]
self.__cmap_listeners = _LISTENERS.cmap_listeners[:]
if listeners is not None:
for lst in listeners:
if isinstance(lst, CommandListener):
self.__command_listeners.append(lst)
if isinstance(lst, ServerListener):
self.__server_listeners.append(lst)
if isinstance(lst, ServerHeartbeatListener):
self.__server_heartbeat_listeners.append(lst)
if isinstance(lst, TopologyListener):
self.__topology_listeners.append(lst)
if isinstance(lst, ConnectionPoolListener):
self.__cmap_listeners.append(lst)
self.__enabled_for_commands = bool(self.__command_listeners)
self.__enabled_for_server = bool(self.__server_listeners)
self.__enabled_for_server_heartbeat = bool(
self.__server_heartbeat_listeners)
self.__enabled_for_topology = bool(self.__topology_listeners)
self.__enabled_for_cmap = bool(self.__cmap_listeners)
示例4: _validate_event_listeners
# 需要導入模塊: from pymongo import monitoring [as 別名]
# 或者: from pymongo.monitoring import CommandListener [as 別名]
def _validate_event_listeners(option, listeners):
"""Validate event listeners"""
if not isinstance(listeners, abc.Sequence):
raise TypeError("%s must be a list or tuple" % (option,))
for listener in listeners:
if not isinstance(listener, _EventListener):
raise TypeError("Listeners for %s must be either a "
"CommandListener, ServerHeartbeatListener, "
"ServerListener, or TopologyListener." % (option,))
return listeners
示例5: enabled_for_commands
# 需要導入模塊: from pymongo import monitoring [as 別名]
# 或者: from pymongo.monitoring import CommandListener [as 別名]
def enabled_for_commands(self):
"""Are any CommandListener instances registered?"""
return self.__enabled_for_commands
示例6: _validate_event_listeners
# 需要導入模塊: from pymongo import monitoring [as 別名]
# 或者: from pymongo.monitoring import CommandListener [as 別名]
def _validate_event_listeners(option, listeners):
"""Validate event listeners"""
if not isinstance(listeners, Sequence):
raise TypeError("%s must be a list or tuple" % (option,))
for listener in listeners:
if not isinstance(listener, CommandListener):
raise TypeError("Only subclasses of "
"pymongo.monitoring.CommandListener are supported")
return listeners
示例7: register
# 需要導入模塊: from pymongo import monitoring [as 別名]
# 或者: from pymongo.monitoring import CommandListener [as 別名]
def register(listener):
"""Register a global event listener.
:Parameters:
- `listener`: A subclass of :class:`CommandListener`.
"""
_validate_event_listeners('listener', [listener])
_LISTENERS.command_listeners.append(listener)
示例8: _validate_event_listeners
# 需要導入模塊: from pymongo import monitoring [as 別名]
# 或者: from pymongo.monitoring import CommandListener [as 別名]
def _validate_event_listeners(option, listeners):
"""Validate event listeners"""
if not isinstance(listeners, abc.Sequence):
raise TypeError("%s must be a list or tuple" % (option,))
for listener in listeners:
if not isinstance(listener, _EventListener):
raise TypeError("Listeners for %s must be either a "
"CommandListener, ServerHeartbeatListener, "
"ServerListener, TopologyListener, or "
"ConnectionPoolListener." % (option,))
return listeners
示例9: register
# 需要導入模塊: from pymongo import monitoring [as 別名]
# 或者: from pymongo.monitoring import CommandListener [as 別名]
def register(listener):
"""Register a global event listener.
:Parameters:
- `listener`: A subclasses of :class:`CommandListener`,
:class:`ServerHeartbeatListener`, :class:`ServerListener`,
:class:`TopologyListener`, or :class:`ConnectionPoolListener`.
"""
if not isinstance(listener, _EventListener):
raise TypeError("Listeners for %s must be either a "
"CommandListener, ServerHeartbeatListener, "
"ServerListener, TopologyListener, or "
"ConnectionPoolListener." % (listener,))
if isinstance(listener, CommandListener):
_LISTENERS.command_listeners.append(listener)
if isinstance(listener, ServerHeartbeatListener):
_LISTENERS.server_heartbeat_listeners.append(listener)
if isinstance(listener, ServerListener):
_LISTENERS.server_listeners.append(listener)
if isinstance(listener, TopologyListener):
_LISTENERS.topology_listeners.append(listener)
if isinstance(listener, ConnectionPoolListener):
_LISTENERS.cmap_listeners.append(listener)
# Note - to avoid bugs from forgetting which if these is all lowercase and
# which are camelCase, and at the same time avoid having to add a test for
# every command, use all lowercase here and test against command_name.lower().
示例10: _validate_event_listeners
# 需要導入模塊: from pymongo import monitoring [as 別名]
# 或者: from pymongo.monitoring import CommandListener [as 別名]
def _validate_event_listeners(option, listeners):
"""Validate event listeners"""
if not isinstance(listeners, Sequence):
raise TypeError("%s must be a list or tuple" % (option,))
for listener in listeners:
if not isinstance(listener, _EventListener):
raise TypeError("Listeners for %s must be either a "
"CommandListener, ServerHeartbeatListener, "
"ServerListener, or TopologyListener." % (option,))
return listeners