Source code for araldo.endpoints
""" Communication endpoints
"""
import logging
from abc import ABCMeta, abstractmethod
import gevent
[docs]class PluginException(Exception):
""" An end-point related exception
"""
def __init__(self, msg):
Exception.__init__(self, msg)
[docs]class EndPointBase(gevent.Greenlet): # pylint: disable-msg=R0904
""" Abstract base class for Araldo endpoints
Concrete classes must implement Greenlet's _run method to
process incoming messages and to enque them into gevent_queue
"""
__meta__ = ABCMeta
def __init__(self, **kwargs):
self._name = kwargs["name"]
self._logger = logging.getLogger("araldo")
self._plugin_manager = kwargs["plugin_manager"]
self._config = kwargs["config"]
#import pdb; pdb.set_trace()
marshalling_name = self._config.get("marshalling", "marshal-json")
self._marshalling = self._get_marshalling(marshalling_name)
self._gevent_queue = kwargs["gevent_queue"]
gevent.Greenlet.__init__(self)
def _get_marshalling(self, marshalling_name):
""" Retrieve plugin instances for marshaller
:return: marshalling-Object
:rtype: araldo.marshalling.Marshaller
"""
self._logger.debug("Obtaining marshaller '%s'" % marshalling_name)
plugin_instances = self._plugin_manager.plugin_instances()
marshalling_instances = plugin_instances["araldo.marshalling"]
#self._logger.debug("### %s" % marshalling_instances)
return marshalling_instances[marshalling_name]
@abstractmethod
[docs] def name(self):
""" Short, human-readable name of plugin
"""
return self._name
@abstractmethod
[docs] def marshalling(self):
""" Short, human-readable name marshalling used
"""
return self._marshalling
@abstractmethod
[docs] def plugin_manager(self):
""" plugin manager for loading other plugins
"""
return self._plugin_manager
@abstractmethod
[docs] def config(self):
""" Plugin configuration sub-object
"""
return self._config
@property
[docs] def gevent_queue(self):
""" gevent target queue
"""
return self._gevent_queue
[docs] def description(self):
""" Textual description of plugin
"""
return "endpoint '%s'" % self.name()
def __repr__(self):
return ("EndPoint(name=%s,id=%s)"
% (self.name(), id(self)))
@abstractmethod
[docs] def send(self, message):
""" Send message to backend
"""