本文整理汇总了Python中autobahn.twisted.wamp.RouterSessionFactory类的典型用法代码示例。如果您正苦于以下问题:Python RouterSessionFactory类的具体用法?Python RouterSessionFactory怎么用?Python RouterSessionFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RouterSessionFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
class WampServer:
def __init__(self, debug = '0'):
self.debug = debug
log.startLogging(sys.stdout)
## we use an Autobahn utility to install the "best" available Twisted reactor
##
from autobahn.twisted.choosereactor import install_reactor
self.reactor = install_reactor()
print("Running on reactor {}".format(self.reactor))
## create a WAMP router factory
##
from autobahn.twisted.wamp import RouterFactory
self.router_factory = RouterFactory()
## create a WAMP router session factory
##
from autobahn.twisted.wamp import RouterSessionFactory
self.session_factory = RouterSessionFactory(self.router_factory)
## Add embedded WAMP application sessions to the router
##
from core.rpc import MyBackendComponent
component_config = types.ComponentConfig(realm = "realm1")
component_session = MyBackendComponent(component_config)
self.session_factory.add(component_session)
## create a WAMP-over-WebSocket transport server factory
##
from autobahn.twisted.websocket import WampWebSocketServerFactory
self.transport_factory = WampWebSocketServerFactory(self.session_factory, debug = self.debug)
self.transport_factory.setProtocolOptions(failByDrop = False)
def run(self, config):
## start the server from an endpoint
##
enpoint = 'tcp:' + config.PORT
print enpoint
self.server = serverFromString(self.reactor, enpoint)
self.server.listen(self.transport_factory)
## now enter the Twisted reactor loop
##
self.reactor.run()
示例2: start
def start(self):
"""
Starts this node. This will start a node controller
and then spawn new worker processes as needed.
The node controller will watch spawned processes,
communicate via stdio with the worker, and start
and restart the worker processes as needed.
"""
## the node controller singleton WAMP application session
##
self._node_controller_session = NodeControllerSession(self)
## router and factory that creates router sessions
##
self._router_factory = RouterFactory()
self._router_session_factory = RouterSessionFactory(self._router_factory)
## add the node controller singleton session to the router
##
self._router_session_factory.add(self._node_controller_session)
if True:
## create a WAMP-over-WebSocket transport server factory
##
from autobahn.twisted.websocket import WampWebSocketServerFactory
from twisted.internet.endpoints import serverFromString
self._router_server_transport_factory = WampWebSocketServerFactory(self._router_session_factory, "ws://localhost:9000", debug = False)
self._router_server_transport_factory.setProtocolOptions(failByDrop = False)
## start the WebSocket server from an endpoint
##
self._router_server = serverFromString(self._reactor, "tcp:9000")
self._router_server.listen(self._router_server_transport_factory)
## factory that creates router session transports. these are for clients
## that talk WAMP-WebSocket over pipes with spawned worker processes and
## for any uplink session to a management service
##
self._router_client_transport_factory = WampWebSocketClientFactory(self._router_session_factory, "ws://localhost", debug = False)
self._router_client_transport_factory.setProtocolOptions(failByDrop = False)
if False:
management_session_factory = ApplicationSessionFactory()
management_session_factory.session = NodeManagementSession
management_session_factory.node_controller_session = node_controller_session
management_transport_factory = WampWebSocketClientFactory(management_session_factory, "ws://127.0.0.1:7000")
management_transport_factory.setProtocolOptions(failByDrop = False)
management_client = clientFromString(self._reactor, "tcp:127.0.0.1:7000")
management_client.connect(management_transport_factory)
## startup the node from configuration file
##
self._node_controller_session.run_node_config(self._config)
示例3: setUp
def setUp(self):
"""
Setup router and router session factories.
"""
if USE_ASYNCIO:
self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(self.loop)
self.router_factory = RouterFactory()
self.session_factory = RouterSessionFactory(self.router_factory)
示例4: start_from_config
def start_from_config(self, config):
controller_config = config.get('controller', {})
controller_options = controller_config.get('options', {})
controller_title = controller_options.get('title', 'crossbar-controller')
try:
import setproctitle
except ImportError:
log.msg("Warning, could not set process title (setproctitle not installed)")
else:
setproctitle.setproctitle(controller_title)
## the node's name (must be unique within the management realm)
if 'id' in controller_config:
self._node_id = controller_config['id']
else:
self._node_id = socket.gethostname()
## the node's management realm
self._realm = controller_config.get('realm', 'crossbar')
## the node controller singleton WAMP application session
##
#session_config = ComponentConfig(realm = options.realm, extra = options)
self._controller = NodeControllerSession(self)
## router and factory that creates router sessions
##
self._router_factory = RouterFactory(
options = wamp.types.RouterOptions(uri_check = wamp.types.RouterOptions.URI_CHECK_LOOSE),
debug = False)
self._router_session_factory = RouterSessionFactory(self._router_factory)
## add the node controller singleton session to the router
##
self._router_session_factory.add(self._controller)
## Detect WAMPlets
##
wamplets = self._controller._get_wamplets()
if len(wamplets) > 0:
log.msg("Detected {} WAMPlets in environment:".format(len(wamplets)))
for wpl in wamplets:
log.msg("WAMPlet {}.{}".format(wpl['dist'], wpl['name']))
else:
log.msg("No WAMPlets detected in enviroment.")
self.run_node_config(config)
示例5: start
def start(self):
"""
Starts this node. This will start a node controller
and then spawn new worker processes as needed.
The node controller will watch spawned processes,
communicate via stdio with the worker, and start
and restart the worker processes as needed.
"""
try:
import setproctitle
except ImportError:
log.msg("Warning, could not set process title (setproctitle not installed)")
else:
setproctitle.setproctitle("Crossbar.io Node Controller")
## the node controller singleton WAMP application session
##
self._node_controller_session = NodeControllerSession(self)
## router and factory that creates router sessions
##
self._router_factory = RouterFactory(
options = types.RouterOptions(uri_check = types.RouterOptions.URI_CHECK_LOOSE),
debug = False)
self._router_session_factory = RouterSessionFactory(self._router_factory)
## add the node controller singleton session to the router
##
self._router_session_factory.add(self._node_controller_session)
## Detect WAMPlets
##
for wpl in self._node_controller_session.list_wamplets():
log.msg("WAMPlet detected: {}.{}".format(wpl['dist'], wpl['name']))
yield self.start_from_local_config(configfile = os.path.join(self._cbdir, 'config.json'))
self.start_local_management_transport(endpoint_descriptor = "tcp:9000")
示例6: install_reactor
from autobahn.twisted.choosereactor import install_reactor
reactor = install_reactor()
if args.debug:
print("Running on reactor {}".format(reactor))
## create a WAMP router factory
##
from autobahn.wamp.router import RouterFactory
router_factory = RouterFactory()
## create a WAMP router session factory
##
from autobahn.twisted.wamp import RouterSessionFactory
session_factory = RouterSessionFactory(router_factory)
## if asked to start an embedded application component ..
##
if args.component:
## dynamically load the application component ..
##
import importlib
c = args.component.split('.')
mod, klass = '.'.join(c[:-1]), c[-1]
app = importlib.import_module(mod)
SessionKlass = getattr(app, klass)
## .. and create and add an WAMP application session to
## run next to the router
示例7: install_reactor
# we use an Autobahn utility to install the "best" available Twisted reactor
##
from autobahn.twisted.choosereactor import install_reactor
reactor = install_reactor()
if args.debug:
print("Running on reactor {}".format(reactor))
# create a WAMP router factory
##
from autobahn.twisted.wamp import RouterFactory
router_factory = RouterFactory()
# create a WAMP router session factory
##
from autobahn.twisted.wamp import RouterSessionFactory
session_factory = RouterSessionFactory(router_factory)
session_factory.session = MyRouterSession
# start an embedded application component ..
##
component_config = types.ComponentConfig(realm="realm1")
component_session = TimeService(component_config)
session_factory.add(component_session)
# create a WAMP-over-WebSocket transport server factory
##
from autobahn.twisted.websocket import WampWebSocketServerFactory
transport_factory = WampWebSocketServerFactory(session_factory, args.wsurl, debug=False, debug_wamp=args.debug)
transport_factory.protocol = ServerProtocol
transport_factory._cookies = {}
示例8: install_reactor
from autobahn.twisted.choosereactor import install_reactor
reactor = install_reactor()
print("Running on reactor {}".format(reactor))
## create a WAMP router factory
##
from autobahn.wamp.router import RouterFactory
router_factory = RouterFactory()
## create a WAMP router session factory
##
from autobahn.twisted.wamp import RouterSessionFactory
session_factory = RouterSessionFactory(router_factory)
## [ ... ... ]
session_factory.add(PubSubComponent())
## create a WAMP-over-WebSocket transport server factory
##
from autobahn.twisted.websocket import WampWebSocketServerFactory
# NB: args.wsurl MUST NOT INCLUDE a path; hence it is not really a URL; all it supports is protocol (which must be ws or wss), hostname, and port. anything after that gives a mysterious
# File "/usr/lib/python2.7/site-packages/autobahn/websocket/protocol.py", line 3383, in setSessionParameters
# raise Exception("path specified for server WebSocket URL")
transport_factory = WampWebSocketServerFactory(session_factory, args.wsurl, debug=True)
transport_factory.setProtocolOptions(failByDrop=False)
## start the WebSocket server from an endpoint
示例9: install_reactor
from autobahn.twisted.choosereactor import install_reactor
reactor = install_reactor()
if args.debug:
print("Running on reactor {}".format(reactor))
## create a WAMP router factory
##
from autobahn.wamp.router import RouterFactory
router_factory = RouterFactory()
## create a WAMP router session factory
##
from autobahn.twisted.wamp import RouterSessionFactory
session_factory = RouterSessionFactory(router_factory)
session_factory.session = MyRouterSession
## start an embedded application component ..
##
session_factory.add(TimeService())
## create a WAMP-over-WebSocket transport server factory
##
from autobahn.twisted.websocket import WampWebSocketServerFactory
transport_factory = WampWebSocketServerFactory(session_factory, args.wsurl, debug_wamp = args.debug)
transport_factory.protocol = ServerProtocol
transport_factory._cookies = {}
示例10: install_reactor
from autobahn.twisted.choosereactor import install_reactor
reactor = install_reactor()
if args.debug:
print("Running on reactor {}".format(reactor))
## create a WAMP router factory
##
from autobahn.twisted.wamp import RouterFactory
router_factory = RouterFactory()
## create a WAMP router session factory
##
from autobahn.twisted.wamp import RouterSessionFactory
session_factory = RouterSessionFactory(router_factory)
## .. and create and add an WAMP application session to
## run next to the router
##
from autobahn.wamp import types
config = types.ComponentConfig(realm = args.realm,
extra = {
'caselog': 'case1.log'
}
)
if False:
示例11: test_minimal
def test_minimal(self):
embedded_components, client_components = [], [Case2_Backend, Case2_Frontend]
## create a WAMP router factory
##
router_factory = RouterFactory()
## create a WAMP router session factory
##
session_factory = RouterSessionFactory(router_factory)
## .. and create and add an WAMP application session to
## run next to the router
##
config = types.ComponentConfig(realm = self.realm,
extra = {
'caselog': 'case1.log'
}
)
try:
log = io.open('caselog.log', 'w')
except Exception as e:
print(e)
return
# log = io.open(config.extra['caselog'], 'w')
config.log = log
config.dlog = []
config.components = []
config.all_done = []
for C in embedded_components:
one_done = Deferred()
config.all_done.append(one_done)
c = C(config, one_done)
config.components.append(c)
session_factory.add(c)
if self.transport == "websocket":
## create a WAMP-over-WebSocket transport server factory
##
transport_factory = WampWebSocketServerFactory(session_factory, debug_wamp = self.debug)
transport_factory.setProtocolOptions(failByDrop = False, openHandshakeTimeout = 0, closeHandshakeTimeout = 0)
elif self.transport in ['rawsocket-json', 'rawsocket-msgpack']:
## create a WAMP-over-RawSocket transport server factory
##
if self.transport == 'rawsocket-msgpack':
serializer = MsgPackSerializer()
elif self.transport == 'rawsocket-json':
serializer = JsonSerializer()
else:
raise Exception("should not arrive here")
transport_factory = WampRawSocketServerFactory(session_factory, serializer, debug = self.debug)
else:
raise Exception("should not arrive here")
## start the server from an endpoint
##
from twisted.internet import reactor
server = serverFromString(reactor, self.server)
d = server.listen(transport_factory)
def onlisten(port):
config.port = port
d.addCallback(onlisten)
clients = []
clients_d = []
for C in client_components:
## create a WAMP application session factory
##
session_factory = ApplicationSessionFactory(config)
one_done = Deferred()
config.all_done.append(one_done)
def make_make(Klass, done):
def make(config):
c = Klass(config, done)
config.components.append(c)
return c
return make
## .. and set the session class on the factory
##
session_factory.session = make_make(C, one_done)
if self.transport == "websocket":
#.........这里部分代码省略.........
示例12: __init__
class Node:
"""
A Crossbar.io node is the running a controller process
and one or multiple worker processes.
A single Crossbar.io node runs exactly one instance of
this class, hence this class can be considered a system
singleton.
"""
def __init__(self, reactor, cbdir, debug = False):
"""
Ctor.
:param reactor: Reactor to run on.
:type reactor: obj
:param cbdir: Crossbar.io node directory to run from.
:type cbdir: str
"""
self.debug = debug
self._reactor = reactor
self._cbdir = cbdir
self._worker_processes = {}
## node name: FIXME
self._node_name = "{}-{}".format(socket.getfqdn(), os.getpid())
self._node_name.replace('-', '_')
self._node_name = '918234'
## node management
self._management_url = "ws://127.0.0.1:7000"
#self._management_url = "wss://cloud.crossbar.io"
self._management_realm = "crossbar.cloud.aliceblue"
## load Crossbar.io node configuration
##
cf = os.path.join(self._cbdir, 'config.json')
with open(cf, 'rb') as infile:
self._config = json.load(infile)
def start(self):
"""
Starts this node. This will start a node controller
and then spawn new worker processes as needed.
The node controller will watch spawned processes,
communicate via stdio with the worker, and start
and restart the worker processes as needed.
"""
## the node controller singleton WAMP application session
##
self._node_controller_session = NodeControllerSession(self)
## router and factory that creates router sessions
##
self._router_factory = RouterFactory()
self._router_session_factory = RouterSessionFactory(self._router_factory)
## add the node controller singleton session to the router
##
self._router_session_factory.add(self._node_controller_session)
if True:
## create a WAMP-over-WebSocket transport server factory
##
from autobahn.twisted.websocket import WampWebSocketServerFactory
from twisted.internet.endpoints import serverFromString
self._router_server_transport_factory = WampWebSocketServerFactory(self._router_session_factory, "ws://localhost:9000", debug = False)
self._router_server_transport_factory.setProtocolOptions(failByDrop = False)
## start the WebSocket server from an endpoint
##
self._router_server = serverFromString(self._reactor, "tcp:9000")
self._router_server.listen(self._router_server_transport_factory)
## factory that creates router session transports. these are for clients
## that talk WAMP-WebSocket over pipes with spawned worker processes and
## for any uplink session to a management service
##
self._router_client_transport_factory = WampWebSocketClientFactory(self._router_session_factory, "ws://localhost", debug = False)
self._router_client_transport_factory.setProtocolOptions(failByDrop = False)
if False:
management_session_factory = ApplicationSessionFactory()
management_session_factory.session = NodeManagementSession
management_session_factory.node_controller_session = node_controller_session
management_transport_factory = WampWebSocketClientFactory(management_session_factory, "ws://127.0.0.1:7000")
management_transport_factory.setProtocolOptions(failByDrop = False)
management_client = clientFromString(self._reactor, "tcp:127.0.0.1:7000")
management_client.connect(management_transport_factory)
## startup the node from configuration file
##
self._node_controller_session.run_node_config(self._config)
示例13: install_reactor
from autobahn.twisted.choosereactor import install_reactor
reactor = install_reactor()
if args.debug:
print("Running on reactor {}".format(reactor))
## create a WAMP router factory
##
from autobahn.wamp.router import RouterFactory
router_factory = RouterFactory()
## create a WAMP router session factory
##
from autobahn.twisted.wamp import RouterSessionFactory
session_factory = RouterSessionFactory(router_factory)
session_factory.add(TestService())
from autobahn.wamp.serializer import MsgPackSerializer
serializer = MsgPackSerializer()
from autobahn.twisted.rawsocket import WampRawSocketClientFactory, WampRawSocketClientProtocol
transport_factory = WampRawSocketClientFactory(session_factory, serializer, debug = args.debug)
class WorkerClientProtocol(WampRawSocketClientProtocol):
def connectionMade(self):
WampRawSocketClientProtocol.connectionMade(self)
示例14: __init__
class Node:
"""
A Crossbar.io node is the running a controller process
and one or multiple worker processes.
A single Crossbar.io node runs exactly one instance of
this class, hence this class can be considered a system
singleton.
"""
def __init__(self, reactor, options):
"""
Ctor.
:param reactor: Reactor to run on.
:type reactor: obj
:param options: Options from command line.
:type options: obj
"""
self.debug = False
self.options = options
## the reactor under which we run
self._reactor = reactor
## shortname for reactor to run (when given via explicit option) or None
self._reactor_shortname = options.reactor
## node directory
self._cbdir = options.cbdir
## the node's name (must be unique within the management realm)
self._node_id = None
## the node's management realm
self._realm = None
## node controller session (a singleton ApplicationSession embedded
## in the node's management router)
self._controller = None
def start(self):
"""
Starts this node. This will start a node controller and then spawn new worker
processes as needed.
"""
## for now, a node is always started from a local configuration
##
configfile = os.path.join(self.options.cbdir, self.options.config)
log.msg("Starting from local configuration '{}'".format(configfile))
config = checkconfig.check_config_file(configfile, silence = True)
self.start_from_config(config)
def start_from_config(self, config):
controller_config = config.get('controller', {})
controller_options = controller_config.get('options', {})
controller_title = controller_options.get('title', 'crossbar-controller')
try:
import setproctitle
except ImportError:
log.msg("Warning, could not set process title (setproctitle not installed)")
else:
setproctitle.setproctitle(controller_title)
## the node's name (must be unique within the management realm)
if 'id' in controller_config:
self._node_id = controller_config['id']
else:
self._node_id = socket.gethostname()
## the node's management realm
self._realm = controller_config.get('realm', 'crossbar')
## the node controller singleton WAMP application session
##
#session_config = ComponentConfig(realm = options.realm, extra = options)
self._controller = NodeControllerSession(self)
## router and factory that creates router sessions
##
self._router_factory = RouterFactory(
options = wamp.types.RouterOptions(uri_check = wamp.types.RouterOptions.URI_CHECK_LOOSE),
debug = False)
self._router_session_factory = RouterSessionFactory(self._router_factory)
## add the node controller singleton session to the router
##
self._router_session_factory.add(self._controller)
#.........这里部分代码省略.........
示例15: install_reactor
# we use an Autobahn utility to install the "best" available Twisted reactor
##
from autobahn.twisted.choosereactor import install_reactor
reactor = install_reactor()
if args.debug:
print("Running on reactor {}".format(reactor))
# create a WAMP router factory
##
from autobahn.wamp.router import RouterFactory
router_factory = RouterFactory()
# create a WAMP router session factory
from autobahn.twisted.wamp import RouterSessionFactory
session_factory = RouterSessionFactory(router_factory)
session_factory.session = WebServiceLoginRouterSession
session_factory.add(TimeService(args.realm))
# create a WAMP-over-WebSocket transport server factory
transport_factory = WampWebSocketServerFactory(
session_factory, args.wsurl, debug_wamp=args.debug)
#transport_factory.protocol = ServerProtocol
transport_factory.setProtocolOptions(failByDrop=False)
from twisted.web.server import Site
from twisted.web.static import File
from autobahn.twisted.resource import WebSocketResource