Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 from cache_chain_object_store import CacheChainObjectStore | 5 from cache_chain_object_store import CacheChainObjectStore |
| 6 from memcache_object_store import MemcacheObjectStore | 6 from memcache_object_store import MemcacheObjectStore |
| 7 from persistent_object_store import PersistentObjectStore | 7 from persistent_object_store import PersistentObjectStore |
| 8 | 8 |
| 9 class ObjectStoreCreator(object): | 9 class ObjectStoreCreator(object): |
| 10 class Factory(object): | 10 class Factory(object): |
| 11 '''Parameters: | 11 '''Parameters: |
| 12 - |branch| The branch to create object stores for. This becomes part of the | 12 - |branch| The branch to create object stores for. This becomes part of the |
| 13 namespace for the object stores that are created. | 13 namespace for the object stores that are created. |
| 14 - |start_empty| Whether the caching object store that gets created should | 14 - |start_empty| Whether the caching object store that gets created should |
| 15 start empty, or start with the content of its delegate object stores. | 15 start empty, or start with the content of its delegate object stores. |
| 16 - |issue| Code review issue to preview. | |
| 17 - |patchset| Code review patchset to preview. | |
| 16 ''' | 18 ''' |
| 17 def __init__(self, app_version, branch, start_empty=False): | 19 def __init__(self, |
| 20 app_version, | |
| 21 branch, | |
| 22 start_empty=False, | |
| 23 issue=None, | |
| 24 patchset=None): | |
|
not at google - send to devlin
2013/04/26 23:53:53
I reckon we should make this stuff more generic, l
方觉(Fang Jue)
2013/04/27 01:02:48
Done.
| |
| 18 self._app_version = app_version | 25 self._app_version = app_version |
| 19 self._branch = branch | 26 self._branch = branch |
| 20 self._start_empty = start_empty | 27 self._start_empty = start_empty |
| 28 self._issue = issue | |
| 29 self._patchset = patchset | |
| 21 | 30 |
| 22 def Create(self, cls, store_type=None): | 31 def Create(self, cls, store_type=None): |
| 23 return ObjectStoreCreator(cls, | 32 return ObjectStoreCreator(cls, |
| 24 self._app_version, | 33 self._app_version, |
| 25 self._branch, | 34 self._branch, |
| 26 store_type=store_type, | 35 store_type=store_type, |
| 27 start_empty=self._start_empty) | 36 start_empty=self._start_empty, |
| 37 issue=self._issue, | |
| 38 patchset=self._patchset) | |
| 28 | 39 |
| 29 class SharedFactory(object): | 40 class SharedFactory(object): |
| 30 '''A |Factory| for creating object stores shared across branches. | 41 '''A |Factory| for creating object stores shared across branches. |
| 31 ''' | 42 ''' |
| 32 def __init__(self, app_version): | 43 def __init__(self, app_version): |
| 33 self._factory = ObjectStoreCreator.Factory(app_version, 'shared') | 44 self._factory = ObjectStoreCreator.Factory(app_version, 'shared') |
| 34 | 45 |
| 35 def Create(self, cls, store_type=None): | 46 def Create(self, cls, store_type=None): |
| 36 return self._factory.Create(cls, store_type=store_type) | 47 return self._factory.Create(cls, store_type=store_type) |
| 37 | 48 |
| 38 class TestFactory(object): | 49 class TestFactory(object): |
| 39 '''A |Factory| for creating object stores for tests, with fake defaults. | 50 '''A |Factory| for creating object stores for tests, with fake defaults. |
| 40 ''' | 51 ''' |
| 41 def __init__(self): | 52 def __init__(self): |
| 42 self._factory = ObjectStoreCreator.Factory('test-version', 'test-branch') | 53 self._factory = ObjectStoreCreator.Factory('test-version', 'test-branch') |
| 43 | 54 |
| 44 def Create(self, cls, store_type=None): | 55 def Create(self, cls, store_type=None): |
| 45 return self._factory.Create(cls, store_type=store_type) | 56 return self._factory.Create(cls, store_type=store_type) |
| 46 | 57 |
| 47 def __init__(self, | 58 def __init__(self, |
| 48 cls, | 59 cls, |
| 49 app_version, | 60 app_version, |
| 50 branch, | 61 branch, |
| 51 store_type=None, | 62 store_type=None, |
| 52 start_empty=False): | 63 start_empty=False, |
| 64 issue=None, | |
| 65 patchset=None): | |
| 53 '''Creates stores with a top-level namespace given by the name of |cls| | 66 '''Creates stores with a top-level namespace given by the name of |cls| |
| 54 combined with |branch|. Set an explicit |store_type| if necessary for tests. | 67 combined with |branch|. Set an explicit |store_type| if necessary for tests. |
| 55 | 68 |
| 56 By convention this should be the name of the class which owns the object | 69 By convention this should be the name of the class which owns the object |
| 57 store. If a class needs multiple object stores it should use Create with the | 70 store. If a class needs multiple object stores it should use Create with the |
| 58 |category| argument. | 71 |category| argument. |
| 59 ''' | 72 ''' |
| 60 assert isinstance(cls, type) | 73 assert isinstance(cls, type) |
| 61 assert not cls.__name__[0].islower() # guard against non-class types | 74 assert not cls.__name__[0].islower() # guard against non-class types |
| 62 self._name = '%s/%s@%s' % (app_version, cls.__name__, branch) | 75 self._name = '%s/%s@%s%s' % ( app_version, cls.__name__, branch, |
| 76 '' if issue is None else '.%s.%s' % (issue, patchset)) | |
|
not at google - send to devlin
2013/04/26 23:53:53
... (continuing from above) then have
if self._mo
方觉(Fang Jue)
2013/04/27 01:02:48
Done.
方觉(Fang Jue)
2013/04/29 12:46:23
In the latest patchset, the namespace will be some
| |
| 63 self._store_type = store_type | 77 self._store_type = store_type |
| 64 self._start_empty = start_empty | 78 self._start_empty = start_empty |
| 79 self._issue = issue | |
| 65 | 80 |
| 66 def Create(self, category=None): | 81 def Create(self, category=None): |
| 67 '''Creates a new object store with the top namespace given in the | 82 '''Creates a new object store with the top namespace given in the |
| 68 constructor with an optional |category| for classes that need multiple | 83 constructor with an optional |category| for classes that need multiple |
| 69 object stores (e.g. one for stat and one for read). | 84 object stores (e.g. one for stat and one for read). |
| 70 ''' | 85 ''' |
| 71 namespace = self._name | 86 namespace = self._name |
| 72 if category is not None: | 87 if category is not None: |
| 73 assert not any(c.isdigit() for c in category) | 88 assert not any(c.isdigit() for c in category) |
| 74 namespace = '%s/%s' % (namespace, category) | 89 namespace = '%s/%s' % (namespace, category) |
| 75 if self._store_type is not None: | 90 if self._store_type is not None: |
| 76 return self._store_type(namespace) | 91 return self._store_type(namespace) |
| 77 return CacheChainObjectStore( | 92 if self._issue is None: |
| 78 (MemcacheObjectStore(namespace), PersistentObjectStore(namespace)), | 93 return CacheChainObjectStore( |
| 79 start_empty=self._start_empty) | 94 (MemcacheObjectStore(namespace), PersistentObjectStore(namespace)), |
| 95 start_empty=self._start_empty) | |
| 96 else: | |
| 97 return CacheChainObjectStore((MemcacheObjectStore(namespace),), | |
| 98 start_empty=self._start_empty) | |
| OLD | NEW |