本文整理汇总了Python中table.Table.getValue方法的典型用法代码示例。如果您正苦于以下问题:Python Table.getValue方法的具体用法?Python Table.getValue怎么用?Python Table.getValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类table.Table
的用法示例。
在下文中一共展示了Table.getValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from table import Table [as 别名]
# 或者: from table.Table import getValue [as 别名]
class Statistics:
_table = None
def __init__(self):
self._table = Table()
def increment(self, index_content):
i_lock.acquire()
initial_value = self._table.getValue(self._table.searchTable(index_content))
if initial_value == None:
initial_value = 0
self._table.searchUpdate(index_content, initial_value+1)
i_lock.release()
def printAll(self):
for i in range(0, self._table.getLen()):
print self._table.getIndex(i), self._table.getValue(i)
示例2: Node
# 需要导入模块: from table import Table [as 别名]
# 或者: from table.Table import getValue [as 别名]
#.........这里部分代码省略.........
"""
Handle requests recieved over the REP socket.
Each request is handled in a spawned greenlet.
"""
while True:
m = self._rep.recv_multipart()
self.spawn(self._handleRepMessage, m)
def _handleRepMessage(self, m):
"""
Handle an individual request recieved over the REP socket.
:param m: The request to handle.
"""
log.debug(str(m))
i = 0
while m[i] != "":
i += 1
envelope = m[:i+1]
msg = m[i+1:]
reply = None
if msg[0] == "PEER":
peerInfo = (msg[1], msg[2], msg[3])
repLog.debug("Recieved PEER request: identity:%s REP:%s PUB:%s", *peerInfo)
reply = envelope + ["PEER", self._id, self._pubAddr]
if not peerInfo[0] in self._peers.keys():
self._subConnect(peerInfo[2])
self._peers[peerInfo[0]] = Peer(self, peerInfo[0], peerInfo[1], peerInfo[2], self._reqConnect(peerInfo[1]))
self._pubPeer(peerInfo[0], peerInfo[1])
elif msg[0] == "PEERS":
repLog.debug("Recieved PEERS request")
reply = envelope
reply.append("PEERS")
reply.append(json.dumps(dict(((ident, peer._repAddr) for ident, peer in self._peers.items()))))
elif msg[0] == "BUCKETS":
repLog.debug("Recieved BUCKETS request")
reply = envelope + ["BUCKETS", json.dumps(self._table.ownedBuckets())]
elif msg[0] == "KEYS":
repLog.debug("Recieved KEYS request for bucket '%s'" % (msg[1],))
reply = envelope + ["KEYS", msg[1], json.dumps(self._table.getKeySet(msg[1], includeTimestamp=True))]
elif msg[0] == "GET":
repLog.debug("Recieved GET request for key '%s'", msg[1])
try:
entry = self._table.getValue(msg[1])
reply = envelope + ["GET", msg[1], entry._value, repr(entry._timestamp)]
except KeyError:
reply = ["ERROR", "KeyError", "GET", msg[1]]
else:
reply = envelope + ["ECHO"] + msg
repLog.debug("REPLY: %s", reply)
self._rep.send_multipart(reply)
def _pubUpdate(self, key):
"""
Send an update message over the PUB socket for the given key.
:param key: The key to give an update for.
"""
entry = self._table.getValue(key)
self._pub.send_multipart(["UPDATE|" + entry._hash, key, entry._value, repr(entry._timestamp)])
def _pubPeer(self, id, addr):
self._pub.send_multipart(["PEER", str(id), str(addr)])
def _handleSub(self):
"""
Handle messages recieved over the SUB socket.
Each message is handled in a spawned greenlet.
"""
while True:
m = self._sub.recv_multipart()
self.spawn(self._handleSubMessage, m)
def _heartbeat(self):
while True:
self._pub.send_multipart(['HEARTBEAT', self._id])
sleep(30)
def _handleSubMessage(self, m):
"""
Handle an individual message recieved over the SUB socket.
:param m: The message to handle.
"""
subLog.debug("SUB: Recieved %s", m)
if m[0][:7] == 'UPDATE|':
subLog.debug("UPDATE key:%s value:%s timestamp:%s", m[1], m[2], m[3])
if self._table.putValue(m[1], m[2], float(m[3])):
self._pubUpdate(m[1])
elif m[0] == 'HEARTBEAT':
id = m[1]
subLog.debug("HEARTBEAT: id:'%s'", id)
elif m[0] == 'PEER':
id = m[1]
addr = m[2]
subLog.debug("PEER: id:'%s', addr:'%s'", id, addr)
if not id in self._peers.keys() and id != self._id:
self.connect(addr)