当前位置: 首页>>代码示例>>Python>>正文


Python Message.createElement方法代码示例

本文整理汇总了Python中message.Message.createElement方法的典型用法代码示例。如果您正苦于以下问题:Python Message.createElement方法的具体用法?Python Message.createElement怎么用?Python Message.createElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在message.Message的用法示例。


在下文中一共展示了Message.createElement方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: exchange

# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import createElement [as 别名]
	def exchange(self, vault=None):
		'''
		First thing first, the initiator issues a "exchange request".

		In Cyclon protocol, the exchange request consists in generating a
		subset of peers to exchange with the oldest peer. The "age" of a peer
		is based on the how many exchanges have passed since I last updated
		the state of that peer of my neighboring list.
		'''
		if self.itsExchanging():
			return True

		Cyclon.peerList.increaseAges()

		try:
			oldestPeer = Cyclon.peerList.getOldest()

		except IndexError:
			print ' * No peer available for exchanging'
			return True

		print '''Starting an exchange with ''' + oldestPeer.getName()

		self.exchangeStarted()

		print >> stderr, ''' * computing subset '''
		shuffleSize = randint(1, self.getShuffleLength()) - 1
		randomSubset = Cyclon.peerList.drop(oldestPeer).getSubset(shuffleSize)
		sentSet = CyclonPeerList([ oldestPeer ]) + randomSubset

		message = Message(kind='exchange',
			source=Cyclon.myself.getName(),
			destination=oldestPeer.getName())

		randomSubset.insert(0, Cyclon.myself)

		body = message.getBody()

		print >> stderr, ''' * building message '''

		for p in randomSubset:
			node = body.appendChild(message.createElement('node'))
			node.setAttribute('name', p.getName())
			node.childNodes = p.getConnectionsXML()

		print >> stderr, ''' * Sending request '''

		message.send(
			oldestPeer.transport, 3, 3
		).addCallback(
			self.exchangeReplyReceived, sentSet=sentSet
		).addErrback(
			self.removePeerErrback, peer=oldestPeer.getName(), success=False
		).addErrback(
			self.exchangeFinished, success=False
		).addErrback(
			self.exchange)

		return True
开发者ID:ComputerNetworks-UFRGS,项目名称:ManP2P-ng,代码行数:61,代码来源:cyclon.py

示例2: replyIntroduction

# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import createElement [as 别名]
	def replyIntroduction(self, peer, introduced):
		replyMessage = Message('intro reply',
			source=Cyclon.myself.getName(), destination=peer.getName(),
			annotations={ 'introduced': introduced })

		node = replyMessage.body.appendChild(Message.createElement("node"))
		node.setAttribute('name', introduced.getName())

		for c in introduced.getConnectionsXML():
			node.appendChild(c)

		replyMessage.send(
			peer.transport, 5, 3
		).addCallback(
			lambda m: (
				Cyclon.peerList.addPeer(peer),
				(Cyclon.peerList.remove(m.introduced) or True
					if m.introduced in Cyclon.peerList else True)
			)
		).addErrback(lambda m: True)
开发者ID:ComputerNetworks-UFRGS,项目名称:ManP2P-ng,代码行数:22,代码来源:cyclon.py

示例3: sendIntroductions

# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import createElement [as 别名]
	def sendIntroductions(self, peer, candidatesSet, replacersSet=None):
		# Building the newcomers peer' description
		nodeInfo = Message.createElement('node', { 'name':peer.getName() })

		for c in peer.getConnectionsXML():
			nodeInfo.appendChild(c)

		# The replacersSet is used for replace unreachable peers in the
		# errback method 'introductionErrback'.
		if replacersSet == None:
			replacersSet = Cyclon.peerList.drop(candidatesSet)

		print ' | Sending introduction to the following peers: '
		# Sending the introductory message to the random candidatesSet
		for q in candidatesSet:
			# One message per peer as the destination must be explicit
			introMessage = Message(kind='introduction',
				source=Cyclon.myself.getName(),
				destination=q.getName(),
				extraAttributes={
					'ttl': str(self.getTTL())},
				annotations={
					'candidatesSset': candidatesSet,
					'newcomer': peer,
					'replacersSet': replacersSet})

			# Appending newcomers info
			introMessage.getBody().appendChild(nodeInfo)

			print ' |->', q.getName()
			# The actual sending
			introMessage.send(
				q.transport, 3, 3
			).addCallback(
				lambda m: True
			).addErrback(
				self.introductionErrback, message=introMessage)
开发者ID:ComputerNetworks-UFRGS,项目名称:ManP2P-ng,代码行数:39,代码来源:cyclon.py


注:本文中的message.Message.createElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。