Example #1
0
	def handleMeta(self, info, data):
		#trace("# Node.handleMeta info=" + str(info) + " data=" + str(data))

		# FILTER
		if not info.msg.startswith("meta."):
			#trace("not a meta message:" + info.msg)
			return  # NOT HANDLED

		# we only process meta messages for a (o d.n) address
		if info.dst.ownerId == None or info.dst.databaseId == None or info.dst.nodeId == None \
			or info.dst.pointId != None:
			#trace("not a Node message")
			return  # NOT HANDLED

		#trace("myaddr: " + str(self.addr))
		#trace("dst:" + str(info.dst))
		if not Address.match(self.addr, info.dst):
			#trace("not for my Node")
			return  # NOT HANDLED

		#trace("matched for my node")


		# DECODE
		verb = info.msg[5:-4]  # Get the middle verb
		msgtype = info.msg[-3:] # last 3 always the type

		self.dispatch(verb, msgtype, info.src, info.dst, data)
Example #2
0
	def handleMeta(self, info, data):
		#trace("Point.handleMeta:" + str(info) + " " + str(data))
		# FILTER
		if not info.msg.startswith("meta."):
			#trace("not a meta message:" + info.msg)
			return  # NOT HANDLED

		if not (info.msg.endswith(".req") or info.msg.endswith(".ind")):
			#trace("not a meta request:" + info.msg)
			return  # NOT HANDLED

		# we only process meta messages for this pointId
		#trace("filter? us:(" + str(self.addr) + " sender:" + str(info))
		if info.dst.pointId == None:
			return  # NOT HANDLED
		#TODO: If this is a remote, then self.addr is the remote address
		if not Address.match(self.addr, info.dst):
			return  # NOT HANDLED
		#trace("filter match Point")


		# DECODE
		verb = info.msg[5:-4]  # Get the middle verb
		msgtype = info.msg[-3:] # last 3 always the type

		self.dispatch(verb, msgtype, info.src, info.dst, data)
