# Path: hurricane/utils.py
# def import_string(import_name, silent=False):
#     """Imports an object based on a string.  This is useful if you want to
#     use import paths as endpoints or something similar.  An import path can
#     be specified either in dotted notation (``xml.sax.saxutils.escape``)
#     or with a colon as object delimiter (``xml.sax.saxutils:escape``).
# 
#     If `silent` is True the return value will be `None` if the import fails.
# 
#     :param import_name: the dotted name for the object to import.
#     :param silent: if set to `True` import errors are ignored and
#                    `None` is returned instead.
#     :return: imported object
#     """
#     try:
#         if ':' in import_name:
#             module, obj = import_name.split(':', 1)
#         elif '.' in import_name:
#             module, obj = import_name.rsplit('.', 1)
#         else:
#             return __import__(import_name)
#         return getattr(__import__(module, None, None, [obj]), obj)
#     except (ImportError, AttributeError):
#         if not silent:
#             raise


import multiprocessing
from hurricane.utils import import_string



class BaseSubscriptionManager(object):
    def __init__(self, settings, handler):
        self.settings = settings
        self.handler = handler

    def receive(self, message):
        self.handler.receive(message)


class BaseApplicationManager(object):
    def __init__(self, settings, publisher):
        self.publisher = publisher
        self.settings = settings
        self.handler_classes = [import_string(handler) for handler in settings.HANDLERS]
        self.handlers = [obj(settings, self) for obj in self.handler_classes]
    
    def subscribe(self, channel, handler):
        raise NotImplementedError
    
    def unsubscribe(self, channel, handler):
        # TODO: Implement this in the subclasses
        raise NotImplementedError
    
    def run(self):
        for handler in self.handlers:

# Path: hurricane/utils.py
# def import_string(import_name, silent=False):
#     """Imports an object based on a string.  This is useful if you want to
#     use import paths as endpoints or something similar.  An import path can
#     be specified either in dotted notation (``xml.sax.saxutils.escape``)
#     or with a colon as object delimiter (``xml.sax.saxutils:escape``).
# 
#     If `silent` is True the return value will be `None` if the import fails.
# 
#     :param import_name: the dotted name for the object to import.
#     :param silent: if set to `True` import errors are ignored and
#                    `None` is returned instead.
#     :return: imported object
#     """
#     try:
#         if ':' in import_name:
#             module, obj = import_name.split(':', 1)
#         elif '.' in import_name:
#             module, obj = import_name.rsplit('.', 1)
#         else:
#             return __import__(import_name)
#         return getattr(__import__(module, None, None, [obj]), obj)
#     except (ImportError, AttributeError):
#         if not silent:
#             raise


# Path: hurricane/managers/base.py
import multiprocessing
from hurricane.utils import import_string




class BaseSubscriptionManager(object):
    def __init__(self, settings, handler):
        self.settings = settings
        self.handler = handler

    def receive(self, message):
        self.handler.receive(message)


class BaseApplicationManager(object):
    def __init__(self, settings, publisher):
        self.publisher = publisher
        self.settings = settings
        self.handler_classes = [import_string(handler) for handler in settings.HANDLERS]
        self.handlers = [obj(settings, self) for obj in self.handler_classes]
    
    def subscribe(self, channel, handler):
        raise NotImplementedError
    
    def unsubscribe(self, channel, handler):
        # TODO: Implement this in the subclasses
        raise NotImplementedError
    
    def run(self):
        for handler in self.handlers:

            multiprocessing.Process(target=handler.run_base).start()