def CreateMatch(self, request, context): """ This is stateless, i.e. no dedicated session for the match; must return the unique id of the match and this must be sent as a parameter with all requests. Like sessions on a multi-threaded webserver. :param request: :param context: :return: match_id """ print("in create match") new_match = self.factory.create(request.matchType) match = darts_match.DartsMatch() match.register_player(request.userName) new_match.set_match(match) match_id = self.registry.add_match(new_match) print("Created match: " + str(match_id.bytes)) return MatchResponse(matchId=match_id.bytes)
from domain import darts_match import threading class AddThread(threading.Thread): def __init__(self, thread_id, name, match): threading.Thread.__init__(self) self.threadID = thread_id self.name = name self.match = match self.dao = darts_match_dao_thread_safe_singleton.DartsMatchDao.get_instance( ) def run(self): print("Starting " + self.name) self.dao.add(self.match) print("Exiting " + self.name) dart_match1 = darts_match.DartsMatch('Dupe', 'Dup2') thread1 = AddThread(1, "Thread-1", dart_match1) dart_match2 = darts_match.DartsMatch('Dupe', 'Dup2') thread2 = AddThread(2, "Thread-2", dart_match2) thread1.start() thread2.start() print("Exiting main thread.")
from dao import darts_match_dao from domain import darts_match from service import match_service dao = darts_match_dao.DartsMatchDao() match = darts_match.DartsMatch('Dupe', 'Dup1') dao.add(match)
from dao import darts_match_dao from domain import darts_match dao = darts_match_dao.DartsMatchDao() match = darts_match.DartsMatch('501', 'Dupe', 'Dup1') dao.add(match) dao2 = darts_match_dao.DartsMatchDao() match = darts_match.DartsMatch('501', 'Dupe2', 'Dup2') dao2.add(match)
import pattern.object_factory as object_factory import app.gameimpl.x01_match as x01_match import domain.darts_match as darts_match from datatype.enums import DartMultiplier from domain import visit factory = object_factory.ObjectFactory() factory.register_builder('X01', x01_match.X01MatchBuilder()) x01 = factory.create('X01') match = darts_match.DartsMatch() player1_index = match.register_player('Alice') player2_index = match.register_player('Kalifa') x01.set_match(match) my_visit = visit.Visit([(DartMultiplier.SINGLE, 20), (DartMultiplier.TREBLE, 20), (DartMultiplier.SINGLE, 5)]) result, response = x01.process_visit(player1_index, my_visit) print(response) my_visit = visit.Visit([(DartMultiplier.SINGLE, 1), (DartMultiplier.SINGLE, 5), (DartMultiplier.SINGLE, 20)]) result, response = x01.process_visit(player2_index, my_visit) print(response) my_visit = visit.Visit([(DartMultiplier.TREBLE, 20), (DartMultiplier.TREBLE, 20), (DartMultiplier.TREBLE, 20)]) result, response = x01.process_visit(player1_index, my_visit)