Example #3
0
	def routePoint(self, endType, pointName, nodeName=None, receive=None):
		"""Find and route one of our bindings to appropriate callbacks"""

		#trace("Node.routePoint:" + str(self.owner.ownerName) + " " + str(nodeName) + " " + str(pointName))

		if nodeName == None: # default to my owner/node
			nodeAddr = (self.owner.databaseId, self.nodeId)
		else: # eventually might want to override owner, so this will have to change
			nodeAddr = self.meta.getNodeAddr(self.owner.ownerId, nodeName)
			if nodeAddr == None:
				raise ValueError("Unknown node:" + str(nodeName))

		# create the in-memory representation of the Point, LOCAL or REMOTE
		databaseId = nodeAddr[0]
		nodeId     = nodeAddr[1]
		pointId = self.meta.getPointId(self.owner.ownerId, nodeId, pointName, databaseId=databaseId)
		if pointId == None:
			raise ValueError("Unknown point:" + str(pointName)
							 + " owner:" + str(self.owner.ownerId) + " databaseId:" + str(databaseId) + " nodeId:"+ str(nodeId))

		rec = self.meta.getPointRec(self.owner.ownerId, nodeId, pointId, databaseId=databaseId)
		pointType = rec["pointType"]
		p = Point.metaRestore(pointType, endType, self.owner.ownerId, nodeId, pointName, pointId, meta=self.meta, data=self.data,
							  	databaseId=databaseId)

		# Route any updates to this Point() through to the user supplied receive function.
		p.setCallbacks(receive)
		p.numBindings = 0

		# Set up data routing, any messages for this pointId routed to this Point() instance
		# which ultimately goes to the user supplied receive function.

		if endType == Point.REMOTE:

			# receiving end of a follow:  REMOTE   ONE_TO_MANY   src(o d.n p)->dst()
			#trace("  REMOTE FOLLOW (receiving end of follow)")
			src = Address(self.addr.ownerId, nodeId, pointId, databaseId=databaseId)
			#trace("  src:" + str(src))

			bindings = self.meta.getBindingsFor(bindType=Point.ONE_TO_MANY, src=src)
			#trace("  bindings:" + str(bindings))
			for b in bindings:
				src = Address(b["srcOwnerId"], b["srcNodeId"], b["srcPointId"], databaseId=b["srcDatabaseId"])
				dst = Address(b["dstOwnerId"], b["dstNodeId"], databaseId=b["dstDatabaseId"])
				anyAddr = Address.EMPTY
				#trace("FOLLOW LISTENER " + str(src) + "=>" + str(dst))
				#trace("my addr:" + str(self.addr))
				if Address.match(self.addr, dst):
					#trace(" found my binding")
					####TODO, only if dst matches our address, should we register a callback
					#otherwise we'll get everyone else's registrations too!
					self.data.registerListener("data.payload", src, anyAddr, p.handleReceive)
					p.numBindings += 1
				else:
					pass#trace("warning: must be a binding for someone else - ignoring")

			# sending end of an attach: REMOTE MANY_TO_ONE src(o d.n)->dst(o d.n p)
			#trace("  REMOTE ATTACH (sending end of attach)")
			#dst = Address(self.addr.ownerId, self.addr.nodeId, pointId, databaseId=databaseId)
			#trace("  dst:" + str(dst))

			#bindings = self.meta.getBindingsFor(dst=dst, bindType=Point.MANY_TO_ONE)
			#trace("  bindings:" + str(bindings))

			#for b in bindings:
			#	src = Address(b["dstOwnerId"], b["dstNodeId"], b["dstPointId"], b["dstDatabaseId"])
			#	dst = Address.EMPTY # right for addressing, but wrong for bind table lookup, get too much back???
			#	#trace("attach sender " + str(src) + "=>" + str(dst))
			#	# no registrations to do, but would expect a binding
			#	p.numBindings += 1

			#if p.numBindings == 0:
			#	raise ValueError("No REMOTE bindings were found in DB for:" + pointName)

		elif endType == Point.LOCAL:

			# receiving end of an attach: LOCAL    MANY_TO_ONE   src(o d.n)->dst(o d.n p)
			#trace("  LOCAL ATTACH (receiving end of attach)")
			dst = Address(self.addr.ownerId, self.addr.nodeId, pointId, databaseId=databaseId)
			#trace("  dst:" + str(dst))

			bindings = self.meta.getBindingsFor(dst=dst, bindType=Point.MANY_TO_ONE)
			#trace("  bindings:" + str(bindings))

			for b in bindings:
				src = Address(b["srcOwnerId"], b["srcNodeId"], databaseId=b["srcDatabaseId"])
				dst = Address(b["dstOwnerId"], b["dstNodeId"], b["dstPointId"], databaseId=b["dstDatabaseId"])
				#trace("ATTACH LISTENER " + str(src) + "=>" + str(dst))
				self.data.registerListener("data.payload", src, dst, p.handleReceive)
				p.numBindings += 1


			# receiving end of an attach: LOCAL    MANY_TO_ONE   src(o d.n)->dst(o d.n p)
			#trace("  LOCAL FOLLOW (sending end of follow)")
			#src = Address(self.owner.ownerId, self.addr.nodeId, pointId, databaseId=self.owner.databaseId)
			#trace("  src:" + str(src))

			#bindings = self.meta.getBindingsFor(bindType=Point.ONE_TO_MANY, src=src)
			#trace("  bindings:" + str(bindings))

			#for b in bindings:
			#	src = Address(b["srcOwnerId"], b["srcNodeId"])
			#	dst = Address(b["dstOwnerId"], b["dstNodeId"], b["dstPointId"]) ####DATABASEID???
			#	#trace("FOLLOW SENDER " + str(src) + "=>" + str(dst))
			#	p.numBindings += 1

			#if p.numBindings == 0:
			#	trace("warning: no bindings found in DB for:" + pointName)

		else:
			trace("warning: endType was not known:" + str(endType))
			raise ValueError("Unknown endType")

		self.points[pointName] = p
		return p