def from_bson(cls, doc, my_node, body): """ @param my_node: the current Node. @type my_node: Node @param body: message body @type body: basestring """ assert cls.validate_schema(doc), repr(doc) # We need to get the proper object (either C{Host} or C{Node}) for # the peer by its UUID, to pass to C{MessageFromBigDB} constructor. # For now let's assume that if any peer (src or dst) # has the same UUID as our Node, the peer is the C{Node}; # otherwise, it's a C{Host}. peer_from_uuid = \ lambda u: my_node if u == my_node.uuid \ else HostAtNode(uuid=HostUUID.safe_cast_uuid(u)) return partial(super(MessageFromBigDB, cls).from_bson(doc), # AbstractMessage src=peer_from_uuid(doc['src']), dst=peer_from_uuid(doc['dst']), is_ack=doc['ack'], direct=doc['src'] == my_node.uuid or doc['dst'] == my_node.uuid, uuid=MessageUUID.safe_cast_uuid(doc['uuid']), status_code=doc.get('status_code', 0), start_time=doc['uploadDate'], # MessageFromBigDB name=doc['name'], body=body)
def get_message_uuids(cls, class_name=None, dst_uuid=None, bdbw=None): """Find the UUIDs of outgoing messages by various criteria. @param class_name: (optional) the name of the desired message class. @type class_name: basestring, NoneType @param dst_uuid: (optional) the UUID of the destination peer. @type dst_uuid: PeerUUID, NoneType @return: the iterable over the the UUIDs of outgoing messages. @rtype: col.Iterable """ spec = cls._spec_for_get_message_uuids(class_name=class_name, dst_uuid=dst_uuid) logger.verbose('Getting transaction states with spec: %r', spec) docs = bdbw.retried_sync(bdbw.messages.files.find, spec=spec) return (MessageUUID.safe_cast_uuid(doc['uuid']) for doc in docs)