def getObjects(self, channel, userSequence, className, bank=0): """ Request immediate content from broker """ codec = Codec() self.setHeader(codec, ord('G'), userSequence) ft = {} ft["_class"] = className codec.write_map(ft) msg = channel.message(codec.encoded, routing_key="agent.1.%d" % bank) channel.send("qpid.management", msg)
def handleBrokerResponse(self, ch, codec): uuid = codec.read_uuid() ch.brokerInfo = brokerInfo(uuid, ch.sessionId) if self.ctrlCb != None: self.ctrlCb(ch.context, self.CTRL_BROKER_INFO, ch.brokerInfo) # Send a package request sendCodec = Codec() seq = self.seqMgr.reserve("outstanding") self.setHeader(sendCodec, ord('P'), seq) smsg = ch.message(sendCodec.encoded) ch.send("qpid.management", smsg)
def addChannel(self, channel, cbContext=None): """ Register a new channel. """ mch = managementChannel(channel, self.topicCb, self.replyCb, self.exceptCb, cbContext) self.channels.append(mch) self.incOutstanding(mch) codec = Codec() self.setHeader(codec, ord('B')) msg = mch.message(codec.encoded) mch.send("qpid.management", msg) return mch
def handlePackageInd(self, ch, codec): pname = codec.read_str8() if pname not in self.packages: self.packages[pname] = {} # Send a class request sendCodec = Codec() seq = self.seqMgr.reserve("outstanding") self.setHeader(sendCodec, ord('Q'), seq) self.incOutstanding(ch) sendCodec.write_str8(pname) smsg = ch.message(sendCodec.encoded) ch.send("qpid.management", smsg)
def topicCb(self, ch, msg): """ Receive messages via the topic queue of a particular channel. """ codec = Codec(msg.body) while True: hdr = self.checkHeader(codec) if hdr == None: return if hdr[0] == 'p': self.handlePackageInd(ch, codec) elif hdr[0] == 'q': self.handleClassInd(ch, codec) elif hdr[0] == 'h': self.handleHeartbeat(ch, codec) elif hdr[0] == 'e': self.handleEvent(ch, codec) else: self.parse(ch, codec, hdr[0], hdr[1])
def method(self, channel, userSequence, objId, classId, methodName, args): """ Invoke a method on an object """ codec = Codec() sequence = self.seqMgr.reserve((userSequence, classId, methodName)) self.setHeader(codec, ord('M'), sequence) objId.encode(codec) codec.write_str8(classId[0]) codec.write_str8(classId[1]) codec.write_bin128(classId[2]) codec.write_str8(methodName) bank = "%d.%d" % (objId.getBroker(), objId.getBank()) # Encode args according to schema if classId not in self.schema: self.seqMgr.release(sequence) raise ValueError("Unknown class name: %s" % classId) schemaClass = self.schema[classId] ms = schemaClass['M'] arglist = None for mname in ms: (mdesc, margs) = ms[mname] if mname == methodName: arglist = margs if arglist == None: self.seqMgr.release(sequence) raise ValueError("Unknown method name: %s" % methodName) for arg in arglist: if arg[2].find("I") != -1: value = arg[8] # default if arg[0] in args: value = args[arg[0]] if value == None: self.seqMgr.release(sequence) raise ValueError("Missing non-defaulted argument: %s" % arg[0]) self.encodeValue(codec, value, arg[1]) packageName = classId[0] className = classId[1] msg = channel.message(codec.encoded, "agent." + bank) channel.send("qpid.management", msg)
def replyCb(self, ch, msg): """ Receive messages via the reply queue of a particular channel. """ codec = Codec(msg.body) while True: hdr = self.checkHeader(codec) if hdr == None: return if hdr[0] == 'm': self.handleMethodReply(ch, codec, hdr[1]) elif hdr[0] == 'z': self.handleCommandComplete(ch, codec, hdr[1]) elif hdr[0] == 'b': self.handleBrokerResponse(ch, codec) elif hdr[0] == 'p': self.handlePackageInd(ch, codec) elif hdr[0] == 'q': self.handleClassInd(ch, codec) else: self.parse(ch, codec, hdr[0], hdr[1])
def handleClassInd(self, ch, codec): kind = codec.read_uint8() if kind != 1: # This API doesn't handle new-style events return pname = codec.read_str8() cname = codec.read_str8() hash = codec.read_bin128() if pname not in self.packages: return if (cname, hash) not in self.packages[pname]: # Send a schema request sendCodec = Codec() seq = self.seqMgr.reserve("outstanding") self.setHeader(sendCodec, ord('S'), seq) self.incOutstanding(ch) sendCodec.write_str8(pname) sendCodec.write_str8(cname) sendCodec.write_bin128(hash) smsg = ch.message(sendCodec.encoded) ch.send("qpid.management", smsg)