Author: justi9
Date: 2008-06-25 17:18:15 -0400 (Wed, 25 Jun 2008)
New Revision: 2165
Modified:
mgmt/mint/python/mint/__init__.py
Log:
Use the callback context argument to avoid extra connection lookups; clean up connection
handling in BrokerConnection open
Modified: mgmt/mint/python/mint/__init__.py
===================================================================
--- mgmt/mint/python/mint/__init__.py 2008-06-25 19:39:49 UTC (rev 2164)
+++ mgmt/mint/python/mint/__init__.py 2008-06-25 21:18:15 UTC (rev 2165)
@@ -178,22 +178,19 @@
self.model.closeCallback)
self.mclient.schemaListener(self.model.schemaCallback)
- self.model.lock()
try:
- try:
- # XXX I want this to happen after broker start, but the
- # callbacks rely on the broker being in the connectedBrokers
- # dict
- self.model.connections[self.id] = self
+ self.conn.start()
+ self.mchan = self.mclient.addChannel \
+ (self.conn.session(str(uuid4())), self)
- self.conn.start()
- self.mchan = self.mclient.addChannel(self.conn.session(str(uuid4())),
- self.id)
+ self.state = "opened"
+ except Exception, e:
+ self.exception = e
+ raise e
- self.state = "opened"
- except Exception, e:
- self.exception = e
- raise e
+ self.model.lock()
+ try:
+ self.model.connections[self.id] = self
finally:
self.model.unlock()
@@ -223,18 +220,18 @@
self.model.lock()
try:
- try:
- self.mclient.removeChannel(self.mchan)
-
del self.model.connections[self.id]
-
- self.state = "closed"
- except Exception, e:
- self.exception = e
- raise e
finally:
self.model.unlock()
+ try:
+ self.mclient.removeChannel(self.mchan)
+
+ self.state = "closed"
+ except Exception, e:
+ self.exception = e
+ raise e
+
self.conn.close()
# XXX What else do I need to try to shutdown here?
@@ -300,32 +297,19 @@
def setCloseListener(self, connCloseListener):
self.connCloseListener = connCloseListener
- def getConnection(self, id):
- self.lock()
- try:
- try:
- return self.connections[id]
- except KeyError:
- log.error("Connection '%s' not found" % id)
- finally:
- self.unlock()
-
- def schemaCallback(self, brokerId, classInfo, configs, metric, methods, events):
- conn = self.getConnection(brokerId)
+ def schemaCallback(self, conn, classInfo, configs, metric, methods, events):
up = update.SchemaUpdate(conn, classInfo, configs, metric, methods, events)
self.updateThread.enqueue(up)
- def configCallback(self, brokerId, classInfo, props, timestamps):
- conn = self.getConnection(brokerId)
+ def configCallback(self, conn, classInfo, props, timestamps):
up = update.PropertyUpdate(conn, classInfo, props, timestamps)
self.updateThread.enqueue(up)
- def instCallback(self, brokerId, classInfo, stats, timestamps):
- conn = self.getConnection(brokerId)
+ def instCallback(self, conn, classInfo, stats, timestamps):
up = update.StatisticUpdate(conn, classInfo, stats, timestamps)
self.updateThread.enqueue(up)
- def methodCallback(self, brokerId, methodId, errorNo, errorText, args):
+ def methodCallback(self, conn, methodId, errorNo, errorText, args):
self.log("\nMETHOD---------------------------------------------------")
self.log("MethodId=%d" % (methodId))
self.log("Error: %d %s" % (errorNo, errorText))
@@ -342,23 +326,23 @@
self.log("END
METHOD---------------------------------------------------\n")
return result
- def closeCallback(self, brokerId, data):
+ def closeCallback(self, conn, data):
self.log("\nCLOSE---------------------------------------------------")
- self.log("BrokerId=%s , Data=%s" % (brokerId, data))
+ self.log("BrokerId=%s , Data=%s" % (conn.id, data))
self.lock()
try:
- del self.connections[brokerId]
+ del self.connections[conn.id]
if (self.connCloseListener != None):
- self.connCloseListener(brokerId, data)
+ self.connCloseListener(conn, data)
finally:
self.unlock()
self.log("END CLOSE---------------------------------------------------\n")
return
- def controlCallback(self, brokerId, type, data):
+ def controlCallback(self, conn, type, data):
self.log("\nCONTROL---------------------------------------------------")
readableType = "UNKNOWN"
if (type == managementClient.CTRL_BROKER_INFO):
@@ -369,7 +353,7 @@
readableType = "CTRL_USER"
elif (type == managementClient.CTRL_HEARTBEAT):
readableType = "CTRL_HEARTBEAT"
- self.log("BrokerId=%s , Type=%s, Data=%s" % (brokerId, readableType,
data))
+ self.log("BrokerId=%s , Type=%s, Data=%s" % (conn.id, readableType, data))
self.log("END
CONTROL---------------------------------------------------\n")
return