Example #1
0
 def __init__(self, actor_cls, init_params={}, initial_message=_EMPTY, nodeid=None, name=None, supervise='stop', keep_running=False):
     nodeid = 'localhost' + nodeid if nodeid and re.match(r'^:\d+$', nodeid) else nodeid
     if nodeid:
         _validate_nodeid(nodeid)
     self._init_params = init_params
     self._initial_message = initial_message
     self._actor_cls = actor_cls
     self._wrapper = None
     self._nodeid = nodeid
     self._name = name
     self._supervise = supervise
     self._keep_running = keep_running
Example #2
0
    def __init__(self, insock, outsock_factory, nodeid, reactor=reactor):
        if not nodeid or not isinstance(nodeid, str):  # pragma: no cover
            raise TypeError("The 'nodeid' argument to Hub must be a str")
        _validate_nodeid(nodeid)

        self.reactor = reactor

        self.nodeid = nodeid

        self.addr = "tcp://" + nodeid if nodeid else None

        # guarantees that terminations will not go unnoticed and that termination messages won't arrive out of order
        self.version = 0

        self.insock = insock
        insock.gotMultipart = self._got_message
        insock.addEndpoints([ZmqEndpoint("bind", _resolve_addr(self.addr))])

        self.outsock_factory = outsock_factory
        self.connections = {}

        self._next_heartbeat = reactor.callLater(self.HEARTBEAT_INTERVAL, self._manage_heartbeat_and_visibility)
        self._next_heartbeat_t = reactor.seconds() + self.HEARTBEAT_INTERVAL
Example #3
0
    def makeService(self, options):
        actor = options['actor']
        if not actor:
            fatal("error: no actor specified")
            sys.exit(1)

        try:
            module_path, actor_cls_name = actor.rsplit('.', 1)
        except ValueError:
            fatal("error: invalid path to actor %s" % actor)
            sys.exit(1)

        try:
            mod = __import__(module_path, globals(), locals(),
                             [actor_cls_name], -1)
        except ImportError:
            fatal("error: could not import %s:\n%s" %
                  (actor, traceback.format_exc()))
            sys.exit(1)

        try:
            actor_cls = getattr(mod, actor_cls_name)
        except AttributeError:
            fatal("error: no such actor %s" % actor)
            sys.exit(1)

        kwargs = {}

        if options['params'] is not _EMPTY:
            params = 'dict(%s)' % (options['params'], )
            try:
                params = eval(params)
            except:
                fatal("error: could not parse parameters")
                sys.exit(1)
            else:
                kwargs['init_params'] = params

        if options['message'] is not _EMPTY:
            initial_message = options['message']
            try:
                initial_message = eval(initial_message)
            except:
                fatal("error: could not parse initial message")
                sys.exit(1)
            else:
                kwargs['initial_message'] = initial_message

        if options['name']:
            name = options['name']
            if '/' in name:
                fatal("invalid name: names cannot contain slashes")
                sys.exit(1)
            else:
                kwargs['name'] = name

        if options['remoting']:
            nodeid = options['remoting']
            try:
                _validate_nodeid(nodeid)
            except TypeError:
                fatal("invalid node ID")
                sys.exit(1)
            else:
                kwargs['nodeid'] = nodeid

        kwargs['keep_running'] = options['keeprunning']

        m = MultiService()
        actor_runner = ActorRunner(actor_cls, **kwargs)
        actor_runner.setServiceParent(m)

        # manhole

        if options['remotedebugging']:
            port = options['remotedebuggingport']
            try:
                port = int(port)
            except ValueError:
                fatal("Invalid port specified: %r" % port)
                sys.exit(1)

            username = options['remotedebuggingusername']
            password = options['remotedebuggingpassword']

            manhole = self.make_manhole_server(port, username, password)
            manhole.setServiceParent(m)

        return m
Example #4
0
    def makeService(self, options):
        actor = options['actor']
        if not actor:
            fatal("error: no actor specified")
            sys.exit(1)

        try:
            module_path, actor_cls_name = actor.rsplit('.', 1)
        except ValueError:
            fatal("error: invalid path to actor %s" % actor)
            sys.exit(1)

        try:
            mod = __import__(module_path, globals(), locals(), [actor_cls_name], -1)
        except ImportError:
            fatal("error: could not import %s:\n%s" % (actor, traceback.format_exc()))
            sys.exit(1)

        try:
            actor_cls = getattr(mod, actor_cls_name)
        except AttributeError:
            fatal("error: no such actor %s" % actor)
            sys.exit(1)

        kwargs = {}

        if options['params'] is not _EMPTY:
            params = 'dict(%s)' % (options['params'],)
            try:
                params = eval(params)
            except:
                fatal("error: could not parse parameters")
                sys.exit(1)
            else:
                kwargs['init_params'] = params

        if options['message'] is not _EMPTY:
            initial_message = options['message']
            try:
                initial_message = eval(initial_message)
            except:
                fatal("error: could not parse initial message")
                sys.exit(1)
            else:
                kwargs['initial_message'] = initial_message

        if options['name']:
            name = options['name']
            if '/' in name:
                fatal("invalid name: names cannot contain slashes")
                sys.exit(1)
            else:
                kwargs['name'] = name

        if options['remoting']:
            nodeid = options['remoting']
            try:
                _validate_nodeid(nodeid)
            except TypeError:
                fatal("invalid node ID")
                sys.exit(1)
            else:
                kwargs['nodeid'] = nodeid

        kwargs['keep_running'] = options['keeprunning']

        m = MultiService()
        actor_runner = ActorRunner(actor_cls, **kwargs)
        actor_runner.setServiceParent(m)

        # manhole

        if options['remotedebugging']:
            port = options['remotedebuggingport']
            try:
                port = int(port)
            except ValueError:
                fatal("Invalid port specified: %r" % port)
                sys.exit(1)

            username = options['remotedebuggingusername']
            password = options['remotedebuggingpassword']

            manhole = self.make_manhole_server(port, username, password)
            manhole.setServiceParent(m)

        return m
Example #5
0
def _assert_valid_nodeid(nodeid):  # pragma: no cover
    try:
        _validate_nodeid(nodeid)
    except ValueError as e:
        raise AssertionError(e.message)