[rhmessaging-commits] rhmessaging commits: r2058 - mgmt/mint/python/mint.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Thu May 15 19:03:35 EDT 2008


Author: nunofsantos
Date: 2008-05-15 19:03:35 -0400 (Thu, 15 May 2008)
New Revision: 2058

Modified:
   mgmt/mint/python/mint/__init__.py
Log:
lock shared data structures for thread safety

Modified: mgmt/mint/python/mint/__init__.py
===================================================================
--- mgmt/mint/python/mint/__init__.py	2008-05-15 19:49:57 UTC (rev 2057)
+++ mgmt/mint/python/mint/__init__.py	2008-05-15 23:03:35 UTC (rev 2058)
@@ -284,12 +284,23 @@
     self.mchan = None
 
   def getByOriginalId(self, objType, idOriginal, managedBroker, create=False, args={}):
-    return self.objs.getByOriginalId(objType, idOriginal, managedBroker, create, args)
+    result = None
+    self.model.lock.acquire()
+    try:
+      result = self.objs.getByOriginalId(objType, idOriginal, managedBroker, create, args)
+    finally:
+      self.model.lock.release()
+    return result
 
   def getByIndexAttrib(self, objType, indexAttrib, indexValue, parent,
                        create=False, args={}):
-    return self.objs.getByIndexAttrib(objType, indexAttrib, indexValue,
-                                      create, args)
+    result = None
+    self.model.lock.acquire()
+    try:
+      result = self.objs.getByIndexAttrib(objType, indexAttrib, indexValue, create, args)
+    finally:
+      self.model.lock.release()
+    return result
 
 class MintModel:
   staticInstance = None
@@ -366,9 +377,16 @@
   def configCallback(self, brokerId, classInfo, list, timestamps):
     self.log("\nCONFIG---------------------------------------------------")
     objectName = classInfo[1]
+    brokerUUID = classInfo[2]
     self.log(objectName)
     d = self.sanitizeDict(dict(list))
-    conn = self.connections[brokerId]
+
+    self.lock.acquire()
+    try:
+      conn = self.connections[brokerId]
+    finally:
+      self.lock.release()
+
     d["managedBroker"] = brokerId
     d["recTime"] = datetime.fromtimestamp(timestamps[0]/1000000000)
     d["creationTime"] = datetime.fromtimestamp(timestamps[1]/1000000000)
@@ -398,9 +416,16 @@
   def instCallback(self, brokerId, classInfo, list, timestamps):
     self.log("\nINST---------------------------------------------------")
     objectName = classInfo[1]
+    brokerUUID = classInfo[2]
     self.log(objectName)
     d = self.sanitizeDict(dict(list))
-    conn = self.connections[brokerId]
+
+    self.lock.acquire()
+    try:
+      conn = self.connections[brokerId]
+    finally:
+      self.lock.release()
+
     d["recTime"] = datetime.fromtimestamp(timestamps[0]/1000000000)
     self.log(d)
 
@@ -455,7 +480,13 @@
   def closeCallback(self, brokerId, data):
     self.log("\nCLOSE---------------------------------------------------")
     self.log("BrokerId=%s , Data=%s" % (brokerId, data))
-    del self.connections[brokerId]
+
+    self.lock.acquire()
+    try:
+      del self.connections[brokerId]
+    finally:
+      self.lock.release()
+
     if (self.connCloseListener != None):
       self.connCloseListener(brokerId, data)
     self.log("END CLOSE---------------------------------------------------\n")
@@ -463,7 +494,14 @@
     
   def controlCallback(self, brokerId, type, data):
     self.log("\nCONTROL---------------------------------------------------")
-    self.log("BrokerId=%s , Type=%s, Data=%s" % (brokerId, type, data))
+    readableType = "UNKNOWN"
+    if (type == managementClient.CTRL_BROKER_INFO): 
+      readableType = "CTRL_BROKER_INFO"
+    elif (type == managementClient.CTRL_SCHEMA_LOADED):
+      readableType = "CTRL_SCHEMA_LOADED"
+    elif (type == managementClient.CTRL_USER):
+      readableType = "CTRL_USER"
+    self.log("BrokerId=%s , Type=%s, Data=%s" % (brokerId, readableType, data))
     self.log("END CONTROL---------------------------------------------------\n")
     return
 
@@ -474,7 +512,13 @@
     return methodId
 
   def getConnectionByRegistration(self, reg):
-    return self.connections.get("%s:%i" % (reg.host, reg.port))
+    result = None
+    self.lock.acquire()
+    try:
+      result = self.connections.get("%s:%i" % (reg.host, reg.port))
+    finally:
+      self.lock.release()
+    return result
 
 class MintDatabase(object):
   def __init__(self, uri):




More information about the rhmessaging-commits mailing list