[rhmessaging-commits] rhmessaging commits: r2008 - mgmt/mint/python/mint.
rhmessaging-commits at lists.jboss.org
rhmessaging-commits at lists.jboss.org
Thu May 8 14:09:50 EDT 2008
Author: justi9
Date: 2008-05-08 14:09:50 -0400 (Thu, 08 May 2008)
New Revision: 2008
Modified:
mgmt/mint/python/mint/__init__.py
Log:
Rearrange some things in broker connection to match changes in the
python client.
Catch connection failures and store the exception.
Modified: mgmt/mint/python/mint/__init__.py
===================================================================
--- mgmt/mint/python/mint/__init__.py 2008-05-08 17:27:43 UTC (rev 2007)
+++ mgmt/mint/python/mint/__init__.py 2008-05-08 18:09:50 UTC (rev 2008)
@@ -172,29 +172,50 @@
###FIX
return None
+# Not thread safe
class BrokerConnection(object):
def __init__(self, model, host, port):
self.model = model
+ self.host = host
+ self.port = port
self.key = "%s:%i" % (host, port)
self.objs = OriginalIdDict()
- spec = qpid.spec.load(model.specPath)
- self.conn = Connection(connect(host, port), spec)
- self.mclient = managementClient(spec, None,
- self.model.configCallback,
- self.model.instCallback,
- self.model.methodCallback)
- self.mclient.schemaListener(self.model.schemaCallback)
-
- self.state = None # in (None, "opening", "opened", "closing", "closed")
+ # state in (None, "opening", "opened", "open_failed",
+ # "closing", "closed", "close_failed")
+ self.state = None
self.exception = None
+ self.conn = None
+ self.mclient = None
+ self.mchan = None
+
def isOpen(self):
return self.state == "opened"
def open(self):
+ assert self.conn is None
+ assert self.mclient is None
+ assert self.mchan is None
+
self.state = "opening"
+ spec = qpid.spec.load(self.model.specPath)
+
+ try:
+ sock = connect(self.host, self.port)
+ except Exception, e:
+ self.state = "open_failed"
+ self.exception = e
+ return
+
+ self.conn = Connection(sock, spec)
+ self.mclient = managementClient(spec, None,
+ self.model.configCallback,
+ self.model.instCallback,
+ self.model.methodCallback)
+ self.mclient.schemaListener(self.model.schemaCallback)
+
self.model.lock.acquire()
try:
try:
@@ -204,7 +225,8 @@
self.model.connections[self.key] = self
self.conn.start()
- self.mchan = self.mclient.addChannel (self.conn.session(str(uuid4())), self.key)
+ self.mchan = self.mclient.addChannel(self.conn.session(str(uuid4())),
+ self.key)
self.state = "opened"
except Exception, e:
@@ -214,12 +236,15 @@
self.model.lock.release()
def getSessionId(self):
- if self.isOpen():
- return self.mchan.sessionId
- else:
- return None
+ if not self.isOpen():
+ raise Exception("Connection not open")
+ return self.mchan.sessionId
+
def callMethod(self, objId, className, methodName, callback, args):
+ if not self.isOpen():
+ raise Exception("Connection not open")
+
self.model.lock.acquire()
try:
self.model.currentMethodId += 1
@@ -248,6 +273,13 @@
finally:
self.model.lock.release()
+ self.conn.close()
+ # XXX What else do I need to try to shutdown here?
+
+ self.conn = None
+ self.mclient = None
+ self.mchan = None
+
def getByOriginalId(self, objType, idOriginal, create=False, args={}):
return self.objs.getByOriginalId(objType, idOriginal, create, args)
More information about the rhmessaging-commits
mailing list