Look up client descriptors by handler_id.

Previously, client descriptors were referenced directly from the
handler object.  Once we split the Tornado process into separate queue
and connection servers, these will no longer be in the same process,
so we need to reference them by ID instead.
This commit is contained in:
Tim Abbott 2014-01-28 11:12:18 -05:00 committed by Tim Abbott
parent ea6211c041
commit c7e3c3ce38
2 changed files with 18 additions and 6 deletions

View File

@ -148,8 +148,7 @@ class ClientDescriptor(object):
def connect_handler(self, handler_id):
self.current_handler_id = handler_id
handler = get_handler_by_id(self.current_handler_id)
handler.client_descriptor = self
set_descriptor_by_handler_id(handler_id, self)
self.last_connection_time = time.time()
def timeout_callback():
self._timeout_handle = None
@ -164,7 +163,7 @@ class ClientDescriptor(object):
if self.current_handler_id:
handler = get_handler_by_id(self.current_handler_id)
request = handler._request
handler.client_descriptor = None
delete_descriptor_by_handler_id(self.current_handler_id, None)
if client_closed:
logging.info("Client disconnected for queue %s (%s via %s)" %
(self.event_queue.id, self.user_profile_email,
@ -179,6 +178,17 @@ class ClientDescriptor(object):
do_gc_event_queues([self.event_queue.id], [self.user_profile_id],
[self.realm_id])
descriptors_by_handler_id = {}
def get_descriptor_by_handler_id(handler_id):
return descriptors_by_handler_id.get(handler_id)
def set_descriptor_by_handler_id(handler_id, client_descriptor):
descriptors_by_handler_id[handler_id] = client_descriptor
def delete_descriptor_by_handler_id(handler_id, client_descriptor):
del descriptors_by_handler_id[handler_id]
def compute_full_event_type(event):
if event["type"] == "update_message_flags":
if event["all"]:

View File

@ -21,7 +21,8 @@ from tornado import ioloop
from zerver.lib.debug import interactive_debug_listen
from zerver.lib.response import json_response
from zerver.lib.event_queue import process_notification, missedmessage_hook
from zerver.lib.event_queue import setup_event_queue, add_client_gc_hook
from zerver.lib.event_queue import setup_event_queue, add_client_gc_hook, \
get_descriptor_by_handler_id
from zerver.lib.handlers import allocate_handler_id
from zerver.lib.queue import setup_tornado_rabbitmq
from zerver.lib.socket import get_sockjs_router, respond_send_message
@ -187,8 +188,9 @@ class AsyncDjangoHandler(tornado.web.RequestHandler, base.BaseHandler):
self.get()
def on_connection_close(self):
if self.client_descriptor is not None:
self.client_descriptor.disconnect_handler(client_closed=True)
client_descriptor = get_descriptor_by_handler_id(self.handler_id)
if client_descriptor is not None:
client_descriptor.disconnect_handler(client_closed=True)
# Based on django.core.handlers.base: get_response
def get_response(self, request):