Пример #1
0
	def HandlePacket(self, oPacketI):
		
		try:
			
			# Handle Function Request packets
			if oPacketI.Type != 'Request':
				raise InvalidOperation("It is illegal to send a worker a packet of type '%s'." % oPacketI.Type)
				
			# Sanity check
			if oPacketI.Target != self.App.Identifier:
				raise InvalidOperation("A packet with Target='%s' may not be sent to a worker with App.Identifier='%s'." % (oPacketI.Target, self.App.Identifier))
			
			try:
				self.App.LoadSecurityContext(oPacketI.SecurityContext, oPacketI.ADDR)
			
				# Call the API
				DATA = self.App.CallAPI(oPacketI.Method, oPacketI.Data, Target='<SELF>')

			finally:
				self.App.FreeSecurityContext()


			# Create the response packet (clone core fields off of the incoming packet)
			oPacketO = ResponsePacket()
			oPacketO.DataType = oPacketI.DataType
			oPacketO.Data = DATA

			# Send the response
			self.SendPacket(oPacketO)

		except Exception, e:
			
			# Print exception
			print; traceback.print_exc(); print
			
			# Format message:
			if DE:BUG(3, "Worker %s received %s: \n%s" % (self, type(e).__name__, e.message))
			
			# Create an exception response packet
			oPacketO = ExceptionPacket()
			if hasattr(e, 'Data'):
				oPacketO.Data = e.Data				
			oPacketO.ExceptionType = type(e).__name__
			oPacketO.Message = e.message

			self.SendPacket(oPacketO)