Source code for crossbar.worker.types

#####################################################################################
#
#  Copyright (c) typedef int GmbH
#  SPDX-License-Identifier: EUPL-1.2
#
#####################################################################################

from datetime import datetime

from autobahn.util import utcstr


[docs] class RouterComponent(object): """ A application component hosted and running inside a router worker. """ def __init__(self, id, config, session): """ :param id: The component ID within the router instance. :type id: str :param config: The component's configuration. :type config: dict :param session: The component application session. :type session: obj (instance of ApplicationSession) """
[docs] self.id = id
[docs] self.config = config
[docs] self.session = session
[docs] self.created = datetime.utcnow()
[docs] def marshal(self): """ Marshal object information for use with WAMP calls/events. """ now = datetime.utcnow() return { "id": self.id, # 'started' is used by container-components; keeping it # for consistency in the public API "started": utcstr(self.created), "uptime": (now - self.created).total_seconds(), "config": self.config, }
[docs] class RouterRealm(object): """ A realm running in a router worker. """
[docs] CATEGORY_STANDALONE = "standalone"
[docs] CATEGORY_ETH = "eth"
[docs] CATEGORY_ENS = "ens"
[docs] CATEGORY_REVERSE_ENS = "reverse_ens"
[docs] VALID_CATEGORIES = [CATEGORY_STANDALONE, CATEGORY_ETH, CATEGORY_ENS, CATEGORY_REVERSE_ENS]
def __init__(self, controller, id, config, category=None, router=None, session=None): """ :param controller: The controller this router is running under. :type controller: object :param id: The realm ID within the router worker, identifying the router. :type id: str :param config: The realm configuration. :type config: dict :param category: The realm category (derived of the realm name), one of ``["standalone", "eth", "ens", "reverse_ens"]``. :type category: str :param router: The router (within the router worker) serving the realm. :type router: :class:`crossbar.router.router.Router` :param session: The realm service session. :type session: :class:`crossbar.router.service.RouterServiceAgent` """ assert category is None or category in RouterRealm.VALID_CATEGORIES # import here to dissolve circular dependency from crossbar.worker.rlink import RLinkManager
[docs] self.controller = controller
[docs] self.id = id
[docs] self.config = config
[docs] self.category = category or RouterRealm.CATEGORY_STANDALONE
# this is filled later (after construction) when the router has been started
[docs] self.router = router
# this is filled later (after construction) when the router service agent session has been started
[docs] self.session = session
# router-realm links ("router-to-router connections")
[docs] self.created = datetime.utcnow()
# Crossbar.io role run-time ID -> RouterRealmRole
[docs] self.roles = {}
# role WAMP name -> Crossbar.io role run-time ID
[docs] self.role_to_id = {}
[docs] def marshal(self): marshalled = { "id": self.id, "config": self.config, "category": self.category, "created": utcstr(self.created), "roles": [self.roles[role].marshal() for role in self.roles if self.roles], "has_router": self.router is not None, "has_service_session": self.session is not None, } rlinks = [] for link_id in self.rlink_manager.keys(): rlinks.append(self.rlink_manager[link_id].marshal()) marshalled["rlinks"] = rlinks return marshalled
[docs] class RouterRealmRole(object): """ A role in a realm running in a router worker. """ def __init__(self, id, config): """ :param id: The role ID within the realm. :type id: str :param config: The role configuration. :type config: dict """
[docs] self.id = id
[docs] self.config = config
[docs] def marshal(self): return { "id": self.id, "config": self.config, }