Fixing static lock messup with Ns3 DCE Manager
[nepi.git] / src / nepi / resources / ns3 / ns3dceapplication.py
index fd1c513..0b3d302 100644 (file)
@@ -32,14 +32,6 @@ import threading
 class NS3BaseDceApplication(NS3BaseApplication):
     _rtype = "abstract::ns3::DceApplication"
 
-    # Lock used to synchronize usage of DceManagerHelper 
-    _dce_manager_lock = threading.Lock()
-    # Lock used to synchronize usage of DceApplicationHelper
-    _dce_application_lock = threading.Lock()
-   
-    _dce_manager_helper_uuid = None
-    _dce_application_helper_uuid = None
-
     @classmethod
     def _register_attributes(cls):
         binary = Attribute("binary", 
@@ -92,36 +84,6 @@ class NS3BaseDceApplication(NS3BaseApplication):
     def pid(self):
         return self._pid
 
-    @property
-    def dce_manager_helper_uuid(self):
-        if not NS3BaseDceApplication._dce_manager_helper_uuid:
-                NS3BaseDceApplication._dce_manager_helper_uuid = \
-                        self.simulation.create("DceManagerHelper")
-
-        if self.get("useDlmLoader"):
-            self.simulation.invoke(
-                NS3BaseDceApplication._dce_manager_helper_uuid, 
-                "SetLoader", 
-                "ns3::DlmLoaderFactory")
-
-        return NS3BaseDceApplication._dce_manager_helper_uuid
-
-    @property
-    def dce_application_helper_uuid(self):
-        if not NS3BaseDceApplication._dce_application_helper_uuid:
-                NS3BaseDceApplication._dce_application_helper_uuid = \
-                        self.simulation.create("DceApplicationHelper")
-                        
-        return NS3BaseDceApplication._dce_application_helper_uuid
-
-    @property
-    def dce_manager_lock(self):
-        return NS3BaseDceApplication._dce_manager_lock
-
-    @property
-    def dce_application_lock(self):
-        return NS3BaseDceApplication._dce_application_lock
-
     def _instantiate_object(self):
         pass
 
@@ -132,51 +94,37 @@ class NS3BaseDceApplication(NS3BaseApplication):
 
             # Preventing concurrent access to the DceApplicationHelper
             # from different DceApplication RMs
-            with self.dce_application_lock:
-                self.simulation.invoke(
-                        self.dce_application_helper_uuid, 
-                        "ResetArguments") 
+            dce_helper = self.simulation.dce_helper
+
+            with dce_helper.dce_application_lock:
+                dce_app_uuid = dce_helper.dce_application_uuid
+
+                self.simulation.invoke(dce_app_uuid, "ResetArguments") 
 
-                self.simulation.invoke(
-                        self.dce_application_helper_uuid, 
-                        "ResetEnvironment") 
+                self.simulation.invoke(dce_app_uuid, "ResetEnvironment") 
 
-                self.simulation.invoke(
-                        self.dce_application_helper_uuid, 
+                self.simulation.invoke(dce_app_uuid, 
                         "SetBinary", self.get("binary")) 
 
-                self.simulation.invoke(
-                        self.dce_application_helper_uuid, 
+                self.simulation.invoke(dce_app_uuid, 
                         "SetStackSize", self.get("stackSize")) 
 
                 arguments = self.get("arguments")
                 if arguments:
                     for arg in map(str.strip, arguments.split(";")):
-                        self.simulation.invoke(
-                                self.dce_application_helper_uuid, 
+                        self.simulation.invoke(dce_app_uuid, 
                             "AddArgument", arg)
 
                 environment = self.get("environment")
                 if environment:
                     for env in map(str.strip, environment.split(";")):
                         key, val = env.split("=")
-                        self.simulation.invoke(
-                                self.dce_application_helper_uuid, 
+                        self.simulation.invoke(dce_app_uuid, 
                             "AddEnvironment", key, val)
 
-                apps_uuid = self.simulation.invoke(
-                        self.dce_application_helper_uuid, 
+                apps_uuid = self.simulation.invoke(dce_app_uuid, 
                         "InstallInNode", self.node.uuid)
 
-
-                """
-                container_uuid = self.simulation.create("NodeContainer")
-                self.simulation.invoke(container_uuid, "Add", self.node.uuid)
-                apps_uuid = self.simulation.invoke(
-                        self.dce_application_helper_uuid, 
-                        "Install", container_uuid)
-                """
-
             self._uuid = self.simulation.invoke(apps_uuid, "Get", 0)
 
             if self.has_changed("StartTime"):
@@ -218,8 +166,12 @@ class NS3BaseDceApplication(NS3BaseApplication):
 
         # Using lock to prevent concurrent access to the DceApplicationHelper
         # from different DceApplication RMs
-        with self.dce_application_lock:
-            self._pid = self.simulation.invoke(self.dce_application_helper_uuid, 
+        dce_helper = self.simulation.dce_helper
+
+        with dce_helper.dce_application_lock:
+            dce_app_uuid = dce_helper.dce_application_uuid
+
+            self._pid = self.simulation.invoke(dce_app_uuid, 
                     "GetPid", self.uuid)
 
         node_id = self.node.node_id