1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2010 United States Government as represented by the
4
# Administrator of the National Aeronautics and Space Administration.
6
# Copyright 2011 Red Hat, Inc.
8
# Licensed under the Apache License, Version 2.0 (the "License"); you may
9
# not use this file except in compliance with the License. You may obtain
10
# a copy of the License at
12
# http://www.apache.org/licenses/LICENSE-2.0
14
# Unless required by applicable law or agreed to in writing, software
15
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17
# License for the specific language governing permissions and limitations
20
from nova.openstack.common.gettextutils import _
21
from nova.openstack.common import log as logging
22
from nova.openstack.common import rpc
23
from nova.openstack.common.rpc import dispatcher as rpc_dispatcher
24
from nova.openstack.common import service
27
LOG = logging.getLogger(__name__)
30
class Service(service.Service):
31
"""Service object for binaries running on hosts.
33
A service enables rpc by listening to queues based on topic and host."""
34
def __init__(self, host, topic, manager=None):
35
super(Service, self).__init__()
41
self.manager = manager
44
super(Service, self).start()
46
self.conn = rpc.create_connection(new=True)
47
LOG.debug(_("Creating Consumer connection for Service %s") %
50
dispatcher = rpc_dispatcher.RpcDispatcher([self.manager])
52
# Share this same connection for these Consumers
53
self.conn.create_consumer(self.topic, dispatcher, fanout=False)
55
node_topic = '%s.%s' % (self.topic, self.host)
56
self.conn.create_consumer(node_topic, dispatcher, fanout=False)
58
self.conn.create_consumer(self.topic, dispatcher, fanout=True)
60
# Consume from all consumers in a thread
61
self.conn.consume_in_thread()
64
# Try to shut the connection down, but if we get any sort of
65
# errors, go ahead and ignore them.. as we're shutting down anyway
70
super(Service, self).stop()