Merge "Rename MessageHandlingServer._executor for readability"

This commit is contained in:
Jenkins 2015-10-21 16:36:00 +00:00 committed by Gerrit Code Review
commit 87ad4c77ff
2 changed files with 13 additions and 13 deletions
oslo_messaging

@ -112,7 +112,7 @@ class MessageHandlingServer(service.ServiceBase):
raise ExecutorLoadFailure(self.executor, ex) raise ExecutorLoadFailure(self.executor, ex)
else: else:
self._executor_cls = mgr.driver self._executor_cls = mgr.driver
self._executor = None self._executor_obj = None
self._running = False self._running = False
super(MessageHandlingServer, self).__init__() super(MessageHandlingServer, self).__init__()
@ -131,19 +131,19 @@ class MessageHandlingServer(service.ServiceBase):
choose to dispatch messages in a new thread, coroutine or simply the choose to dispatch messages in a new thread, coroutine or simply the
current thread. current thread.
""" """
if self._executor is not None: if self._executor_obj is not None:
return return
with self._state_cond: with self._state_cond:
if self._executor is not None: if self._executor_obj is not None:
return return
try: try:
listener = self.dispatcher._listen(self.transport) listener = self.dispatcher._listen(self.transport)
except driver_base.TransportDriverError as ex: except driver_base.TransportDriverError as ex:
raise ServerListenError(self.target, ex) raise ServerListenError(self.target, ex)
self._running = True self._running = True
self._executor = self._executor_cls(self.conf, listener, self._executor_obj = self._executor_cls(self.conf, listener,
self.dispatcher) self.dispatcher)
self._executor.start() self._executor_obj.start()
self._state_cond.notify_all() self._state_cond.notify_all()
def stop(self): def stop(self):
@ -155,9 +155,9 @@ class MessageHandlingServer(service.ServiceBase):
server are still in use. See 'wait' for more details. server are still in use. See 'wait' for more details.
""" """
with self._state_cond: with self._state_cond:
if self._executor is not None: if self._executor_obj is not None:
self._running = False self._running = False
self._executor.stop() self._executor_obj.stop()
self._state_cond.notify_all() self._state_cond.notify_all()
def wait(self): def wait(self):
@ -190,8 +190,8 @@ class MessageHandlingServer(service.ServiceBase):
" messages to finish processing, it has" " messages to finish processing, it has"
" been %0.2f seconds and stop() still has" " been %0.2f seconds and stop() still has"
" not been called"), w.elapsed()) " not been called"), w.elapsed())
executor = self._executor executor = self._executor_obj
self._executor = None self._executor_obj = None
if executor is not None: if executor is not None:
# We are the lucky calling thread to wait on the executor to # We are the lucky calling thread to wait on the executor to
# actually finish. # actually finish.

@ -120,14 +120,14 @@ class TestRPCServer(test_utils.BaseTestCase, ServerSetupMixin):
server = oslo_messaging.get_rpc_server(transport, target, endpoints, server = oslo_messaging.get_rpc_server(transport, target, endpoints,
serializer=serializer) serializer=serializer)
# Mocking executor # Mocking executor
server._executor = mock.Mock() server._executor_obj = mock.Mock()
# Here assigning executor's listener object to listener variable # Here assigning executor's listener object to listener variable
# before calling wait method, because in wait method we are # before calling wait method, because in wait method we are
# setting executor to None. # setting executor to None.
listener = server._executor.listener listener = server._executor_obj.listener
# call server wait method # call server wait method
server.wait() server.wait()
self.assertIsNone(server._executor) self.assertIsNone(server._executor_obj)
self.assertEqual(1, listener.cleanup.call_count) self.assertEqual(1, listener.cleanup.call_count)
def test_no_target_server(self): def test_no_target_server(self):