#NEWLINE# def __Get( self ) : #NEWLINE# #INDENT# 'Get the least-loaded node from the heap.\n\n    Returns:\n      A node.\n    ' #NEWLINE# while True : #NEWLINE# #INDENT# n = self . _downq #NEWLINE# m = None #NEWLINE# while ( n is not None ) : #NEWLINE# #INDENT# if ( n . index < 0 ) : #NEWLINE# #INDENT# n = n . downq #NEWLINE# if ( m is None ) : #NEWLINE# #INDENT# self . _downq = n #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# m . downq = n #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( n . channel . state == ChannelState . Open ) : #NEWLINE# #INDENT# n . load -= self . Penalty #NEWLINE# ep = n . endpoint #NEWLINE# Heap . FixUp ( self . _heap , n . index ) #NEWLINE# o = n . downq #NEWLINE# n . downq = None #NEWLINE# n = o #NEWLINE# if ( m is None ) : #NEWLINE# #INDENT# self . _downq = n #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# m . downq = n #NEWLINE# #UNINDENT# self . _log . info ( ( 'Marking node %s up' % str ( ep ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ( m , n ) = ( n , n . downq ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# n = self . _heap [ 1 ] #NEWLINE# if ( ( n . channel . state == ChannelState . Open ) or ( n . load >= 0 ) ) : #NEWLINE# #INDENT# return n #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# n . downq = self . _downq #NEWLINE# self . _downq = n #NEWLINE# n . load += n . Penalty #NEWLINE# Heap . FixDown ( self . _heap , 1 , self . _size ) #NEWLINE# self . _OnNodeDown ( n ) #NEWLINE# self . _log . warning ( ( 'Marking node %s down' % str ( n . endpoint ) ) )