def __init__(self, server_socket, to_eventprocessor, from_eventprocessor, pdbhelper, rootcc): """@type server_socket: ServerSocket @type to_eventprocessor: L{Queue.Queue} @type from_eventprocessor: L{Queue.Queue} @param rootcc: root counter collection @type rootcc: L{satella.instrumentation.CounterCollection}""" SelectHandlingLayer.__init__(self) # Set up the server socket and attach it to SL self.server_socket = server_socket self.register_channel(server_socket) # dictionary (user pids => respective PlayerSocket) self.authenticated_channels = {} # Queue section self.to_ep = to_eventprocessor self.from_ep = from_eventprocessor # PDB section self.pdbhelper = pdbhelper # Instrumentation section cc = CounterCollection('selectlayer') self.connections_counter = DeltaCounter('connections', units='connections', description='SSL connections to server') self.outbound_events = PulseCounter('events_to_ep', resolution=60, units='events per minute', description='events sent to EventProcessor') cc.add(self.connections_counter) cc.add(self.outbound_events) rootcc.add(cc)
def test_async_socket_onconnected_called(self): """Tests whether socket's on_connected() is called in async configuration""" class CheckSocket(Socket): def __init__(self, *args, **kwargs): self.on_connected_called = False Socket.__init__(self, *args, **kwargs) def on_connected(self): self.on_connected_called = True mshl = SelectHandlingLayer() sck = CheckSocket(socket(AF_INET, SOCK_STREAM)) mshl.register_channel(sck) sck.connect(('www.yahoo.com', 80)) # that was just nonblocking a = time() while (time() - a < 30) and (not sck.on_connected_called): mshl.select() self.assertEquals(sck.on_connected_called, True)
def __init__(self, server_sockets, rootcc): SelectHandlingLayer.__init__(self) # process server sockets self.server_sockets = server_sockets # there may be many for server_socket in server_sockets: self.register_channel(server_socket) self.reqtasks = [] # ---------- instrumentation stuff self.c_lshardmgrs_connected = DeltaCounter('lshardmgrs_connected', description='Amount of lshardmgrs connected') self.c_requests_dispatched = PulseCounter('requests_dispatched', resolution=60, units=u'requests per minute', description='Requests to allocate a server sent') self.c_alloc_orders = PulseCounter('allocation_orders', resolution=60, units=u'allocation requests per minute', description=u'Allocation requests received') self.c_requests_success = PulseCounter('requests_successful', resolution=60, units=u'successful requests per minute', description=u'Requests successfully executed') self.c_requests_failed = PulseCounter('requests_failed', resolution=60, units=u'failed requests per minute', description=u'Failed requests') def calculate_shards_available(): a = [x for x in self.channels if x not in self.server_sockets] a = [x for x in a if x.who == 'l'] return sum([x.shards for x in a]) self.c_shards_available = CallbackCounter('shards_available', calculate_shards_available, units=u'shards', description=u'Available shards') rootcc.add(self.c_lshardmgrs_connected) rootcc.add(self.c_requests_dispatched) rootcc.add(self.c_alloc_orders) rootcc.add(self.c_requests_success) rootcc.add(self.c_requests_failed) rootcc.add(self.c_shards_available)
def __init__(self, pdb, socket): SelectHandlingLayer.__init__(self) self.server_socket = socket self.pdb = pdb self.register_channel(self.server_socket)
def __init__(self, utc): SelectHandlingLayer.__init__(self) self.packets_to_go = 3 self.sockets_to_close = 3 self.utc = utc
def __init__(self, utc): SelectHandlingLayer.__init__(self) self.utc = utc self.ok = False