def __init__(self, pdbhelper, rootcc, qmangr, to_eventprocessor, cshardmgr_interface): """@type pdbhelper: L{lobbyapp.playerdb.api.PDBHelperInterface} implementation. @type qmangr: L{lobbyapp.queuemangr.QueueManager} @param to_eventprocessor: Queue that can be used to send orders to EventProcessor @type to_eventprocessor: L{Queue.Queue} @param cshardmgr_interface: interface to CShardMgr @type cshardmgr_interface: tuple(str, int)""" Monitor.__init__(self) self.pirs = {} #: pid => PlayerInformationRecord self.cshardmgr_interface = cshardmgr_interface self.pdbhelper = pdbhelper self.qmangr = qmangr self.alphas = [] # all existing AlphaMatches self.betagammas = [] # all existing BetaGammas self.to_eventprocessor = to_eventprocessor cc = CounterCollection('player_database') self.transactions_counter = PulseCounter('transactions', resolution=60, units=u'transactions per minute', description=u'player database transactions performed') alphas_waiting = CallbackCounter('alphas_waiting', self.alphas.__len__, description=u'matches being prepared') betagammas = CallbackCounter('betagammas', self.betagammas.__len__, description=u'matches being played') cc.add(self.transactions_counter) cc.add(alphas_waiting) cc.add(betagammas) rootcc.add(cc)
def test_release_contextmanager(self): class TestedClass(Monitor): def __init__(self, cqueue): self.cqueue = cqueue Monitor.__init__(self) @Monitor.protect def execute(self): self.cqueue.put(1) sleep(1) self.cqueue.get() class TesterThread(Thread): def __init__(self, tc): self.tc = tc Thread.__init__(self) def run(self): self.tc.execute() cq = Queue() cq.put(1) tc = TestedClass(cq) tt = TesterThread(tc) with Monitor.acquire(tc): with Monitor.release(tc): tt.start() sleep(0.4) self.assertEqual(cq.qsize(), 2)
def __init__(self, confsection): Monitor.__init__(self) self.conn = sqlite3.connect(confsection['path'], check_same_thread=False) # Check if table exists cur = self.conn.cursor() try: cur.execute('SELECT COUNT(rowid) FROM sent') except sqlite3.OperationalError: cur.execute('''CREATE TABLE sent ( rowid INTEGER PRIMARY KEY ASC, sent_on DATE NOT NULL, content BLOB NOT NULL, target TEXT NOT NULL, tag TEXT); ''') cur.execute('CREATE INDEX i_sent_sent_on ON sent (sent_on)') self.conn.commit() cur.close()
def start(self, slave=False): """Organizes for transaction in run() to be run atomically. @param slave: set this to True if you invoke it from a transaction so that lock is not reacquired. """ self.pdb.transactions_counter.update() if not slave: with Monitor.acquire(self.pdb): return self.run() else: return self.run()
def __init__(self, pdbhelper, rootcc, qmangr, to_eventprocessor, cshardmgr_interface): """@type pdbhelper: L{lobbyapp.playerdb.api.PDBHelperInterface} implementation. @type qmangr: L{lobbyapp.queuemangr.QueueManager} @param to_eventprocessor: Queue that can be used to send orders to EventProcessor @type to_eventprocessor: L{Queue.Queue} @param cshardmgr_interface: interface to CShardMgr @type cshardmgr_interface: tuple(str, int)""" Monitor.__init__(self) self.pirs = {} #: pid => PlayerInformationRecord self.cshardmgr_interface = cshardmgr_interface self.pdbhelper = pdbhelper self.qmangr = qmangr self.alphas = [] # all existing AlphaMatches self.betagammas = [] # all existing BetaGammas self.to_eventprocessor = to_eventprocessor cc = CounterCollection('player_database') self.transactions_counter = PulseCounter( 'transactions', resolution=60, units=u'transactions per minute', description=u'player database transactions performed') alphas_waiting = CallbackCounter('alphas_waiting', self.alphas.__len__, description=u'matches being prepared') betagammas = CallbackCounter('betagammas', self.betagammas.__len__, description=u'matches being played') cc.add(self.transactions_counter) cc.add(alphas_waiting) cc.add(betagammas) rootcc.add(cc)
def __init__(self, namespace, description=None): Monitor.__init__(self) CounterObject.__init__(self, namespace, description=description) self.items = {}
def __init__(self, cqueue): self.cqueue = cqueue Monitor.__init__(self)