Add convenience RPC server classes
Rather than forcing all users of the server API to construct a dispatcher and import a specific executor, add a convenience server class e.g. server = eventlet.EventletRPCServer(transport, target, endpoints) Note that openstack.common.messaging.eventlet need be the only public module which has a dependency on eventlet. We can expose servers, clients and anything else eventlet specific through this part of the API.
This commit is contained in:
parent
e14ddb80e5
commit
a136bb089d
|
@ -44,10 +44,8 @@ Projects will need to do e.g.
|
|||
|
||||
from nova import baserpc
|
||||
from nova import config
|
||||
from nova.openstack.common.messaging import server
|
||||
from nova.openstack.common.messaging.executors import impl_eventlet
|
||||
from nova.openstack.common.messaging.rpc import dispatcher
|
||||
from nova.openstack.common.messaging.rpc import target
|
||||
from nova.openstack.common.messaging import eventlet
|
||||
from nova.openstack.common.messaging import target
|
||||
|
||||
def start(self):
|
||||
...
|
||||
|
@ -55,12 +53,9 @@ Projects will need to do e.g.
|
|||
|
||||
base_rpc = baserpc.BaseRPCAPI(self.service_name, backdoor_port)
|
||||
|
||||
self.rpcdispatcher = dispatcher.RPCDispatcher([self.manager, base_rpc])
|
||||
|
||||
self.rpcserver = server.MessageHandlingServer(config.TRANSPORT_DRIVER,
|
||||
target,
|
||||
self.rpcdispatcher,
|
||||
impl_eventlet.EventletExecutor)
|
||||
self.rpcserver = eventlet.EventletRPCServer(config.TRANSPORT_DRIVER,
|
||||
target,
|
||||
[self.manager, base_rpc])
|
||||
|
||||
LOG.debug(_("Starting RPC server for %(topic)s on %(server)s") %
|
||||
dict(topic=self.topic, host=self.server))
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
|
||||
# Copyright 2013 Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from openstack.common.messaging.executors import impl_eventlet
|
||||
from openstack.common.messaging.rpc import server
|
||||
|
||||
|
||||
class EventletRPCServer(server.RPCServer):
|
||||
|
||||
def __init__(self, transport, target, endpoints):
|
||||
executor_cls = impl_eventlet.EventletExecutor
|
||||
super(BlockingingRPCServer, self).__init__(transport,
|
||||
target,
|
||||
endpoints,
|
||||
executor_cls)
|
|
@ -0,0 +1,37 @@
|
|||
|
||||
# Copyright 2013 Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from openstack.common.messaging import server
|
||||
from openstack.common.messaging.executors import impl_blocking
|
||||
from openstack.common.messaging.rpc import dispatcher
|
||||
|
||||
|
||||
class RPCServer(server.MessageHandlingServer):
|
||||
|
||||
def __init__(self, transport, target, endpoints, executor_cls):
|
||||
super(RPCServer, self).__init__(transport,
|
||||
target,
|
||||
dispatcher.RPCDispatcher(endpoints),
|
||||
executor_cls)
|
||||
|
||||
|
||||
class BlockingRPCServer(RPCServer):
|
||||
|
||||
def __init__(self, transport, target, endpoints):
|
||||
executor_cls = impl_blocking.BlockingExecutor
|
||||
super(BlockingingRPCServer, self).__init__(transport,
|
||||
target,
|
||||
endpoints,
|
||||
executor_cls)
|
Loading…
Reference in New Issue