base/app_manager: introduce singleton pattern to AppManager

Later VRRP service creates/deletes RyuApp dynamically as VRRP router
is enabled/disabled.
When creating/deleting RyuApp, unique RyuManager should be used.
There needs a way to get a unique RyuApp. So introduce singleton pattern

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
Isaku Yamahata 2013-11-22 16:45:58 +09:00 committed by FUJITA Tomonori
parent 5dd45aea0c
commit 2a10dfbd9c
2 changed files with 10 additions and 1 deletions

View File

@ -149,6 +149,15 @@ class RyuApp(object):
class AppManager(object):
# singletone
_instance = None
@staticmethod
def get_instance():
if not AppManager._instance:
AppManager._instance = AppManager()
return AppManager._instance
def __init__(self):
self.applications_cls = {}
self.applications = {}

View File

@ -63,7 +63,7 @@ def main():
app_lists = CONF.app_lists + CONF.app
app_mgr = AppManager()
app_mgr = AppManager.get_instance()
app_mgr.load_apps(app_lists)
contexts = app_mgr.create_contexts()
app_mgr.instantiate_apps(**contexts)