server/repository.py
changeset 8946 fae2f561b0f5
parent 8943 58b3b2d9c965
child 8947 3bbd416b09ec
equal deleted inserted replaced
8945:ba9e3fbfa5a5 8946:fae2f561b0f5
   190         self.querier = querier.QuerierHelper(self, self.schema)
   190         self.querier = querier.QuerierHelper(self, self.schema)
   191         # cache eid -> (type, physical source, extid, actual source)
   191         # cache eid -> (type, physical source, extid, actual source)
   192         self._type_source_cache = {}
   192         self._type_source_cache = {}
   193         # cache (extid, source uri) -> eid
   193         # cache (extid, source uri) -> eid
   194         self._extid_cache = {}
   194         self._extid_cache = {}
   195         # open some connections set
   195         # open some connection sets
   196         if config.init_cnxset_pool:
   196         if config.init_cnxset_pool:
   197             self.init_cnxset_pool()
   197             self.init_cnxset_pool()
       
   198         # the hooks manager
       
   199         self.hm = hook.HooksManager(self.vreg)
       
   200         # registry hook to fix user class on registry reload
   198         @onevent('after-registry-reload', self)
   201         @onevent('after-registry-reload', self)
   199         def fix_user_classes(self):
   202         def fix_user_classes(self):
   200             # After registery reload the 'CWUser' class used for CWEtype
   203             # After registery reload the 'CWUser' class used for CWEtype
   201             # changed.  To any existing user object have a different class than
   204             # changed.  To any existing user object have a different class than
   202             # the new loaded one. We are hot fixing this.
   205             # the new loaded one. We are hot fixing this.
   204             for session in self._sessions.itervalues():
   207             for session in self._sessions.itervalues():
   205                 if not isinstance(session.user, InternalManager):
   208                 if not isinstance(session.user, InternalManager):
   206                     session.user.__class__ = usercls
   209                     session.user.__class__ = usercls
   207 
   210 
   208     def init_cnxset_pool(self):
   211     def init_cnxset_pool(self):
       
   212         """should be called bootstrap_repository, as this is what it does"""
   209         config = self.config
   213         config = self.config
   210         self._cnxsets_pool = Queue.Queue()
   214         self._cnxsets_pool = Queue.Queue()
   211         self._cnxsets_pool.put_nowait(pool.ConnectionsSet(self.sources))
   215         self._cnxsets_pool.put_nowait(pool.ConnectionsSet(self.sources))
   212         if config.quick_start:
   216         if config.quick_start:
   213             # quick start, usually only to get a minimal repository to get cubes
   217             # quick start: only to get a minimal repository to get cubes
   214             # information (eg dump/restore/...)
   218             # information (eg dump/restore/...)
   215             config._cubes = ()
   219             config._cubes = ()
   216             # only load hooks and entity classes in the registry
   220             # only load hooks and entity classes in the registry
   217             config.cube_appobject_path = set(('hooks', 'entities'))
   221             config.cube_appobject_path = set(('hooks', 'entities'))
   218             config.cubicweb_appobject_path = set(('hooks', 'entities'))
   222             config.cubicweb_appobject_path = set(('hooks', 'entities'))
   239             for source in self.sources:
   243             for source in self.sources:
   240                 source.init_creating()
   244                 source.init_creating()
   241         # close initialization connetions set and reopen fresh ones for proper
   245         # close initialization connetions set and reopen fresh ones for proper
   242         # initialization now that we know cubes
   246         # initialization now that we know cubes
   243         self._get_cnxset().close(True)
   247         self._get_cnxset().close(True)
   244         # list of available_cnxsets (we can't iterate on Queue instance)
   248         self.cnxsets = [] # list of available cnxsets (can't iterate on a Queue)
   245         self.cnxsets = []
       
   246         for i in xrange(config['connections-pool-size']):
   249         for i in xrange(config['connections-pool-size']):
   247             self.cnxsets.append(pool.ConnectionsSet(self.sources))
   250             self.cnxsets.append(pool.ConnectionsSet(self.sources))
   248             self._cnxsets_pool.put_nowait(self.cnxsets[-1])
   251             self._cnxsets_pool.put_nowait(self.cnxsets[-1])
   249         if config.quick_start:
   252         if config.quick_start:
   250             config.init_cubes(self.get_cubes())
   253             config.init_cubes(self.get_cubes())
   251         self.hm = hook.HooksManager(self.vreg)
       
   252 
   254 
   253     # internals ###############################################################
   255     # internals ###############################################################
   254 
   256 
   255     def init_sources_from_database(self):
   257     def init_sources_from_database(self):
   256         self.sources_by_eid = {}
   258         self.sources_by_eid = {}