Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# Copyright (c) 2014, Facebook, Inc. All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. An additional grant # of patent rights can be found in the PATENTS file in the same directory. #
"""A loopless task that handles thrift requests.
You will need to subclass this task, set MODULE, and implement the necessary methods in order for requests to be mapped here."""
(self.__class__.__name__, missing_methods))
def processor(self):
(self.MODULE)
def processor(self):
"""Returns True if `task` implements the appropriate MODULE Iface""" # Skip non-ThriftHandlerTasks
# If self.MODULE is None, then connect *any* ThriftHandlerTask
iface = self.MODULE.Iface # Verify task has all the Iface methods. for method_name in dir(iface): method = getattr(iface, method_name)
# Skip field attributes if not callable(method): continue
# Check for this method on the handler task handler_method = getattr(task, method_name, None) if handler_method is None: self.logger.debug("Skipping Task %s (missing method %s)", task.name, method_name) return False
# And make sure that attribute is actually callable if not callable(handler_method): self.logger.debug("Skipping Task %s (%s not callable)", task.name, method_name) return False
# If all the methods are there, the shoe fits. return True
"""Returns all processors that match this tasks' MODULE"""
"""Spin up a thrift TNonblockingServer in a sparts worker thread"""
help='Address to bind server to [%(default)s]') type=int, metavar='PORT', help='Port to run server on [%(default)s]') help='Server Worker Threads [%(default)s]')
"""Overridden to bind sockets, etc"""
# Construct TServerSocket this way for compatibility with fbthrift
threads=self.num_threads)
self._fmt_hostport(self.bound_host, self.bound_port))
"""Helper to retrieve the socket objects for a given TServerSocket"""
# Some TServerSocket implementations support multiple handles per # TServerSocket (e.g., to support binding v4 and v6 without # v4-mapped addresses return tsocket.handles.values()
return '[%s]:%d' % (host, port) else:
"""Overridden to tell the thrift server to shutdown asynchronously"""
"""Overridden to execute TNonblockingServer's main loop""" |